Commit 1e73a246 authored by Antoine Pitrou's avatar Antoine Pitrou

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%.
parent cf28eaca
...@@ -49,6 +49,7 @@ libpython*.so* ...@@ -49,6 +49,7 @@ libpython*.so*
*.pyd *.pyd
*.cover *.cover
*~ *~
Lib/_sysconfigdata.py
Lib/lib2to3/*.pickle Lib/lib2to3/*.pickle
Lib/test/data/* Lib/test/data/*
Misc/*.wpu Misc/*.wpu
......
...@@ -319,9 +319,11 @@ def get_makefile_filename(): ...@@ -319,9 +319,11 @@ def get_makefile_filename():
config_dir_name = 'config' config_dir_name = 'config'
return os.path.join(get_path('stdlib'), config_dir_name, 'Makefile') return os.path.join(get_path('stdlib'), config_dir_name, 'Makefile')
def _generate_posix_vars():
def _init_posix(vars): """Generate the Python module containing build-time variables."""
"""Initialize the module as appropriate for POSIX systems.""" import pprint
vars = {}
destfile = os.path.join(os.path.dirname(__file__), '_sysconfigdata.py')
# load the installed Makefile: # load the installed Makefile:
makefile = get_makefile_filename() makefile = get_makefile_filename()
try: try:
...@@ -346,7 +348,15 @@ def _init_posix(vars): ...@@ -346,7 +348,15 @@ def _init_posix(vars):
# the scripts are in another directory. # the scripts are in another directory.
if _PYTHON_BUILD: if _PYTHON_BUILD:
vars['LDSHARED'] = vars['BLDSHARED'] 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): def _init_non_posix(vars):
"""Initialize the module as appropriate for NT""" """Initialize the module as appropriate for NT"""
...@@ -753,6 +763,9 @@ def _print_dict(title, data): ...@@ -753,6 +763,9 @@ def _print_dict(title, data):
def _main(): def _main():
"""Display all information sysconfig detains.""" """Display all information sysconfig detains."""
if '--generate-posix-vars' in sys.argv:
_generate_posix_vars()
return
print('Platform: "%s"' % get_platform()) print('Platform: "%s"' % get_platform())
print('Python version: "%s"' % get_python_version()) print('Python version: "%s"' % get_python_version())
print('Current installation scheme: "%s"' % _get_default_scheme()) print('Current installation scheme: "%s"' % _get_default_scheme())
......
...@@ -396,7 +396,7 @@ LIBRARY_OBJS= \ ...@@ -396,7 +396,7 @@ LIBRARY_OBJS= \
# Default target # Default target
all: build_all all: build_all
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Modules/_testembed build_all: $(BUILDPYTHON) sysconfig oldsharedmods sharedmods gdbhooks Modules/_testembed
# Compile a binary with gcc profile guided optimization. # Compile a binary with gcc profile guided optimization.
profile-opt: profile-opt:
...@@ -429,12 +429,15 @@ coverage: ...@@ -429,12 +429,15 @@ coverage:
$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) $(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
platform: $(BUILDPYTHON) platform: $(BUILDPYTHON) sysconfig
$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform $(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
# Generate the sysconfig build-time data
sysconfig: $(BUILDPYTHON)
$(RUNSHARED) ./$(BUILDPYTHON) -SE -m sysconfig --generate-posix-vars
# Build the shared modules # Build the shared modules
sharedmods: $(BUILDPYTHON) sharedmods: $(BUILDPYTHON) sysconfig
@case $$MAKEFLAGS in \ @case $$MAKEFLAGS in \
*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \ *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \ *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
...@@ -1379,7 +1382,7 @@ patchcheck: ...@@ -1379,7 +1382,7 @@ patchcheck:
Python/thread.o: @THREADHEADERS@ Python/thread.o: @THREADHEADERS@
# Declare targets that aren't real files # Declare targets that aren't real files
.PHONY: all build_all sharedmods oldsharedmods test quicktest .PHONY: all build_all sysconfig sharedmods oldsharedmods test quicktest
.PHONY: install altinstall oldsharedinstall bininstall altbininstall .PHONY: install altinstall oldsharedinstall bininstall altbininstall
.PHONY: maninstall libinstall inclinstall libainstall sharedinstall .PHONY: maninstall libinstall inclinstall libainstall sharedinstall
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
......
...@@ -315,6 +315,10 @@ Core and Builtins ...@@ -315,6 +315,10 @@ Core and Builtins
Library Library
------- -------
- 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%.
- Issue #12448: smtplib now flushes stdout while running ``python -m smtplib`` - Issue #12448: smtplib now flushes stdout while running ``python -m smtplib``
in order to display the prompt correctly. in order to display the prompt correctly.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment