Skip to content

Commit

Permalink
Merge pull request #3809 from pypa/distutils-8c3c3d29
Browse files Browse the repository at this point in the history
Merge with distutils@8c3c3d29
  • Loading branch information
jaraco authored Feb 7, 2023
2 parents 8032430 + 47c7cfd commit bb17d4f
Show file tree
Hide file tree
Showing 54 changed files with 153 additions and 111 deletions.
1 change: 1 addition & 0 deletions changelog.d/3809.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merge with distutils@8c3c3d29, including fix for ``sysconfig.get_python_inc()`` (pypa/distutils#178), fix for segfault on MinGW (pypa/distutils#196), and better ``has_function`` support (pypa/distutils#195).
2 changes: 1 addition & 1 deletion setuptools/_distutils/_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def bounds(self):
return (sorted_keys[RangeMap.first_item], sorted_keys[RangeMap.last_item])

# some special values for the RangeMap
undefined_value = type(str('RangeValueUndefined'), (), {})()
undefined_value = type('RangeValueUndefined', (), {})()

class Item(int):
"RangeMap Item"
Expand Down
6 changes: 1 addition & 5 deletions setuptools/_distutils/_msvccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ def compile( # noqa: C901
extra_postargs=None,
depends=None,
):

if not self.initialized:
self.initialize()
compile_info = self._setup_compile(
Expand Down Expand Up @@ -413,8 +412,7 @@ def compile( # noqa: C901
args = [self.cc] + compile_opts + pp_opts
if add_cpp_opts:
args.append('/EHsc')
args.append(input_opt)
args.append("/Fo" + obj)
args.extend((input_opt, "/Fo" + obj))
args.extend(extra_postargs)

try:
Expand All @@ -427,7 +425,6 @@ def compile( # noqa: C901
def create_static_lib(
self, objects, output_libname, output_dir=None, debug=0, target_lang=None
):

if not self.initialized:
self.initialize()
objects, output_dir = self._fix_object_args(objects, output_dir)
Expand Down Expand Up @@ -461,7 +458,6 @@ def link(
build_temp=None,
target_lang=None,
):

if not self.initialized:
self.initialize()
objects, output_dir = self._fix_object_args(objects, output_dir)
Expand Down
9 changes: 1 addition & 8 deletions setuptools/_distutils/bcppcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class BCPPCompiler(CCompiler):
exe_extension = '.exe'

def __init__(self, verbose=0, dry_run=0, force=0):

super().__init__(verbose, dry_run, force)

# These executables are assumed to all be in the path.
Expand Down Expand Up @@ -98,7 +97,6 @@ def compile( # noqa: C901
extra_postargs=None,
depends=None,
):

macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
output_dir, macros, include_dirs, sources, depends, extra_postargs
)
Expand Down Expand Up @@ -167,7 +165,6 @@ def compile( # noqa: C901
def create_static_lib(
self, objects, output_libname, output_dir=None, debug=0, target_lang=None
):

(objects, output_dir) = self._fix_object_args(objects, output_dir)
output_filename = self.library_filename(output_libname, output_dir=output_dir)

Expand Down Expand Up @@ -200,7 +197,6 @@ def link( # noqa: C901
build_temp=None,
target_lang=None,
):

# XXX this ignores 'build_temp'! should follow the lead of
# msvccompiler.py

Expand All @@ -219,7 +215,6 @@ def link( # noqa: C901
output_filename = os.path.join(output_dir, output_filename)

if self._need_link(objects, output_filename):

# Figure out linker args based on type of target.
if target_desc == CCompiler.EXECUTABLE:
startup_obj = 'c0w32'
Expand Down Expand Up @@ -294,8 +289,7 @@ def link( # noqa: C901
ld_args.append(libfile)

# some default libraries
ld_args.append('import32')
ld_args.append('cw32mt')
ld_args.extend(('import32', 'cw32mt'))

# def file for export symbols
ld_args.extend([',', def_file])
Expand Down Expand Up @@ -381,7 +375,6 @@ def preprocess(
extra_preargs=None,
extra_postargs=None,
):

(_, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = ['cpp32.exe'] + pp_opts
Expand Down
46 changes: 40 additions & 6 deletions setuptools/_distutils/ccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import os
import re
import warnings

from .errors import (
CompileError,
Expand Down Expand Up @@ -388,7 +389,7 @@ def _fix_compile_args(self, output_dir, macros, include_dirs):
raise TypeError("'macros' (if supplied) must be a list of tuples")

if include_dirs is None:
include_dirs = self.include_dirs
include_dirs = list(self.include_dirs)
elif isinstance(include_dirs, (list, tuple)):
include_dirs = list(include_dirs) + (self.include_dirs or [])
else:
Expand Down Expand Up @@ -824,9 +825,19 @@ def has_function( # noqa: C901
libraries=None,
library_dirs=None,
):
"""Return a boolean indicating whether funcname is supported on
the current platform. The optional arguments can be used to
augment the compilation environment.
"""Return a boolean indicating whether funcname is provided as
a symbol on the current platform. The optional arguments can
be used to augment the compilation environment.
The libraries argument is a list of flags to be passed to the
linker to make additional symbol definitions available for
linking.
The includes and include_dirs arguments are deprecated.
Usually, supplying include files with function declarations
will cause function detection to fail even in cases where the
symbol is available for linking.
"""
# this can't be included at module scope because it tries to
# import math which might not be available at that point - maybe
Expand All @@ -835,8 +846,12 @@ def has_function( # noqa: C901

if includes is None:
includes = []
else:
warnings.warn("includes is deprecated", DeprecationWarning)
if include_dirs is None:
include_dirs = []
else:
warnings.warn("include_dirs is deprecated", DeprecationWarning)
if libraries is None:
libraries = []
if library_dirs is None:
Expand All @@ -845,7 +860,24 @@ def has_function( # noqa: C901
f = os.fdopen(fd, "w")
try:
for incl in includes:
f.write("""#include "%s"\n""" % incl)
f.write("""#include %s\n""" % incl)
if not includes:
# Use "char func(void);" as the prototype to follow
# what autoconf does. This prototype does not match
# any well-known function the compiler might recognize
# as a builtin, so this ends up as a true link test.
# Without a fake prototype, the test would need to
# know the exact argument types, and the has_function
# interface does not provide that level of information.
f.write(
"""\
#ifdef __cplusplus
extern "C"
#endif
char %s(void);
"""
% funcname
)
f.write(
"""\
int main (int argc, char **argv) {
Expand All @@ -871,7 +903,9 @@ def has_function( # noqa: C901
except (LinkError, TypeError):
return False
else:
os.remove(os.path.join(self.output_dir or '', "a.out"))
os.remove(
self.executable_filename("a.out", output_dir=self.output_dir or '')
)
finally:
for fn in objects:
os.remove(fn)
Expand Down
6 changes: 3 additions & 3 deletions setuptools/_distutils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def dump_options(self, header=None, indent=""):
header = "command options for '%s':" % self.get_command_name()
self.announce(indent + header, level=logging.INFO)
indent = indent + " "
for (option, _, _) in self.user_options:
for option, _, _ in self.user_options:
option = option.translate(longopt_xlate)
if option[-1] == "=":
option = option[:-1]
Expand Down Expand Up @@ -291,7 +291,7 @@ def set_undefined_options(self, src_cmd, *option_pairs):
# Option_pairs: list of (src_option, dst_option) tuples
src_cmd_obj = self.distribution.get_command_obj(src_cmd)
src_cmd_obj.ensure_finalized()
for (src_option, dst_option) in option_pairs:
for src_option, dst_option in option_pairs:
if getattr(self, dst_option) is None:
setattr(self, dst_option, getattr(src_cmd_obj, src_option))

Expand Down Expand Up @@ -325,7 +325,7 @@ def get_sub_commands(self):
run for the current distribution. Return a list of command names.
"""
commands = []
for (cmd_name, method) in self.sub_commands:
for cmd_name, method in self.sub_commands:
if method is None or method(self):
commands.append(cmd_name)
return commands
Expand Down
1 change: 0 additions & 1 deletion setuptools/_distutils/command/bdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def append(self, item):


class bdist(Command):

description = "create a built (binary) distribution"

user_options = [
Expand Down
1 change: 0 additions & 1 deletion setuptools/_distutils/command/bdist_dumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


class bdist_dumb(Command):

description = "create a \"dumb\" built distribution"

user_options = [
Expand Down
3 changes: 1 addition & 2 deletions setuptools/_distutils/command/bdist_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


class bdist_rpm(Command):

description = "create an RPM distribution"

user_options = [
Expand Down Expand Up @@ -554,7 +553,7 @@ def _make_spec_file(self): # noqa: C901
('postun', 'post_uninstall', None),
]

for (rpm_opt, attr, default) in script_options:
for rpm_opt, attr, default in script_options:
# Insert contents of file referred to, if no file is referred to
# use 'default' as contents of script
val = getattr(self, attr)
Expand Down
1 change: 0 additions & 1 deletion setuptools/_distutils/command/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def show_compilers():


class build(Command):

description = "build everything needed to install"

user_options = [
Expand Down
9 changes: 4 additions & 5 deletions setuptools/_distutils/command/build_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def show_compilers():


class build_clib(Command):

description = "build C/C++ libraries used by Python extensions"

user_options = [
Expand Down Expand Up @@ -103,7 +102,7 @@ def run(self):
self.compiler.set_include_dirs(self.include_dirs)
if self.define is not None:
# 'define' option is a list of (name,value) tuples
for (name, value) in self.define:
for name, value in self.define:
self.compiler.define_macro(name, value)
if self.undef is not None:
for macro in self.undef:
Expand Down Expand Up @@ -155,14 +154,14 @@ def get_library_names(self):
return None

lib_names = []
for (lib_name, build_info) in self.libraries:
for lib_name, build_info in self.libraries:
lib_names.append(lib_name)
return lib_names

def get_source_files(self):
self.check_library_list(self.libraries)
filenames = []
for (lib_name, build_info) in self.libraries:
for lib_name, build_info in self.libraries:
sources = build_info.get('sources')
if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError(
Expand All @@ -175,7 +174,7 @@ def get_source_files(self):
return filenames

def build_libraries(self, libraries):
for (lib_name, build_info) in libraries:
for lib_name, build_info in libraries:
sources = build_info.get('sources')
if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError(
Expand Down
5 changes: 2 additions & 3 deletions setuptools/_distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def show_compilers():


class build_ext(Command):

description = "build C/C++ extensions (compile/link to build directory)"

# XXX thoughts on how to deal with complex command-line options like
Expand Down Expand Up @@ -328,7 +327,7 @@ def run(self): # noqa: C901
self.compiler.set_include_dirs(self.include_dirs)
if self.define is not None:
# 'define' option is a list of (name,value) tuples
for (name, value) in self.define:
for name, value in self.define:
self.compiler.define_macro(name, value)
if self.undef is not None:
for macro in self.undef:
Expand Down Expand Up @@ -721,7 +720,7 @@ def get_export_symbols(self, ext):
name = ext.name.split('.')[-1]
try:
# Unicode module name support as defined in PEP-489
# https://www.python.org/dev/peps/pep-0489/#export-hook-name
# https://peps.python.org/pep-0489/#export-hook-name
name.encode('ascii')
except UnicodeEncodeError:
suffix = 'U_' + name.encode('punycode').replace(b'-', b'_').decode('ascii')
Expand Down
7 changes: 3 additions & 4 deletions setuptools/_distutils/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


class build_py(Command):

description = "\"build\" pure Python modules (copy to build directory)"

user_options = [
Expand Down Expand Up @@ -310,7 +309,7 @@ def get_module_outfile(self, build_dir, package, module):
def get_outputs(self, include_bytecode=1):
modules = self.find_all_modules()
outputs = []
for (package, module, module_file) in modules:
for package, module, module_file in modules:
package = package.split('.')
filename = self.get_module_outfile(self.build_lib, package, module)
outputs.append(filename)
Expand Down Expand Up @@ -352,7 +351,7 @@ def build_module(self, module, module_file, package):

def build_modules(self):
modules = self.find_modules()
for (package, module, module_file) in modules:
for package, module, module_file in modules:
# Now "build" the module -- ie. copy the source file to
# self.build_lib (the build directory for Python source).
# (Actually, it gets copied to the directory for this package
Expand All @@ -375,7 +374,7 @@ def build_packages(self):

# Now loop over the modules we found, "building" each one (just
# copy it to self.build_lib).
for (package_, module, module_file) in modules:
for package_, module, module_file in modules:
assert package == package_
self.build_module(module, module_file, package)

Expand Down
1 change: 0 additions & 1 deletion setuptools/_distutils/command/build_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class build_scripts(Command):

description = "\"build\" scripts (copy and fixup #! line)"

user_options = [
Expand Down
1 change: 0 additions & 1 deletion setuptools/_distutils/command/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class clean(Command):

description = "clean up temporary files from 'build' command"
user_options = [
('build-base=', 'b', "base build directory (default: 'build.build-base')"),
Expand Down
1 change: 0 additions & 1 deletion setuptools/_distutils/command/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


class config(Command):

description = "prepare to build"

user_options = [
Expand Down
Loading

0 comments on commit bb17d4f

Please sign in to comment.