Skip to content

bpo-39763: Refactor setup.py #18778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down Expand Up @@ -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]
Expand All @@ -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')]
Expand All @@ -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 ]
Expand All @@ -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:
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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
Expand Down