diff --git a/aksetup_helper.py b/aksetup_helper.py index a3e3afc5ccc0cfde6d04dd52810ac809daf7b48e..a63576f8f406a9de81226e70547e17e53187dc33 100644 --- a/aksetup_helper.py +++ b/aksetup_helper.py @@ -1,10 +1,10 @@ import setuptools # noqa from setuptools import Extension +import sys def count_down_delay(delay): from time import sleep - import sys while delay: sys.stdout.write("Continuing in %d seconds... \r" % delay) sys.stdout.flush() @@ -128,7 +128,9 @@ def get_config(schema=None, warn_about_no_config=True): count_down_delay(delay=10) - return expand_options(schema.read_config()) + config = expand_options(schema.read_config()) + schema.update_config_from_and_modify_command_line(config, sys.argv) + return config def hack_distutils(debug=False, fast_link=True, what_opt=3): @@ -143,7 +145,6 @@ def hack_distutils(debug=False, fast_link=True, what_opt=3): break return optlist - import sys if not sys.platform.lower().startswith("win"): from distutils import sysconfig @@ -233,7 +234,6 @@ class ConfigSchema: from os.path import expanduser self.user_conf_file = expanduser("~/.aksetup-defaults.py") - import sys if not sys.platform.lower().startswith("win"): self.global_conf_file = "/etc/aksetup-defaults.py" else: @@ -328,23 +328,44 @@ class ConfigSchema: import os return os.access(self.get_conf_file(), os.R_OK) - def read_config(self, warn_if_none=True): + def update_from_python_snippet(self, config, py_snippet, filename): + filevars = {} + exec(compile(py_snippet, filename, "exec"), filevars) + + for key, value in filevars.items(): + if key in self.optdict: + config[key] = value + elif key == "__builtins__": + pass + else: + raise KeyError("invalid config key in %s: %s" % ( + filename, key)) + + def update_config_from_and_modify_command_line(self, config, argv): + cfg_prefix = "--conf:" + + i = 0 + while i < len(argv): + arg = argv[i] + + if arg.startswith(cfg_prefix): + del argv[i] + self.update_from_python_snippet( + config, arg[len(cfg_prefix):], "<command line>") + else: + i += 1 + + return config + + def read_config(self): import os cfile = self.get_conf_file() result = self.get_default_config_with_files() if os.access(cfile, os.R_OK): - filevars = {} - exec(compile(open(cfile, "r").read(), cfile, "exec"), filevars) - - for key, value in filevars.items(): - if key in self.optdict: - result[key] = value - elif key == "__builtins__": - pass - else: - raise KeyError("invalid config key in %s: %s" % ( - cfile, key)) + with open(cfile, "r") as inf: + py_snippet = inf.read() + self.update_from_python_snippet(result, py_snippet, cfile) return result @@ -484,7 +505,6 @@ class BoostLibraries(Libraries): def __init__(self, lib_base_name, default_lib_name=None): if default_lib_name is None: if lib_base_name == "python": - import sys default_lib_name = "boost_python-py%d%d" % sys.version_info[:2] else: default_lib_name = "boost_%s" % lib_base_name @@ -506,7 +526,6 @@ def set_up_shipped_boost_if_requested(project_name, conf, source_path=None, (only relevant in shipped mode) """ from os.path import exists - import sys if source_path is None: source_path = "bpl-subset/bpl_subset" @@ -619,8 +638,6 @@ def configure_frontend(): print("*** %s." % schema.get_conf_file()) print("************************************************************") - import sys - description = "generate a configuration file for this software package" parser = OptionParser(description=description) parser.add_option( @@ -691,7 +708,6 @@ def substitute(substitutions, fname): new_lines.append(l) new_lines.insert(1, "# DO NOT EDIT THIS FILE -- " "it was generated by configure.py\n") - import sys new_lines.insert(2, "# %s\n" % (" ".join(sys.argv))) open(fname, "w").write("".join(new_lines))