[Python-Dev] [Python-checkins] cpython (2.7): - Issue #13150: sysconfig no longer parses the Makefile and config.h files (original) (raw)

Andrew Svetlov andrew.svetlov at gmail.com
Fri Mar 22 05:54:30 CET 2013


Great!

On Thu, Mar 21, 2013 at 3:02 PM, matthias.klose <python-checkins at python.org> wrote:

http://hg.python.org/cpython/rev/66e30c4870bb changeset: 82872:66e30c4870bb branch: 2.7 parent: 82843:71adf21421d9 user: doko at ubuntu.com date: Thu Mar 21 15:02:16 2013 -0700 summary: - 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%.

files: Lib/distutils/sysconfig.py | 63 +-------------------- Lib/pprint.py | 5 +- Lib/sysconfig.py | 75 ++++++++++++++++++++++++- Makefile.pre.in | 12 +++- Misc/NEWS | 4 + 5 files changed, 93 insertions(+), 66 deletions(-)

diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py --- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -387,66 +387,11 @@ def initposix(): """Initialize the module as appropriate for POSIX systems.""" - g = {} - # load the installed Makefile: - try: - filename = getmakefilefilename() - parsemakefile(filename, g) - except IOError, msg: - mymsg = "invalid Python installation: unable to open %s" % filename - if hasattr(msg, "strerror"): - mymsg = mymsg + " (%s)" % msg.strerror - - raise DistutilsPlatformError(mymsg) - - # load the installed pyconfig.h: - try: - filename = getconfighfilename() - parseconfigh(file(filename), g) - except IOError, msg: - mymsg = "invalid Python installation: unable to open %s" % filename - if hasattr(msg, "strerror"): - mymsg = mymsg + " (%s)" % msg.strerror - - raise DistutilsPlatformError(mymsg) - - # On AIX, there are wrong paths to the linker scripts in the Makefile - # -- these paths are relative to the Python source, but when installed - # the scripts are in another directory. - if pythonbuild: - g['LDSHARED'] = g['BLDSHARED'] - - elif getpythonversion() < '2.1':_ _- # The following two branches are for 1.5.2 compatibility._ _- if sys.platform == 'aix4': # what about AIX 3.x ?_ _- # Linker script is in the config directory, not in Modules as the_ _- # Makefile says._ _- pythonlib = getpythonlib(standardlib=1)_ _- ldsoaix = os.path.join(pythonlib, 'config', 'ldsoaix')_ _- pythonexp = os.path.join(pythonlib, 'config', 'python.exp')_ _-_ _- g['LDSHARED'] = "%s %s -bI:%s" % (ldsoaix, g['CC'], pythonexp)_ _-_ _- elif sys.platform == 'beos':_ _- # Linker script is in the config directory. In the Makefile it is_ _- # relative to the srcdir, which after installation no longer makes_ _- # sense._ _- pythonlib = getpythonlib(standardlib=1)_ _- linkerscriptpath = string.split(g['LDSHARED'])[0]_ _- linkerscriptname = os.path.basename(linkerscriptpath)_ _- linkerscript = os.path.join(pythonlib, 'config',_ _- linkerscriptname)_ _-_ _- # XXX this isn't the right place to do this: adding the Python_ _- # library to the link, if needed, should be in the "buildext"_ _- # command. (It's also needed for non-MS compilers on Windows, and_ _- # it's taken care of for them by the 'buildext.getlibraries()'_ _- # method.)_ _- g['LDSHARED'] = ("%s -L%s/lib -lpython%s" %_ _- (linkerscript, PREFIX, getpythonversion()))_ _-_ _+ # sysconfigdata is generated at build time, see the sysconfig module_ _+ from sysconfigdata import buildtimevars_ _global configvars_ _- configvars = g_ _+ configvars = {}_ _+ configvars.update(buildtimevars)_ _def initnt():_ _diff --git a/Lib/pprint.py b/Lib/pprint.py_ _--- a/Lib/pprint.py_ _+++ b/Lib/pprint.py_ _@@ -37,7 +37,10 @@_ _import sys as sys_ _import warnings_ _-from cStringIO import StringIO as StringIO_ _+try:_ _+ from cStringIO import StringIO as StringIO_ _+except ImportError:_ _+ from StringIO import StringIO as StringIO_ __all_ = ["pprint","pformat","isreadable","isrecursive","saferepr",_ _"PrettyPrinter"]_ _diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py_ _--- a/Lib/sysconfig.py_ _+++ b/Lib/sysconfig.py_ _@@ -278,9 +278,10 @@_ _return os.path.join(PROJECTBASE, "Makefile")_ _return os.path.join(getpath('platstdlib'), "config", "Makefile")_ _-_ _-def initposix(vars):_ _- """Initialize the module as appropriate for POSIX systems."""_ _+def generateposixvars():_ _+ """Generate the Python module containing build-time variables."""_ _+ import pprint_ _+ vars = {}_ _# load the installed Makefile:_ _makefile = getmakefilefilename()_ _try:_ _@@ -308,6 +309,49 @@_ _if PYTHONBUILD:_ _vars['LDSHARED'] = vars['BLDSHARED']_ _+ # There's a chicken-and-egg situation on OS X with regards to the_ _+ # sysconfigdata module after the changes introduced by #15298:_ _+ # getconfigvars() is called by getplatform() as part of the_ _+ # make pybuilddir.txt target -- which is a precursor to the_ _+ # sysconfigdata.py module being constructed. Unfortunately,_ _+ # getconfigvars() eventually calls initposix(), which attempts_ _+ # to import sysconfigdata, which we won't have built yet. In order_ _+ # for initposix() to work, if we're on Darwin, just mock up the_ _+ # sysconfigdata module manually and populate it with the build vars._ _+ # This is more than sufficient for ensuring the subsequent call to_ _+ # getplatform() succeeds._ _+ name = 'sysconfigdata'_ _+ if 'darwin' in sys.platform:_ _+ import imp_ _+ module = imp.newmodule(name)_ _+ module.buildtimevars = vars_ _+ sys.modules[name] = module_ _+_ _+ pybuilddir = 'build/lib.%s-%s' % (getplatform(), sys.version[:3])_ _+ if hasattr(sys, "gettotalrefcount"):_ _+ pybuilddir += '-pydebug'_ _+ try:_ _+ os.makedirs(pybuilddir)_ _+ except OSError:_ _+ pass_ _+ destfile = os.path.join(pybuilddir, name + '.py')_ _+_ _+ with open(destfile, 'wb') as f:_ _+ f.write('# system configuration generated and used by'_ _+ ' the sysconfig module\n')_ _+ f.write('buildtimevars = ')_ _+ pprint.pprint(vars, stream=f)_ _+_ _+ # Create file used for sys.path fixup -- see Modules/getpath.c_ _+ with open('pybuilddir.txt', 'w') as f:_ _+ f.write(pybuilddir)_ _+_ _+def initposix(vars):_ _+ """Initialize the module as appropriate for POSIX systems."""_ _+ # sysconfigdata is generated at build time, see generateposixvars()_ _+ from sysconfigdata import buildtimevars_ _+ vars.update(buildtimevars)_ _+_ _def initnonposix(vars):_ _"""Initialize the module as appropriate for NT"""_ _# set basic install directories_ _@@ -565,3 +609,28 @@_ _def getpythonversion():_ _return PYVERSIONSHORT_ _+_ _+_ _+def printdict(title, data):_ _+ for index, (key, value) in enumerate(sorted(data.items())):_ _+ if index == 0:_ _+ print '%s: ' % (title)_ _+ print '\t%s = "%s"' % (key, value)_ _+_ _+_ _+def main():_ _+ """Display all information sysconfig detains."""_ _+ if '--generate-posix-vars' in sys.argv:_ _+ generateposixvars()_ _+ return_ _+ print 'Platform: "%s"' % getplatform()_ _+ print 'Python version: "%s"' % getpythonversion()_ _+ print 'Current installation scheme: "%s"' % getdefaultscheme()_ _+ print_ _+ printdict('Paths', getpaths())_ _+ print_ _+ printdict('Variables', getconfigvars())_ _+_ _+_ _+if _name_ == '_main_':_ _+ main()_ _diff --git a/Makefile.pre.in b/Makefile.pre.in_ _--- a/Makefile.pre.in_ _+++ b/Makefile.pre.in_ _@@ -437,15 +437,20 @@_ _Modules/python.o _ _$(BLDLIBRARY) (LIBS)(LIBS) (LIBS)(MODLIBS) (SYSLIBS)(SYSLIBS) (SYSLIBS)(LDLAST) -platform: $(BUILDPYTHON) +platform: $(BUILDPYTHON) pybuilddir.txt $(RUNSHARED) $(PYTHONFORBUILD) -c 'import sys ; from sysconfig import getplatform ; print getplatform()+"-"+sys.version[0:3]' >platform +# Create build directory and generate the sysconfig build-time data there. +# pybuilddir.txt contains the name of the build dir and is used for +# sys.path fixup -- see Modules/getpath.c. +pybuilddir.txt: $(BUILDPYTHON) + (RUNSHARED)(RUNSHARED) (RUNSHARED)(PYTHONFORBUILD) -S -m sysconfig --generate-posix-vars # Build the shared modules # Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for # -s, --silent or --quiet is always the first char. # Under BSD make, MAKEFLAGS might be " -s -v x=y". -sharedmods: $(BUILDPYTHON) +sharedmods: $(BUILDPYTHON) pybuilddir.txt _@case "$$MAKEFLAGS" in _ _\ -s|s*) quiet="-q";; _ _) quiet="";; _ @@ -955,7 +960,7 @@ _else true; _ _fi; _ done _- @for i in (srcdir)/Lib/∗.py(srcdir)/Lib/.py (srcdir)/Lib/.py(srcdir)/Lib/.doc $(srcdir)/Lib/.egg-info ; _ _+ @for i in (srcdir)/Lib/∗.py‘catpybuilddir.txt‘/sysconfigdata.py(srcdir)/Lib/.py cat pybuilddir.txt/sysconfigdata.py (srcdir)/Lib/.pycatpybuilddir.txt‘/sysconfigdata.py(srcdir)/Lib/.doc $(srcdir)/Lib/.egg-info ; _ _do _ _if test -x i; then _ _$(INSTALLSCRIPT) i (DESTDIR)(DESTDIR)(DESTDIR)(LIBDEST); _ @@ -1133,6 +1138,7 @@ _--install-scripts=$(BINDIR) _ _--install-platlib=$(DESTSHARED) _ --root=$(DESTDIR)/ _+ -rm (DESTDIR)(DESTDIR)(DESTDIR)(DESTSHARED)/sysconfigdata.py_ # Here are a couple of targets for MacOSX again, to install a full # framework-based Python. frameworkinstall installs everything, the diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -216,6 +216,10 @@ 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 #10212: cStringIO and struct.unpack support new buffer objects. - Issue #12098: multiprocessing on Windows now starts child processes -- Repository URL: http://hg.python.org/cpython


Python-checkins mailing list Python-checkins at python.org http://mail.python.org/mailman/listinfo/python-checkins

-- Thanks, Andrew Svetlov



More information about the Python-Dev mailing list