From 9eb2f3c0e6b554aaba1d9080327b6a18c3cf91a7 Mon Sep 17 00:00:00 2001 From: Arya Reais-Parsi Date: Tue, 8 Dec 2020 10:43:29 -0800 Subject: [PATCH] add error message when configuration files are not valid python module names --- compiler/globals.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/globals.py b/compiler/globals.py index f5c42dc0..b1cc92c4 100644 --- a/compiler/globals.py +++ b/compiler/globals.py @@ -295,6 +295,14 @@ def read_config(config_file, is_unit_test=True): dir_name = os.path.dirname(config_file) module_name = os.path.basename(config_file) + # Check that the module name adheres to Python's module naming conventions. + # This will assist the user in interpreting subsequent errors in loading + # the module. Valid Python module naming is described here: + # https://docs.python.org/3/reference/simple_stmts.html#the-import-statement + if not module_name.isidentifier(): + debug.error("Configuration file name is not a valid Python module name: " + "{0}. It should be a valid identifier.".format(module_name)) + # Prepend the path to avoid if we are using the example config sys.path.insert(0, dir_name) # Import the configuration file of which modules to use