bpo-36146: Add TEST_EXTENSIONS to setup.py (GH-12129) · python/cpython@cfe172d (original) (raw)
`@@ -20,6 +20,13 @@
`
20
20
`from distutils.spawn import find_executable
`
21
21
``
22
22
``
``
23
`+
Compile extensions used to test Python?
`
``
24
`+
TEST_EXTENSIONS = True
`
``
25
+
``
26
`+
This global variable is used to hold the list of modules to be disabled.
`
``
27
`+
DISABLED_MODULE_LIST = []
`
``
28
+
``
29
+
23
30
`def get_platform():
`
24
31
`# Cross compiling
`
25
32
`if "_PYTHON_HOST_PLATFORM" in os.environ:
`
`@@ -36,15 +43,8 @@ def get_platform():
`
36
43
`MS_WINDOWS = (HOST_PLATFORM == 'win32')
`
37
44
`CYGWIN = (HOST_PLATFORM == 'cygwin')
`
38
45
`MACOS = (HOST_PLATFORM == 'darwin')
`
39
``
-
40
46
`VXWORKS = ('vxworks' in HOST_PLATFORM)
`
41
47
``
42
``
`-
Were we compiled --with-pydebug or with #define Py_DEBUG?
`
43
``
`-
COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
`
44
``
-
45
``
`-
This global variable is used to hold the list of modules to be disabled.
`
46
``
`-
DISABLED_MODULE_LIST = []
`
47
``
-
48
48
``
49
49
`SUMMARY = """
`
50
50
`Python is an interpreted, interactive, object-oriented programming
`
`@@ -242,13 +242,6 @@ def find_library_file(compiler, libname, std_dirs, paths):
`
242
242
`assert False, "Internal error: Path not found in std_dirs or paths"
`
243
243
``
244
244
``
245
``
`-
def module_enabled(extlist, modname):
`
246
``
`-
"""Returns whether the module 'modname' is present in the list
`
247
``
`-
of extensions 'extlist'."""
`
248
``
`-
extlist = [ext for ext in extlist if ext.name == modname]
`
249
``
`-
return len(extlist)
`
250
``
-
251
``
-
252
245
`def find_module_file(module, dirlist):
`
253
246
`"""Find a module in a set of possible folders. If it is not found
`
254
247
` return the unadorned filename"""
`
`@@ -592,18 +585,7 @@ def add_cross_compiling_paths(self):
`
592
585
`finally:
`
593
586
`os.unlink(tmpfile)
`
594
587
``
595
``
`-
def add_compiler_directories(self):
`
596
``
`-
Ensure that /usr/local is always used, but the local build
`
597
``
`-
directories (i.e. '.' and 'Include') must be first. See issue
`
598
``
`-
10520.
`
599
``
`-
if not CROSS_COMPILING:
`
600
``
`-
add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
`
601
``
`-
add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
`
602
``
`-
only change this for cross builds for 3.3, issues on Mageia
`
603
``
`-
if CROSS_COMPILING:
`
604
``
`-
self.add_cross_compiling_paths()
`
605
``
`-
self.add_multiarch_paths()
`
606
``
-
``
588
`+
def add_ldflags_cppflags(self):
`
607
589
`# Add paths specified in the environment variables LDFLAGS and
`
608
590
`# CPPFLAGS for header and library files.
`
609
591
`# We must get the values from the Makefile and not the environment
`
`@@ -623,6 +605,19 @@ def add_compiler_directories(self):
`
623
605
`for directory in reversed(options.dirs):
`
624
606
`add_dir_to_list(dir_list, directory)
`
625
607
``
``
608
`+
def configure_compiler(self):
`
``
609
`+
Ensure that /usr/local is always used, but the local build
`
``
610
`+
directories (i.e. '.' and 'Include') must be first. See issue
`
``
611
`+
10520.
`
``
612
`+
if not CROSS_COMPILING:
`
``
613
`+
add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
`
``
614
`+
add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
`
``
615
`+
only change this for cross builds for 3.3, issues on Mageia
`
``
616
`+
if CROSS_COMPILING:
`
``
617
`+
self.add_cross_compiling_paths()
`
``
618
`+
self.add_multiarch_paths()
`
``
619
`+
self.add_ldflags_cppflags()
`
``
620
+
626
621
`def init_inc_lib_dirs(self):
`
627
622
`if (not CROSS_COMPILING and
`
628
623
`os.path.normpath(sys.base_prefix) != '/usr' and
`
`@@ -697,13 +692,15 @@ def detect_simple_extensions(self):
`
697
692
`self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
`
698
693
``
699
694
`shared_math = 'Modules/_math.o'
`
700
``
`-
complex math library functions
`
701
``
`-
self.add(Extension('cmath', ['cmathmodule.c'],
`
``
695
+
``
696
`+
math library functions, e.g. sin()
`
``
697
`+
self.add(Extension('math', ['mathmodule.c'],
`
702
698
`extra_objects=[shared_math],
`
703
699
`depends=['_math.h', shared_math],
`
704
700
`libraries=['m']))
`
705
``
`-
math library functions, e.g. sin()
`
706
``
`-
self.add(Extension('math', ['mathmodule.c'],
`
``
701
+
``
702
`+
complex math library functions
`
``
703
`+
self.add(Extension('cmath', ['cmathmodule.c'],
`
707
704
`extra_objects=[shared_math],
`
708
705
`depends=['_math.h', shared_math],
`
709
706
`libraries=['m']))
`
`@@ -735,15 +732,7 @@ def detect_simple_extensions(self):
`
735
732
`self.add(Extension("_json", ["_json.c"],
`
736
733
`# pycore_accu.h requires Py_BUILD_CORE_BUILTIN
`
737
734
`extra_compile_args=['-DPy_BUILD_CORE_BUILTIN']))
`
738
``
`-
Python C API test module
`
739
``
`-
self.add(Extension('_testcapi', ['_testcapimodule.c'],
`
740
``
`-
depends=['testcapi_long.h']))
`
741
``
`-
Python PEP-3118 (buffer protocol) test module
`
742
``
`-
self.add(Extension('_testbuffer', ['_testbuffer.c']))
`
743
``
`-
Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
`
744
``
`-
self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
`
745
``
`-
Test multi-phase extension module init (PEP 489)
`
746
``
`-
self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
`
``
735
+
747
736
`# profiler (_lsprof is for cProfile.py)
`
748
737
`self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
`
749
738
`# static Unicode character database
`
`@@ -794,11 +783,6 @@ def detect_simple_extensions(self):
`
794
783
`# syslog daemon interface
`
795
784
`self.add(Extension('syslog', ['syslogmodule.c']))
`
796
785
``
797
``
`-
Fuzz tests.
`
798
``
`-
self.add(Extension('_xxtestfuzz',
`
799
``
`-
['_xxtestfuzz/_xxtestfuzz.c',
`
800
``
`-
'_xxtestfuzz/fuzzer.c']))
`
801
``
-
802
786
`# Python interface to subinterpreter C-API.
`
803
787
`self.add(Extension('_xxsubinterpreters',
`
804
788
` ['_xxsubinterpretersmodule.c'],
`
`@@ -827,6 +811,25 @@ def detect_simple_extensions(self):
`
827
811
`# POSIX subprocess module helper.
`
828
812
`self.add(Extension('_posixsubprocess', ['_posixsubprocess.c']))
`
829
813
``
``
814
`+
def detect_test_extensions(self):
`
``
815
`+
Python C API test module
`
``
816
`+
self.add(Extension('_testcapi', ['_testcapimodule.c'],
`
``
817
`+
depends=['testcapi_long.h']))
`
``
818
+
``
819
`+
Python PEP-3118 (buffer protocol) test module
`
``
820
`+
self.add(Extension('_testbuffer', ['_testbuffer.c']))
`
``
821
+
``
822
`+
Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
`
``
823
`+
self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
`
``
824
+
``
825
`+
Test multi-phase extension module init (PEP 489)
`
``
826
`+
self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
`
``
827
+
``
828
`+
Fuzz tests.
`
``
829
`+
self.add(Extension('_xxtestfuzz',
`
``
830
`+
['_xxtestfuzz/_xxtestfuzz.c',
`
``
831
`+
'_xxtestfuzz/fuzzer.c']))
`
``
832
+
830
833
`def detect_readline_curses(self):
`
831
834
`# readline
`
832
835
`do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')
`
`@@ -936,6 +939,7 @@ def detect_readline_curses(self):
`
936
939
`curses_defines.append(('HAVE_NCURSESW', '1'))
`
937
940
`curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
`
938
941
``
``
942
`+
curses_enabled = True
`
939
943
`if curses_library.startswith('ncurses'):
`
940
944
`curses_libs = [curses_library]
`
941
945
`self.add(Extension('_curses', ['_cursesmodule.c'],
`
`@@ -956,10 +960,11 @@ def detect_readline_curses(self):
`
956
960
`define_macros=curses_defines,
`
957
961
`libraries=curses_libs))
`
958
962
`else:
`
``
963
`+
curses_enabled = False
`
959
964
`self.missing.append('_curses')
`
960
965
``
961
966
`# If the curses module is enabled, check for the panel module
`
962
``
`-
if (module_enabled(self.extensions, '_curses') and
`
``
967
`+
if (curses_enabled and
`
963
968
`self.compiler.find_library_file(self.lib_dirs, panel_library)):
`
964
969
`self.add(Extension('_curses_panel', ['_curses_panel.c'],
`
965
970
`include_dirs=curses_includes,
`
`@@ -1622,17 +1627,19 @@ def detect_uuid(self):
`
1622
1627
`uuid_libs = ['uuid']
`
1623
1628
`else:
`
1624
1629
`uuid_libs = []
`
1625
``
`-
self.extensions.append(Extension('_uuid', ['_uuidmodule.c'],
`
1626
``
`-
libraries=uuid_libs,
`
1627
``
`-
include_dirs=uuid_incs))
`
``
1630
`+
self.add(Extension('_uuid', ['_uuidmodule.c'],
`
``
1631
`+
libraries=uuid_libs,
`
``
1632
`+
include_dirs=uuid_incs))
`
1628
1633
`else:
`
1629
1634
`self.missing.append('_uuid')
`
1630
1635
``
1631
1636
`def detect_modules(self):
`
1632
``
`-
self.add_compiler_directories()
`
``
1637
`+
self.configure_compiler()
`
1633
1638
`self.init_inc_lib_dirs()
`
1634
1639
``
1635
1640
`self.detect_simple_extensions()
`
``
1641
`+
if TEST_EXTENSIONS:
`
``
1642
`+
self.detect_test_extensions()
`
1636
1643
`self.detect_readline_curses()
`
1637
1644
`self.detect_crypt()
`
1638
1645
`self.detect_socket()
`
`@@ -1652,13 +1659,11 @@ def detect_modules(self):
`
1652
1659
`self.detect_uuid()
`
1653
1660
``
1654
1661
`## # Uncomment these lines if you want to play with xxmodule.c
`
1655
``
`-
ext = Extension('xx', ['xxmodule.c'])
`
1656
``
`-
self.extensions.append(ext)
`
``
1662
`+
self.add(Extension('xx', ['xxmodule.c']))
`
1657
1663
``
1658
1664
`if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
`
1659
``
`-
ext = Extension('xxlimited', ['xxlimited.c'],
`
1660
``
`-
define_macros=[('Py_LIMITED_API', '0x03050000')])
`
1661
``
`-
self.extensions.append(ext)
`
``
1665
`+
self.add(Extension('xxlimited', ['xxlimited.c'],
`
``
1666
`+
define_macros=[('Py_LIMITED_API', '0x03050000')]))
`
1662
1667
``
1663
1668
`def detect_tkinter_explicitly(self):
`
1664
1669
`# Build _tkinter using explicit locations for Tcl/Tk.
`
`@@ -1687,12 +1692,10 @@ def detect_tkinter_explicitly(self):
`
1687
1692
``
1688
1693
`extra_compile_args = tcltk_includes.split()
`
1689
1694
`extra_link_args = tcltk_libs.split()
`
1690
``
`-
ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
`
1691
``
`-
define_macros=[('WITH_APPINIT', 1)],
`
1692
``
`-
extra_compile_args = extra_compile_args,
`
1693
``
`-
extra_link_args = extra_link_args,
`
1694
``
`-
)
`
1695
``
`-
self.extensions.append(ext)
`
``
1695
`+
self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
`
``
1696
`+
define_macros=[('WITH_APPINIT', 1)],
`
``
1697
`+
extra_compile_args = extra_compile_args,
`
``
1698
`+
extra_link_args = extra_link_args))
`
1696
1699
`return True
`
1697
1700
``
1698
1701
`def detect_tkinter_darwin(self):
`
`@@ -1774,14 +1777,12 @@ def detect_tkinter_darwin(self):
`
1774
1777
`frameworks.append('-arch')
`
1775
1778
`frameworks.append(a)
`
1776
1779
``
1777
``
`-
ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
`
1778
``
`-
define_macros=[('WITH_APPINIT', 1)],
`
1779
``
`-
include_dirs = include_dirs,
`
1780
``
`-
libraries = [],
`
1781
``
`-
extra_compile_args = frameworks[2:],
`
1782
``
`-
extra_link_args = frameworks,
`
1783
``
`-
)
`
1784
``
`-
self.extensions.append(ext)
`
``
1780
`+
self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
`
``
1781
`+
define_macros=[('WITH_APPINIT', 1)],
`
``
1782
`+
include_dirs=include_dirs,
`
``
1783
`+
libraries=[],
`
``
1784
`+
extra_compile_args=frameworks[2:],
`
``
1785
`+
extra_link_args=frameworks))
`
1785
1786
`return True
`
1786
1787
``
1787
1788
`def detect_tkinter(self):
`
`@@ -1839,7 +1840,10 @@ def detect_tkinter(self):
`
1839
1840
``
1840
1841
`# OK... everything seems to be present for Tcl/Tk.
`
1841
1842
``
1842
``
`-
include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
`
``
1843
`+
include_dirs = []
`
``
1844
`+
libs = []
`
``
1845
`+
defs = []
`
``
1846
`+
added_lib_dirs = []
`
1843
1847
`for dir in tcl_includes + tk_includes:
`
1844
1848
`if dir not in include_dirs:
`
1845
1849
`include_dirs.append(dir)
`
`@@ -1895,13 +1899,11 @@ def detect_tkinter(self):
`
1895
1899
`# *** Uncomment these for TOGL extension only:
`
1896
1900
`# -lGL -lGLU -lXext -lXmu \
`
1897
1901
``
1898
``
`-
ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
`
1899
``
`-
define_macros=[('WITH_APPINIT', 1)] + defs,
`
1900
``
`-
include_dirs = include_dirs,
`
1901
``
`-
libraries = libs,
`
1902
``
`-
library_dirs = added_lib_dirs,
`
1903
``
`-
)
`
1904
``
`-
self.extensions.append(ext)
`
``
1902
`+
self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
`
``
1903
`+
define_macros=[('WITH_APPINIT', 1)] + defs,
`
``
1904
`+
include_dirs=include_dirs,
`
``
1905
`+
libraries=libs,
`
``
1906
`+
library_dirs=added_lib_dirs))
`
1905
1907
`return True
`
1906
1908
``
1907
1909
`def configure_ctypes_darwin(self, ext):
`
`@@ -1980,11 +1982,12 @@ def detect_ctypes(self):
`
1980
1982
`libraries=[],
`
1981
1983
`sources=sources,
`
1982
1984
`depends=depends)
`
1983
``
`-
function my_sqrt() needs libm for sqrt()
`
1984
``
`-
ext_test = Extension('_ctypes_test',
`
1985
``
`-
sources=['_ctypes/_ctypes_test.c'],
`
1986
``
`-
libraries=['m'])
`
1987
``
`-
self.extensions.extend([ext, ext_test])
`
``
1985
`+
self.add(ext)
`
``
1986
`+
if TEST_EXTENSIONS:
`
``
1987
`+
function my_sqrt() needs libm for sqrt()
`
``
1988
`+
self.add(Extension('_ctypes_test',
`
``
1989
`+
sources=['_ctypes/_ctypes_test.c'],
`
``
1990
`+
libraries=['m']))
`
1988
1991
``
1989
1992
`ffi_inc_dirs = self.inc_dirs.copy()
`
1990
1993
`if MACOS:
`