diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-18 15:52:24 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-18 15:52:24 (GMT) |
commit | 1e73a2467f312f7b5ebef515cca6d3a16cf36f97 (patch) | |
tree | a5ddfaf2907b079983a2924779eb36b708b4e4ea /Lib/sysconfig.py | |
parent | cf28eacafe603fac8784d4a0b22b7864aec4a383 (diff) | |
download | cpython-1e73a2467f312f7b5ebef515cca6d3a16cf36f97.zip cpython-1e73a2467f312f7b5ebef515cca6d3a16cf36f97.tar.gz cpython-1e73a2467f312f7b5ebef515cca6d3a16cf36f97.tar.bz2 |
Issue #13150: sysconfig no longer parses the Makefile and config.h files
when imported, instead doing it at build time. This makes importing
sysconfig faster and reduces Python startup time by 20%.
Diffstat (limited to 'Lib/sysconfig.py')
-rw-r--r-- | Lib/sysconfig.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index 6594104..36c7aa4 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -319,9 +319,11 @@ def get_makefile_filename(): config_dir_name = 'config' return os.path.join(get_path('stdlib'), config_dir_name, 'Makefile') - -def _init_posix(vars): - """Initialize the module as appropriate for POSIX systems.""" +def _generate_posix_vars(): + """Generate the Python module containing build-time variables.""" + import pprint + vars = {} + destfile = os.path.join(os.path.dirname(__file__), '_sysconfigdata.py') # load the installed Makefile: makefile = get_makefile_filename() try: @@ -346,7 +348,15 @@ def _init_posix(vars): # the scripts are in another directory. if _PYTHON_BUILD: vars['LDSHARED'] = vars['BLDSHARED'] + with open(destfile, 'w', encoding='utf8') as f: + f.write('build_time_vars = ') + pprint.pprint(vars, stream=f) +def _init_posix(vars): + """Initialize the module as appropriate for POSIX systems.""" + # _sysconfigdata is generated at build time, see _generate_posix_vars() + from _sysconfigdata import build_time_vars + vars.update(build_time_vars) def _init_non_posix(vars): """Initialize the module as appropriate for NT""" @@ -753,6 +763,9 @@ def _print_dict(title, data): def _main(): """Display all information sysconfig detains.""" + if '--generate-posix-vars' in sys.argv: + _generate_posix_vars() + return print('Platform: "%s"' % get_platform()) print('Python version: "%s"' % get_python_version()) print('Current installation scheme: "%s"' % _get_default_scheme()) |