Skip to content

Commit bb17d4f

Browse files
authored
Merge pull request #3809 from pypa/distutils-8c3c3d29
Merge with distutils@8c3c3d29
2 parents 8032430 + 47c7cfd commit bb17d4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+153
-111
lines changed

changelog.d/3809.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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).

setuptools/_distutils/_collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def bounds(self):
185185
return (sorted_keys[RangeMap.first_item], sorted_keys[RangeMap.last_item])
186186

187187
# some special values for the RangeMap
188-
undefined_value = type(str('RangeValueUndefined'), (), {})()
188+
undefined_value = type('RangeValueUndefined', (), {})()
189189

190190
class Item(int):
191191
"RangeMap Item"

setuptools/_distutils/_msvccompiler.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ def compile( # noqa: C901
339339
extra_postargs=None,
340340
depends=None,
341341
):
342-
343342
if not self.initialized:
344343
self.initialize()
345344
compile_info = self._setup_compile(
@@ -413,8 +412,7 @@ def compile( # noqa: C901
413412
args = [self.cc] + compile_opts + pp_opts
414413
if add_cpp_opts:
415414
args.append('/EHsc')
416-
args.append(input_opt)
417-
args.append("/Fo" + obj)
415+
args.extend((input_opt, "/Fo" + obj))
418416
args.extend(extra_postargs)
419417

420418
try:
@@ -427,7 +425,6 @@ def compile( # noqa: C901
427425
def create_static_lib(
428426
self, objects, output_libname, output_dir=None, debug=0, target_lang=None
429427
):
430-
431428
if not self.initialized:
432429
self.initialize()
433430
objects, output_dir = self._fix_object_args(objects, output_dir)
@@ -461,7 +458,6 @@ def link(
461458
build_temp=None,
462459
target_lang=None,
463460
):
464-
465461
if not self.initialized:
466462
self.initialize()
467463
objects, output_dir = self._fix_object_args(objects, output_dir)

setuptools/_distutils/bcppcompiler.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class BCPPCompiler(CCompiler):
6464
exe_extension = '.exe'
6565

6666
def __init__(self, verbose=0, dry_run=0, force=0):
67-
6867
super().__init__(verbose, dry_run, force)
6968

7069
# These executables are assumed to all be in the path.
@@ -98,7 +97,6 @@ def compile( # noqa: C901
9897
extra_postargs=None,
9998
depends=None,
10099
):
101-
102100
macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
103101
output_dir, macros, include_dirs, sources, depends, extra_postargs
104102
)
@@ -167,7 +165,6 @@ def compile( # noqa: C901
167165
def create_static_lib(
168166
self, objects, output_libname, output_dir=None, debug=0, target_lang=None
169167
):
170-
171168
(objects, output_dir) = self._fix_object_args(objects, output_dir)
172169
output_filename = self.library_filename(output_libname, output_dir=output_dir)
173170

@@ -200,7 +197,6 @@ def link( # noqa: C901
200197
build_temp=None,
201198
target_lang=None,
202199
):
203-
204200
# XXX this ignores 'build_temp'! should follow the lead of
205201
# msvccompiler.py
206202

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

221217
if self._need_link(objects, output_filename):
222-
223218
# Figure out linker args based on type of target.
224219
if target_desc == CCompiler.EXECUTABLE:
225220
startup_obj = 'c0w32'
@@ -294,8 +289,7 @@ def link( # noqa: C901
294289
ld_args.append(libfile)
295290

296291
# some default libraries
297-
ld_args.append('import32')
298-
ld_args.append('cw32mt')
292+
ld_args.extend(('import32', 'cw32mt'))
299293

300294
# def file for export symbols
301295
ld_args.extend([',', def_file])
@@ -381,7 +375,6 @@ def preprocess(
381375
extra_preargs=None,
382376
extra_postargs=None,
383377
):
384-
385378
(_, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
386379
pp_opts = gen_preprocess_options(macros, include_dirs)
387380
pp_args = ['cpp32.exe'] + pp_opts

setuptools/_distutils/ccompiler.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
import os
88
import re
9+
import warnings
910

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

390391
if include_dirs is None:
391-
include_dirs = self.include_dirs
392+
include_dirs = list(self.include_dirs)
392393
elif isinstance(include_dirs, (list, tuple)):
393394
include_dirs = list(include_dirs) + (self.include_dirs or [])
394395
else:
@@ -824,9 +825,19 @@ def has_function( # noqa: C901
824825
libraries=None,
825826
library_dirs=None,
826827
):
827-
"""Return a boolean indicating whether funcname is supported on
828-
the current platform. The optional arguments can be used to
829-
augment the compilation environment.
828+
"""Return a boolean indicating whether funcname is provided as
829+
a symbol on the current platform. The optional arguments can
830+
be used to augment the compilation environment.
831+
832+
The libraries argument is a list of flags to be passed to the
833+
linker to make additional symbol definitions available for
834+
linking.
835+
836+
The includes and include_dirs arguments are deprecated.
837+
Usually, supplying include files with function declarations
838+
will cause function detection to fail even in cases where the
839+
symbol is available for linking.
840+
830841
"""
831842
# this can't be included at module scope because it tries to
832843
# import math which might not be available at that point - maybe
@@ -835,8 +846,12 @@ def has_function( # noqa: C901
835846

836847
if includes is None:
837848
includes = []
849+
else:
850+
warnings.warn("includes is deprecated", DeprecationWarning)
838851
if include_dirs is None:
839852
include_dirs = []
853+
else:
854+
warnings.warn("include_dirs is deprecated", DeprecationWarning)
840855
if libraries is None:
841856
libraries = []
842857
if library_dirs is None:
@@ -845,7 +860,24 @@ def has_function( # noqa: C901
845860
f = os.fdopen(fd, "w")
846861
try:
847862
for incl in includes:
848-
f.write("""#include "%s"\n""" % incl)
863+
f.write("""#include %s\n""" % incl)
864+
if not includes:
865+
# Use "char func(void);" as the prototype to follow
866+
# what autoconf does. This prototype does not match
867+
# any well-known function the compiler might recognize
868+
# as a builtin, so this ends up as a true link test.
869+
# Without a fake prototype, the test would need to
870+
# know the exact argument types, and the has_function
871+
# interface does not provide that level of information.
872+
f.write(
873+
"""\
874+
#ifdef __cplusplus
875+
extern "C"
876+
#endif
877+
char %s(void);
878+
"""
879+
% funcname
880+
)
849881
f.write(
850882
"""\
851883
int main (int argc, char **argv) {
@@ -871,7 +903,9 @@ def has_function( # noqa: C901
871903
except (LinkError, TypeError):
872904
return False
873905
else:
874-
os.remove(os.path.join(self.output_dir or '', "a.out"))
906+
os.remove(
907+
self.executable_filename("a.out", output_dir=self.output_dir or '')
908+
)
875909
finally:
876910
for fn in objects:
877911
os.remove(fn)

setuptools/_distutils/cmd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def dump_options(self, header=None, indent=""):
160160
header = "command options for '%s':" % self.get_command_name()
161161
self.announce(indent + header, level=logging.INFO)
162162
indent = indent + " "
163-
for (option, _, _) in self.user_options:
163+
for option, _, _ in self.user_options:
164164
option = option.translate(longopt_xlate)
165165
if option[-1] == "=":
166166
option = option[:-1]
@@ -291,7 +291,7 @@ def set_undefined_options(self, src_cmd, *option_pairs):
291291
# Option_pairs: list of (src_option, dst_option) tuples
292292
src_cmd_obj = self.distribution.get_command_obj(src_cmd)
293293
src_cmd_obj.ensure_finalized()
294-
for (src_option, dst_option) in option_pairs:
294+
for src_option, dst_option in option_pairs:
295295
if getattr(self, dst_option) is None:
296296
setattr(self, dst_option, getattr(src_cmd_obj, src_option))
297297

@@ -325,7 +325,7 @@ def get_sub_commands(self):
325325
run for the current distribution. Return a list of command names.
326326
"""
327327
commands = []
328-
for (cmd_name, method) in self.sub_commands:
328+
for cmd_name, method in self.sub_commands:
329329
if method is None or method(self):
330330
commands.append(cmd_name)
331331
return commands

setuptools/_distutils/command/bdist.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def append(self, item):
3333

3434

3535
class bdist(Command):
36-
3736
description = "create a built (binary) distribution"
3837

3938
user_options = [

setuptools/_distutils/command/bdist_dumb.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
class bdist_dumb(Command):
17-
1817
description = "create a \"dumb\" built distribution"
1918

2019
user_options = [

setuptools/_distutils/command/bdist_rpm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222

2323
class bdist_rpm(Command):
24-
2524
description = "create an RPM distribution"
2625

2726
user_options = [
@@ -554,7 +553,7 @@ def _make_spec_file(self): # noqa: C901
554553
('postun', 'post_uninstall', None),
555554
]
556555

557-
for (rpm_opt, attr, default) in script_options:
556+
for rpm_opt, attr, default in script_options:
558557
# Insert contents of file referred to, if no file is referred to
559558
# use 'default' as contents of script
560559
val = getattr(self, attr)

setuptools/_distutils/command/build.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def show_compilers():
1616

1717

1818
class build(Command):
19-
2019
description = "build everything needed to install"
2120

2221
user_options = [

0 commit comments

Comments
 (0)