[Python-checkins] bpo-39763: Refactor setup.py (GH-18778)
Victor Stinner
webhook-mailer at python.org
Wed Mar 4 12:44:57 EST 2020
https://github.com/python/cpython/commit/00c77ae55a82548a6b45af73cdf712ea34910645
commit: 00c77ae55a82548a6b45af73cdf712ea34910645
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-03-04T18:44:49+01:00
summary:
bpo-39763: Refactor setup.py (GH-18778)
Split long build_extensions() method into sub-methods.
Fix also a typo in Popen.wait(): replace sts with status.
files:
M setup.py
diff --git a/setup.py b/setup.py
index c9f3c97238c22..a331315817950 100644
--- a/setup.py
+++ b/setup.py
@@ -52,7 +52,7 @@ def wait(self):
elif os.WIFEXITED(status):
self.returncode = os.WEXITSTATUS(status)
elif os.WIFSTOPPED(status):
- self.returncode = -os.WSTOPSIG(sts)
+ self.returncode = -os.WSTOPSIG(status)
else:
# Should never happen
raise Exception("Unknown child exit status!")
@@ -364,16 +364,14 @@ def __init__(self, dist):
def add(self, ext):
self.extensions.append(ext)
- def build_extensions(self):
+ def set_srcdir(self):
self.srcdir = sysconfig.get_config_var('srcdir')
if not self.srcdir:
# Maybe running on Windows but not using CYGWIN?
raise ValueError("No source directory; cannot proceed.")
self.srcdir = os.path.abspath(self.srcdir)
- # Detect which modules should be compiled
- self.detect_modules()
-
+ def remove_disabled(self):
# Remove modules that are present on the disabled list
extensions = [ext for ext in self.extensions
if ext.name not in DISABLED_MODULE_LIST]
@@ -384,6 +382,7 @@ def build_extensions(self):
extensions.append(ctypes)
self.extensions = extensions
+ def update_sources_depends(self):
# Fix up the autodetected modules, prefixing all the source files
# with Modules/.
moddirlist = [os.path.join(self.srcdir, 'Modules')]
@@ -396,14 +395,6 @@ def build_extensions(self):
headers = [sysconfig.get_config_h_filename()]
headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
- # The sysconfig variables built by makesetup that list the already
- # built modules and the disabled modules as configured by the Setup
- # files.
- sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
- sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
-
- mods_built = []
- mods_disabled = []
for ext in self.extensions:
ext.sources = [ find_module_file(filename, moddirlist)
for filename in ext.sources ]
@@ -415,6 +406,16 @@ def build_extensions(self):
# re-compile extensions if a header file has been changed
ext.depends.extend(headers)
+ def remove_configured_extensions(self):
+ # The sysconfig variables built by makesetup that list the already
+ # built modules and the disabled modules as configured by the Setup
+ # files.
+ sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
+ sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
+
+ mods_built = []
+ mods_disabled = []
+ for ext in self.extensions:
# If a module has already been built or has been disabled in the
# Setup files, don't build it here.
if ext.name in sysconf_built:
@@ -432,6 +433,9 @@ def build_extensions(self):
if os.path.exists(fullpath):
os.unlink(fullpath)
+ return (mods_built, mods_disabled)
+
+ def set_compiler_executables(self):
# When you run "make CC=altcc" or something similar, you really want
# those environment variables passed into the setup.py phase. Here's
# a small set of useful ones.
@@ -444,6 +448,18 @@ def build_extensions(self):
args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
self.compiler.set_executables(**args)
+ def build_extensions(self):
+ self.set_srcdir()
+
+ # Detect which modules should be compiled
+ self.detect_modules()
+
+ self.remove_disabled()
+
+ self.update_sources_depends()
+ mods_built, mods_disabled = self.remove_configured_extensions()
+ self.set_compiler_executables()
+
build_ext.build_extensions(self)
if SUBPROCESS_BOOTSTRAP:
@@ -454,6 +470,9 @@ def build_extensions(self):
for ext in self.extensions:
self.check_extension_import(ext)
+ self.summary(mods_built, mods_disabled)
+
+ def summary(self, mods_built, mods_disabled):
longest = max([len(e.name) for e in self.extensions], default=0)
if self.failed or self.failed_on_import:
all_failed = self.failed + self.failed_on_import
More information about the Python-checkins
mailing list