Skip to content

Commit

Permalink
Update aksetup to support --conf:XXX=YYY on setup.py command line
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Apr 24, 2016
1 parent 8be0b7a commit edfd5eb
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions 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()
Expand Down Expand Up @@ -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):
Expand All @@ -143,7 +145,6 @@ def remove_prefixes(optlist, bad_prefixes):
break
return optlist

import sys
if not sys.platform.lower().startswith("win"):
from distutils import sysconfig

Expand Down Expand Up @@ -233,7 +234,6 @@ def __init__(self, options, conf_file="siteconf.py", conf_dir="."):
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:
Expand Down Expand Up @@ -328,23 +328,44 @@ def have_config(self):
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

Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit edfd5eb

Please sign in to comment.