From 676e669a317d6a4804f8f8bf438fd1e31afbd306 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 26 Dec 2021 16:38:52 +0100 Subject: [PATCH 01/14] sysconfig: use get_config_h_filename() from the stdlib distutils.sysconfig provides various functions already present in the stdlib sysconfig module. Reusing the stdlib versions has the advantage that it is in control of the Python distributor/packager and distutils doesn't have to deal with platform details. This tries to start the transition using the simple get_config_h_filename() for starters by forwarding calls to the stdlib in case Python is considered to be installed. --- distutils/sysconfig.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index d36d94f76f..2300014d61 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -13,6 +13,7 @@ import os import re import sys +import sysconfig from .errors import DistutilsPlatformError @@ -274,10 +275,10 @@ def get_config_h_filename(): inc_dir = os.path.join(_sys_home or project_base, "PC") else: inc_dir = _sys_home or project_base + return os.path.join(inc_dir, 'pyconfig.h') else: - inc_dir = get_python_inc(plat_specific=1) + return sysconfig.get_config_h_filename() - return os.path.join(inc_dir, 'pyconfig.h') # Allow this value to be patched by pkgsrc. Ref pypa/distutils#16. From b17dad6615d9b2f4fe255ec6750b2765d9b281f1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 26 Dec 2021 14:47:29 -0500 Subject: [PATCH 02/14] =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20?= =?UTF-8?q?(delint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- distutils/log.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/distutils/log.py b/distutils/log.py index 8ef6b28ea2..a68b156b5b 100644 --- a/distutils/log.py +++ b/distutils/log.py @@ -3,13 +3,14 @@ # The class here is styled after PEP 282 so that it could later be # replaced with a standard Python logging implementation. +import sys + DEBUG = 1 INFO = 2 WARN = 3 ERROR = 4 FATAL = 5 -import sys class Log: @@ -54,6 +55,7 @@ def error(self, msg, *args): def fatal(self, msg, *args): self._log(FATAL, msg, args) + _global_log = Log() log = _global_log.log debug = _global_log.debug @@ -62,12 +64,14 @@ def fatal(self, msg, *args): error = _global_log.error fatal = _global_log.fatal + def set_threshold(level): # return the old threshold for use from tests old = _global_log.threshold _global_log.threshold = level return old + def set_verbosity(v): if v <= 0: set_threshold(WARN) From 9d0b8cda4075e1f654b8e633957f76b921c608cd Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 26 Dec 2021 19:40:43 +0100 Subject: [PATCH 03/14] sysconfig: use parse_config_h() from stdlib sysconfig The only difference is the argument name change --- distutils/sysconfig.py | 22 ++-------------------- distutils/tests/test_sysconfig.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index d36d94f76f..94993cc59a 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -13,6 +13,7 @@ import os import re import sys +import sysconfig from .errors import DistutilsPlatformError @@ -308,26 +309,7 @@ def parse_config_h(fp, g=None): optional dictionary is passed in as the second argument, it is used instead of a new dictionary. """ - if g is None: - g = {} - define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n") - undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n") - # - while True: - line = fp.readline() - if not line: - break - m = define_rx.match(line) - if m: - n, v = m.group(1, 2) - try: v = int(v) - except ValueError: pass - g[n] = v - else: - m = undef_rx.match(line) - if m: - g[m.group(1)] = 0 - return g + return sysconfig.parse_config_h(fp, vars=g) # Regexes needed for parsing Makefile (and similar syntaxes, diff --git a/distutils/tests/test_sysconfig.py b/distutils/tests/test_sysconfig.py index 80cd1599a7..d28f47120e 100644 --- a/distutils/tests/test_sysconfig.py +++ b/distutils/tests/test_sysconfig.py @@ -283,6 +283,16 @@ def test_customize_compiler_before_get_config_vars(self): outs, errs = p.communicate() self.assertEqual(0, p.returncode, "Subprocess failed: " + outs) + def test_parse_config_h(self): + config_h = sysconfig.get_config_h_filename() + input = {} + with open(config_h, encoding="utf-8") as f: + result = sysconfig.parse_config_h(f, g=input) + self.assertTrue(input) + self.assertTrue(input is result) + with open(config_h, encoding="utf-8") as f: + result = sysconfig.parse_config_h(f) + self.assertTrue(result) def test_suite(): suite = unittest.TestSuite() From 9c4d48c1312192af1e42d9baf5d3bad7e4fe7bae Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Mon, 27 Dec 2021 09:48:30 +0100 Subject: [PATCH 04/14] tests: use loadTestsFromTestCase() instead of the deprecated makeSuite() See https://github.com/python/cpython/pull/28299 loadTestsFromTestCase() is available since Python 2.7 at least. --- distutils/tests/test_archive_util.py | 2 +- distutils/tests/test_bdist.py | 2 +- distutils/tests/test_bdist_dumb.py | 2 +- distutils/tests/test_bdist_msi.py | 2 +- distutils/tests/test_bdist_rpm.py | 2 +- distutils/tests/test_bdist_wininst.py | 2 +- distutils/tests/test_build.py | 2 +- distutils/tests/test_build_clib.py | 2 +- distutils/tests/test_build_ext.py | 4 ++-- distutils/tests/test_build_py.py | 2 +- distutils/tests/test_build_scripts.py | 2 +- distutils/tests/test_check.py | 2 +- distutils/tests/test_clean.py | 2 +- distutils/tests/test_cmd.py | 2 +- distutils/tests/test_config.py | 2 +- distutils/tests/test_config_cmd.py | 2 +- distutils/tests/test_core.py | 2 +- distutils/tests/test_cygwinccompiler.py | 2 +- distutils/tests/test_dep_util.py | 2 +- distutils/tests/test_dir_util.py | 2 +- distutils/tests/test_dist.py | 4 ++-- distutils/tests/test_extension.py | 2 +- distutils/tests/test_file_util.py | 2 +- distutils/tests/test_filelist.py | 4 ++-- distutils/tests/test_install.py | 2 +- distutils/tests/test_install_data.py | 2 +- distutils/tests/test_install_headers.py | 2 +- distutils/tests/test_install_lib.py | 2 +- distutils/tests/test_install_scripts.py | 2 +- distutils/tests/test_log.py | 2 +- distutils/tests/test_msvc9compiler.py | 2 +- distutils/tests/test_msvccompiler.py | 2 +- distutils/tests/test_register.py | 2 +- distutils/tests/test_sdist.py | 2 +- distutils/tests/test_spawn.py | 2 +- distutils/tests/test_sysconfig.py | 2 +- distutils/tests/test_text_file.py | 2 +- distutils/tests/test_unixccompiler.py | 2 +- distutils/tests/test_upload.py | 2 +- distutils/tests/test_util.py | 2 +- distutils/tests/test_version.py | 2 +- 41 files changed, 44 insertions(+), 44 deletions(-) diff --git a/distutils/tests/test_archive_util.py b/distutils/tests/test_archive_util.py index c5560372bd..800b90180e 100644 --- a/distutils/tests/test_archive_util.py +++ b/distutils/tests/test_archive_util.py @@ -387,7 +387,7 @@ def test_tarfile_root_owner(self): archive.close() def test_suite(): - return unittest.makeSuite(ArchiveUtilTestCase) + return unittest.TestLoader().loadTestsFromTestCase(ArchiveUtilTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_bdist.py b/distutils/tests/test_bdist.py index 130d8bf155..8b7498e3eb 100644 --- a/distutils/tests/test_bdist.py +++ b/distutils/tests/test_bdist.py @@ -51,7 +51,7 @@ def test_skip_build(self): def test_suite(): - return unittest.makeSuite(BuildTestCase) + return unittest.TestLoader().loadTestsFromTestCase(BuildTestCase) if __name__ == '__main__': run_unittest(test_suite()) diff --git a/distutils/tests/test_bdist_dumb.py b/distutils/tests/test_bdist_dumb.py index 01a233bce3..bb860c8ac7 100644 --- a/distutils/tests/test_bdist_dumb.py +++ b/distutils/tests/test_bdist_dumb.py @@ -91,7 +91,7 @@ def test_simple_built(self): self.assertEqual(contents, sorted(wanted)) def test_suite(): - return unittest.makeSuite(BuildDumbTestCase) + return unittest.TestLoader().loadTestsFromTestCase(BuildDumbTestCase) if __name__ == '__main__': run_unittest(test_suite()) diff --git a/distutils/tests/test_bdist_msi.py b/distutils/tests/test_bdist_msi.py index 937266f8c0..b1831ef20c 100644 --- a/distutils/tests/test_bdist_msi.py +++ b/distutils/tests/test_bdist_msi.py @@ -22,7 +22,7 @@ def test_minimal(self): def test_suite(): - return unittest.makeSuite(BDistMSITestCase) + return unittest.TestLoader().loadTestsFromTestCase(BDistMSITestCase) if __name__ == '__main__': run_unittest(test_suite()) diff --git a/distutils/tests/test_bdist_rpm.py b/distutils/tests/test_bdist_rpm.py index 6453a02b88..3b22af3a90 100644 --- a/distutils/tests/test_bdist_rpm.py +++ b/distutils/tests/test_bdist_rpm.py @@ -129,7 +129,7 @@ def test_no_optimize_flag(self): os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm')) def test_suite(): - return unittest.makeSuite(BuildRpmTestCase) + return unittest.TestLoader().loadTestsFromTestCase(BuildRpmTestCase) if __name__ == '__main__': run_unittest(test_suite()) diff --git a/distutils/tests/test_bdist_wininst.py b/distutils/tests/test_bdist_wininst.py index 31cf2628de..59f25167e6 100644 --- a/distutils/tests/test_bdist_wininst.py +++ b/distutils/tests/test_bdist_wininst.py @@ -34,7 +34,7 @@ def test_get_exe_bytes(self): self.assertGreater(len(exe_file), 10) def test_suite(): - return unittest.makeSuite(BuildWinInstTestCase) + return unittest.TestLoader().loadTestsFromTestCase(BuildWinInstTestCase) if __name__ == '__main__': run_unittest(test_suite()) diff --git a/distutils/tests/test_build.py b/distutils/tests/test_build.py index b020a5ba35..83a9e4f4dd 100644 --- a/distutils/tests/test_build.py +++ b/distutils/tests/test_build.py @@ -50,7 +50,7 @@ def test_finalize_options(self): self.assertEqual(cmd.executable, os.path.normpath(sys.executable)) def test_suite(): - return unittest.makeSuite(BuildTestCase) + return unittest.TestLoader().loadTestsFromTestCase(BuildTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_build_clib.py b/distutils/tests/test_build_clib.py index 259c43522d..d50ead7c94 100644 --- a/distutils/tests/test_build_clib.py +++ b/distutils/tests/test_build_clib.py @@ -130,7 +130,7 @@ def test_run(self): self.assertIn('libfoo.a', os.listdir(build_temp)) def test_suite(): - return unittest.makeSuite(BuildCLibTestCase) + return unittest.TestLoader().loadTestsFromTestCase(BuildCLibTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_build_ext.py b/distutils/tests/test_build_ext.py index 85ecf4b720..cb0db2b57a 100644 --- a/distutils/tests/test_build_ext.py +++ b/distutils/tests/test_build_ext.py @@ -538,8 +538,8 @@ def build_ext(self, *args, **kwargs): def test_suite(): suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(BuildExtTestCase)) - suite.addTest(unittest.makeSuite(ParallelBuildExtTestCase)) + suite.addTest(unittest.TestLoader().loadTestsFromTestCase(BuildExtTestCase)) + suite.addTest(unittest.TestLoader().loadTestsFromTestCase(ParallelBuildExtTestCase)) return suite if __name__ == '__main__': diff --git a/distutils/tests/test_build_py.py b/distutils/tests/test_build_py.py index 0712e92c6a..a590a485a2 100644 --- a/distutils/tests/test_build_py.py +++ b/distutils/tests/test_build_py.py @@ -173,7 +173,7 @@ def test_dont_write_bytecode(self): def test_suite(): - return unittest.makeSuite(BuildPyTestCase) + return unittest.TestLoader().loadTestsFromTestCase(BuildPyTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_build_scripts.py b/distutils/tests/test_build_scripts.py index 954fc76398..f299e51ef7 100644 --- a/distutils/tests/test_build_scripts.py +++ b/distutils/tests/test_build_scripts.py @@ -106,7 +106,7 @@ def test_version_int(self): self.assertIn(name, built) def test_suite(): - return unittest.makeSuite(BuildScriptsTestCase) + return unittest.TestLoader().loadTestsFromTestCase(BuildScriptsTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_check.py b/distutils/tests/test_check.py index e534aca1d4..91bcdceb43 100644 --- a/distutils/tests/test_check.py +++ b/distutils/tests/test_check.py @@ -157,7 +157,7 @@ def test_check_all(self): 'restructuredtext': 1}) def test_suite(): - return unittest.makeSuite(CheckTestCase) + return unittest.TestLoader().loadTestsFromTestCase(CheckTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_clean.py b/distutils/tests/test_clean.py index c605afd860..92367499ce 100644 --- a/distutils/tests/test_clean.py +++ b/distutils/tests/test_clean.py @@ -43,7 +43,7 @@ def test_simple_run(self): cmd.run() def test_suite(): - return unittest.makeSuite(cleanTestCase) + return unittest.TestLoader().loadTestsFromTestCase(cleanTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_cmd.py b/distutils/tests/test_cmd.py index cf5197c30f..2319214a9e 100644 --- a/distutils/tests/test_cmd.py +++ b/distutils/tests/test_cmd.py @@ -120,7 +120,7 @@ def test_debug_print(self): debug.DEBUG = False def test_suite(): - return unittest.makeSuite(CommandTestCase) + return unittest.TestLoader().loadTestsFromTestCase(CommandTestCase) if __name__ == '__main__': run_unittest(test_suite()) diff --git a/distutils/tests/test_config.py b/distutils/tests/test_config.py index 344084afb7..8ab70efb16 100644 --- a/distutils/tests/test_config.py +++ b/distutils/tests/test_config.py @@ -135,7 +135,7 @@ def test_config_interpolation(self): def test_suite(): - return unittest.makeSuite(PyPIRCCommandTestCase) + return unittest.TestLoader().loadTestsFromTestCase(PyPIRCCommandTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_config_cmd.py b/distutils/tests/test_config_cmd.py index 4cd9a6b9a0..2c84719aad 100644 --- a/distutils/tests/test_config_cmd.py +++ b/distutils/tests/test_config_cmd.py @@ -92,7 +92,7 @@ def test_clean(self): self.assertFalse(os.path.exists(f)) def test_suite(): - return unittest.makeSuite(ConfigTestCase) + return unittest.TestLoader().loadTestsFromTestCase(ConfigTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_core.py b/distutils/tests/test_core.py index d99cfd26c3..7270d699a3 100644 --- a/distutils/tests/test_core.py +++ b/distutils/tests/test_core.py @@ -159,7 +159,7 @@ def test_debug_mode(self): self.assertEqual(stdout.readlines()[0], wanted) def test_suite(): - return unittest.makeSuite(CoreTestCase) + return unittest.TestLoader().loadTestsFromTestCase(CoreTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_cygwinccompiler.py b/distutils/tests/test_cygwinccompiler.py index 0e52c88fb0..8715a53539 100644 --- a/distutils/tests/test_cygwinccompiler.py +++ b/distutils/tests/test_cygwinccompiler.py @@ -90,7 +90,7 @@ def test_get_msvcr(self): self.assertRaises(ValueError, get_msvcr) def test_suite(): - return unittest.makeSuite(CygwinCCompilerTestCase) + return unittest.TestLoader().loadTestsFromTestCase(CygwinCCompilerTestCase) if __name__ == '__main__': run_unittest(test_suite()) diff --git a/distutils/tests/test_dep_util.py b/distutils/tests/test_dep_util.py index c6fae39cfb..0d52740a9e 100644 --- a/distutils/tests/test_dep_util.py +++ b/distutils/tests/test_dep_util.py @@ -74,7 +74,7 @@ def test_newer_group(self): def test_suite(): - return unittest.makeSuite(DepUtilTestCase) + return unittest.TestLoader().loadTestsFromTestCase(DepUtilTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_dir_util.py b/distutils/tests/test_dir_util.py index d436cf8319..1b1f3bbb02 100644 --- a/distutils/tests/test_dir_util.py +++ b/distutils/tests/test_dir_util.py @@ -133,7 +133,7 @@ def test_copy_tree_exception_in_listdir(self): def test_suite(): - return unittest.makeSuite(DirUtilTestCase) + return unittest.TestLoader().loadTestsFromTestCase(DirUtilTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_dist.py b/distutils/tests/test_dist.py index 45eadee87f..36155be152 100644 --- a/distutils/tests/test_dist.py +++ b/distutils/tests/test_dist.py @@ -525,8 +525,8 @@ def test_read_metadata(self): def test_suite(): suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(DistributionTestCase)) - suite.addTest(unittest.makeSuite(MetadataTestCase)) + suite.addTest(unittest.TestLoader().loadTestsFromTestCase(DistributionTestCase)) + suite.addTest(unittest.TestLoader().loadTestsFromTestCase(MetadataTestCase)) return suite if __name__ == "__main__": diff --git a/distutils/tests/test_extension.py b/distutils/tests/test_extension.py index 2eb5b422df..78a55daa08 100644 --- a/distutils/tests/test_extension.py +++ b/distutils/tests/test_extension.py @@ -65,7 +65,7 @@ def test_extension_init(self): "Unknown Extension options: 'chic'") def test_suite(): - return unittest.makeSuite(ExtensionTestCase) + return unittest.TestLoader().loadTestsFromTestCase(ExtensionTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_file_util.py b/distutils/tests/test_file_util.py index d253607526..81b90d6c8a 100644 --- a/distutils/tests/test_file_util.py +++ b/distutils/tests/test_file_util.py @@ -118,7 +118,7 @@ def test_copy_file_hard_link_failure(self): def test_suite(): - return unittest.makeSuite(FileUtilTestCase) + return unittest.TestLoader().loadTestsFromTestCase(FileUtilTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_filelist.py b/distutils/tests/test_filelist.py index 9ec507b5d0..a90edcf138 100644 --- a/distutils/tests/test_filelist.py +++ b/distutils/tests/test_filelist.py @@ -344,8 +344,8 @@ def test_symlink_loop(self): def test_suite(): return unittest.TestSuite([ - unittest.makeSuite(FileListTestCase), - unittest.makeSuite(FindAllTestCase), + unittest.TestLoader().loadTestsFromTestCase(FileListTestCase), + unittest.TestLoader().loadTestsFromTestCase(FindAllTestCase), ]) diff --git a/distutils/tests/test_install.py b/distutils/tests/test_install.py index cce973dc57..75770b05e6 100644 --- a/distutils/tests/test_install.py +++ b/distutils/tests/test_install.py @@ -244,7 +244,7 @@ def test_debug_mode(self): def test_suite(): - return unittest.makeSuite(InstallTestCase) + return unittest.TestLoader().loadTestsFromTestCase(InstallTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_install_data.py b/distutils/tests/test_install_data.py index 32ab296a32..6191d2fa6e 100644 --- a/distutils/tests/test_install_data.py +++ b/distutils/tests/test_install_data.py @@ -69,7 +69,7 @@ def test_simple_run(self): self.assertTrue(os.path.exists(os.path.join(inst, rone))) def test_suite(): - return unittest.makeSuite(InstallDataTestCase) + return unittest.TestLoader().loadTestsFromTestCase(InstallDataTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_install_headers.py b/distutils/tests/test_install_headers.py index 2217b321e6..1aa4d09cde 100644 --- a/distutils/tests/test_install_headers.py +++ b/distutils/tests/test_install_headers.py @@ -33,7 +33,7 @@ def test_simple_run(self): self.assertEqual(len(cmd.get_outputs()), 2) def test_suite(): - return unittest.makeSuite(InstallHeadersTestCase) + return unittest.TestLoader().loadTestsFromTestCase(InstallHeadersTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_install_lib.py b/distutils/tests/test_install_lib.py index fda6315bbc..652653f2b2 100644 --- a/distutils/tests/test_install_lib.py +++ b/distutils/tests/test_install_lib.py @@ -109,7 +109,7 @@ def test_dont_write_bytecode(self): def test_suite(): - return unittest.makeSuite(InstallLibTestCase) + return unittest.TestLoader().loadTestsFromTestCase(InstallLibTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_install_scripts.py b/distutils/tests/test_install_scripts.py index 1f7b1038cb..648db3b11d 100644 --- a/distutils/tests/test_install_scripts.py +++ b/distutils/tests/test_install_scripts.py @@ -76,7 +76,7 @@ def write_script(name, text): def test_suite(): - return unittest.makeSuite(InstallScriptsTestCase) + return unittest.TestLoader().loadTestsFromTestCase(InstallScriptsTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_log.py b/distutils/tests/test_log.py index 75cf900617..ec2ae028de 100644 --- a/distutils/tests/test_log.py +++ b/distutils/tests/test_log.py @@ -40,7 +40,7 @@ def test_non_ascii(self): 'Fαtal\t\\xc8rr\\u014dr') def test_suite(): - return unittest.makeSuite(TestLog) + return unittest.TestLoader().loadTestsFromTestCase(TestLog) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_msvc9compiler.py b/distutils/tests/test_msvc9compiler.py index 77a07ef39d..6235405e31 100644 --- a/distutils/tests/test_msvc9compiler.py +++ b/distutils/tests/test_msvc9compiler.py @@ -178,7 +178,7 @@ def test_remove_entire_manifest(self): def test_suite(): - return unittest.makeSuite(msvc9compilerTestCase) + return unittest.TestLoader().loadTestsFromTestCase(msvc9compilerTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_msvccompiler.py b/distutils/tests/test_msvccompiler.py index 46a51cd0a7..aefdd8bad4 100644 --- a/distutils/tests/test_msvccompiler.py +++ b/distutils/tests/test_msvccompiler.py @@ -132,7 +132,7 @@ def CCompiler_spawn(self, cmd): def test_suite(): - return unittest.makeSuite(msvccompilerTestCase) + return unittest.TestLoader().loadTestsFromTestCase(msvccompilerTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_register.py b/distutils/tests/test_register.py index 84607f996f..5770ed58ae 100644 --- a/distutils/tests/test_register.py +++ b/distutils/tests/test_register.py @@ -319,7 +319,7 @@ def test_show_response(self): def test_suite(): - return unittest.makeSuite(RegisterTestCase) + return unittest.TestLoader().loadTestsFromTestCase(RegisterTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_sdist.py b/distutils/tests/test_sdist.py index 880044fa39..4c51717ce6 100644 --- a/distutils/tests/test_sdist.py +++ b/distutils/tests/test_sdist.py @@ -483,7 +483,7 @@ def test_make_distribution_owner_group(self): archive.close() def test_suite(): - return unittest.makeSuite(SDistTestCase) + return unittest.TestLoader().loadTestsFromTestCase(SDistTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_spawn.py b/distutils/tests/test_spawn.py index f620da7843..c5ed8e2b45 100644 --- a/distutils/tests/test_spawn.py +++ b/distutils/tests/test_spawn.py @@ -133,7 +133,7 @@ def test_spawn_missing_exe(self): def test_suite(): - return unittest.makeSuite(SpawnTestCase) + return unittest.TestLoader().loadTestsFromTestCase(SpawnTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_sysconfig.py b/distutils/tests/test_sysconfig.py index d28f47120e..93509c71d5 100644 --- a/distutils/tests/test_sysconfig.py +++ b/distutils/tests/test_sysconfig.py @@ -296,7 +296,7 @@ def test_parse_config_h(self): def test_suite(): suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(SysconfigTestCase)) + suite.addTest(unittest.TestLoader().loadTestsFromTestCase(SysconfigTestCase)) return suite diff --git a/distutils/tests/test_text_file.py b/distutils/tests/test_text_file.py index 7e76240a9a..ebac3d52f9 100644 --- a/distutils/tests/test_text_file.py +++ b/distutils/tests/test_text_file.py @@ -101,7 +101,7 @@ def test_input(count, description, file, expected_result): in_file.close() def test_suite(): - return unittest.makeSuite(TextFileTestCase) + return unittest.TestLoader().loadTestsFromTestCase(TextFileTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index 2ea93da1b5..4574f77fb4 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -246,7 +246,7 @@ def test_has_function(self): def test_suite(): - return unittest.makeSuite(UnixCCompilerTestCase) + return unittest.TestLoader().loadTestsFromTestCase(UnixCCompilerTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_upload.py b/distutils/tests/test_upload.py index bca5516d2f..ce3e84a248 100644 --- a/distutils/tests/test_upload.py +++ b/distutils/tests/test_upload.py @@ -217,7 +217,7 @@ def test_wrong_exception_order(self): def test_suite(): - return unittest.makeSuite(uploadTestCase) + return unittest.TestLoader().loadTestsFromTestCase(uploadTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_util.py b/distutils/tests/test_util.py index bf0d4333f9..12469e3de3 100644 --- a/distutils/tests/test_util.py +++ b/distutils/tests/test_util.py @@ -303,7 +303,7 @@ def test_grok_environment_error(self): def test_suite(): - return unittest.makeSuite(UtilTestCase) + return unittest.TestLoader().loadTestsFromTestCase(UtilTestCase) if __name__ == "__main__": run_unittest(test_suite()) diff --git a/distutils/tests/test_version.py b/distutils/tests/test_version.py index d50cca1fc0..8405aa3a62 100644 --- a/distutils/tests/test_version.py +++ b/distutils/tests/test_version.py @@ -89,7 +89,7 @@ def test_cmp(self): (v1, v2, res)) def test_suite(): - return unittest.makeSuite(VersionTestCase) + return unittest.TestLoader().loadTestsFromTestCase(VersionTestCase) if __name__ == "__main__": run_unittest(test_suite()) From 1736f537eb85bcfe58e1ae854a45d5b79fe12996 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Mon, 27 Dec 2021 10:19:30 +0100 Subject: [PATCH 05/14] tests: fix tests on Ubuntu 22.04 I added a test for sysconfig.parse_config_h() in 9d0b8cda407 which assumed pyconfig.h always has some macros defined and checked that the result was non-empty. On Ubuntu 22.04 the pyconfig.h is just a shim, including various platform specific configs and not defining anything directly. This changes the test to not assume anything about the output of parse_config_h() instead. --- distutils/tests/test_sysconfig.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/distutils/tests/test_sysconfig.py b/distutils/tests/test_sysconfig.py index d28f47120e..c7989d68a0 100644 --- a/distutils/tests/test_sysconfig.py +++ b/distutils/tests/test_sysconfig.py @@ -288,11 +288,10 @@ def test_parse_config_h(self): input = {} with open(config_h, encoding="utf-8") as f: result = sysconfig.parse_config_h(f, g=input) - self.assertTrue(input) self.assertTrue(input is result) with open(config_h, encoding="utf-8") as f: result = sysconfig.parse_config_h(f) - self.assertTrue(result) + self.assertTrue(isinstance(result, dict)) def test_suite(): suite = unittest.TestSuite() From a8e6207c20912bdfd158421819889216e0413c47 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Mon, 27 Dec 2021 10:33:16 +0100 Subject: [PATCH 06/14] tests: use sys.executable instead of hardcoding "python" Don't assume a "python" is in PATH. Fixes this test when run from an uninstalled Python at least. --- distutils/tests/test_msvccompiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distutils/tests/test_msvccompiler.py b/distutils/tests/test_msvccompiler.py index 46a51cd0a7..a65537aad6 100644 --- a/distutils/tests/test_msvccompiler.py +++ b/distutils/tests/test_msvccompiler.py @@ -98,7 +98,7 @@ def test_concurrent_safe(self): compiler = _msvccompiler.MSVCCompiler() compiler._paths = "expected" inner_cmd = 'import os; assert os.environ["PATH"] == "expected"' - command = ['python', '-c', inner_cmd] + command = [sys.executable, '-c', inner_cmd] threads = [ CheckThread(target=compiler.spawn, args=[command]) From 62ed95282bb1f79b8b7564ddac2c28967035300a Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 26 Dec 2021 18:13:20 +0100 Subject: [PATCH 07/14] sysconfig: use get_makefile_filename() from stdlib sysconfig Instead of guessing the filename just refer to the stdlib. This also removes the "_makefile_tmpl" hook added in #16, but 1) It was never implemented by the distro requesting it from what I can see: https://github.com/NetBSD/pkgsrc/blob/586097714897b1b4d4a9/devel/py-setuptools/Makefile#L28 2) The stdlib version should return a proper result as it is patched by the distro requesting the change: https://github.com/NetBSD/pkgsrc/blob/6efa5763ec447864a7d4/lang/python38/patches/patch-Lib_sysconfig.py Also adds a small test checking that the file exists on Unix platforms --- distutils/sysconfig.py | 18 +----------------- distutils/tests/test_sysconfig.py | 6 ++++++ 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index 6f1bbb4867..4a77a431dc 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -281,25 +281,9 @@ def get_config_h_filename(): -# Allow this value to be patched by pkgsrc. Ref pypa/distutils#16. -_makefile_tmpl = 'config-{python_ver}{build_flags}{multiarch}' - - def get_makefile_filename(): """Return full pathname of installed Makefile from the Python build.""" - if python_build: - return os.path.join(_sys_home or project_base, "Makefile") - lib_dir = get_python_lib(plat_specific=0, standard_lib=1) - multiarch = ( - '-%s' % sys.implementation._multiarch - if hasattr(sys.implementation, '_multiarch') else '' - ) - config_file = _makefile_tmpl.format( - python_ver=get_python_version(), - build_flags=build_flags, - multiarch=multiarch, - ) - return os.path.join(lib_dir, config_file, 'Makefile') + return sysconfig.get_makefile_filename() def parse_config_h(fp, g=None): diff --git a/distutils/tests/test_sysconfig.py b/distutils/tests/test_sysconfig.py index d28f47120e..3fbacc2f30 100644 --- a/distutils/tests/test_sysconfig.py +++ b/distutils/tests/test_sysconfig.py @@ -38,6 +38,12 @@ def test_get_config_h_filename(self): config_h = sysconfig.get_config_h_filename() self.assertTrue(os.path.isfile(config_h), config_h) + @unittest.skipIf(sys.platform == 'win32', + 'Makefile only exists on Unix like systems') + def test_get_makefile_filename(self): + makefile = sysconfig.get_makefile_filename() + self.assertTrue(os.path.isfile(makefile), makefile) + def test_get_python_lib(self): # XXX doesn't work on Linux when Python was never installed before #self.assertTrue(os.path.isdir(lib_dir), lib_dir) From 79f6a3fa77407405259242cbdd85d4ff78ed7193 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 28 Dec 2021 15:24:39 -0500 Subject: [PATCH 08/14] Use line-based matrix values for nicer diffs. Remove Python 3.6 and bump to Python 3.10, matching jaraco/skeleton and pypa/setuptools approaches. --- .github/workflows/main.yml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bd0e1992ad..bd2dc8f285 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,8 +6,14 @@ jobs: test: strategy: matrix: - python: [3.6, 3.8, 3.9] - platform: [ubuntu-latest, macos-latest, windows-latest] + python: + - 3.7 + - 3.9 + - "3.10" + platform: + - ubuntu-latest + - macos-latest + - windows-latest runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v2 @@ -24,8 +30,10 @@ jobs: test_cygwin: strategy: matrix: - python: [39] - platform: [windows-latest] + python: + - "3.10" + platform: + - windows-latest runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v2 @@ -49,8 +57,10 @@ jobs: # Integration testing with setuptools strategy: matrix: - python: [3.9] - platform: [ubuntu-latest] + python: + - "3.10" + platform: + - ubuntu-latest runs-on: ${{ matrix.platform }} env: SETUPTOOLS_USE_DISTUTILS: local @@ -89,7 +99,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: "3.10" - name: Install tox run: | python -m pip install tox From 8c160a96931520044688471c8d1ea6148aacb719 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Dec 2021 11:51:20 -0500 Subject: [PATCH 09/14] Restore 'get_versions' attribute, allowing older mpi4py to monkeypatch it. Fixes pypa/setuptools#2969. --- distutils/cygwinccompiler.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/distutils/cygwinccompiler.py b/distutils/cygwinccompiler.py index 4a38dfdadd..fd082f6d27 100644 --- a/distutils/cygwinccompiler.py +++ b/distutils/cygwinccompiler.py @@ -354,3 +354,9 @@ def is_cygwincc(cc): out_string = check_output(shlex.split(cc) + ['-dumpmachine']) return out_string.strip().endswith(b'cygwin') + +get_versions = None +""" +A stand-in for the previous get_versions() function to prevent failures +when monkeypatched. See pypa/setuptools#2969. +""" From ddafa7b8aa83c2596391dcf65723e6e3b39ca1a6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Dec 2021 13:01:32 -0500 Subject: [PATCH 10/14] Disable setuptools installation. Fixes pypa/distutils#99. --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bd2dc8f285..d9e219ae34 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,6 +2,10 @@ name: tests on: [push, pull_request] +env: + # pypa/distutils#99 + VIRTUALENV_NO_SETUPTOOLS: 1 + jobs: test: strategy: From eb337f6440da3d9aaedf6ba92674c283ca34e2e2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Dec 2021 13:09:56 -0500 Subject: [PATCH 11/14] Also use PEP 517 to build things like pytest-virtualenv. --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d9e219ae34..60d0794885 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,6 +5,7 @@ on: [push, pull_request] env: # pypa/distutils#99 VIRTUALENV_NO_SETUPTOOLS: 1 + PIP_USE_PEP517: 1 jobs: test: From 2842e802a42c7eb9fd8fc80336cb65f077dfd49c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Dec 2021 13:15:09 -0500 Subject: [PATCH 12/14] 39 is actually required to get the right packages. --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 60d0794885..dcd8b901a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,7 +36,7 @@ jobs: strategy: matrix: python: - - "3.10" + - 3.9 platform: - windows-latest runs-on: ${{ matrix.platform }} @@ -47,9 +47,9 @@ jobs: with: platform: x86_64 packages: >- - python${{ matrix.python }}, - python${{ matrix.python }}-devel, - python${{ matrix.python }}-pytest, + python${{ matrix.python//.// }}, + python${{ matrix.python//.// }}-devel, + python${{ matrix.python//.// }}-pytest, gcc-core, gcc-g++, ncompress From 9f2b840b218b6f46ede9d75b3c79db1042b433dd Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Dec 2021 13:17:53 -0500 Subject: [PATCH 13/14] Unset VIRTUALENV_NO_SETUPTOOLS for ci_setuptools because pytest-virtualenv can't install without it. Ref man-group/pytest-plugins#190 --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dcd8b901a7..e404559be8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,6 @@ on: [push, pull_request] env: # pypa/distutils#99 VIRTUALENV_NO_SETUPTOOLS: 1 - PIP_USE_PEP517: 1 jobs: test: @@ -93,6 +92,8 @@ jobs: run: | cd integration/setuptools tox + env: + VIRTUALENV_NO_SETUPTOOLS: null release: needs: test From 0dfbfb81c67708aa55aa35bf612bd6769eb4eaa4 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Dec 2021 13:19:59 -0500 Subject: [PATCH 14/14] It really must be literally 39. --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e404559be8..3708751169 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: strategy: matrix: python: - - 3.9 + - 39 platform: - windows-latest runs-on: ${{ matrix.platform }} @@ -46,9 +46,9 @@ jobs: with: platform: x86_64 packages: >- - python${{ matrix.python//.// }}, - python${{ matrix.python//.// }}-devel, - python${{ matrix.python//.// }}-pytest, + python${{ matrix.python }}, + python${{ matrix.python }}-devel, + python${{ matrix.python }}-pytest, gcc-core, gcc-g++, ncompress