diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-07-07 21:22:40 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-07-07 21:22:40 -0400 |
commit | bbe8e80bcbafff8cf3d135d17a8526c8ac5f4b27 (patch) | |
tree | e77ebb7f49a52a4efd1421ff75f279a840163dac | |
parent | a21ea47bf0a8bbd79afdbd93b80681f1133aedf0 (diff) | |
parent | e34d6d8b739a8e0edbdfa324bf3607430aa3ff70 (diff) | |
download | external_python_setuptools-bbe8e80bcbafff8cf3d135d17a8526c8ac5f4b27.tar.gz external_python_setuptools-bbe8e80bcbafff8cf3d135d17a8526c8ac5f4b27.tar.bz2 external_python_setuptools-bbe8e80bcbafff8cf3d135d17a8526c8ac5f4b27.zip |
Merge branch 'cpython'
-rw-r--r-- | distutils/command/build_py.py | 6 | ||||
-rw-r--r-- | distutils/tests/__init__.py | 14 | ||||
-rw-r--r-- | distutils/tests/py38compat.py | 50 | ||||
-rw-r--r-- | distutils/tests/support.py | 5 | ||||
-rw-r--r-- | distutils/tests/test_archive_util.py | 5 | ||||
-rw-r--r-- | distutils/tests/test_bdist_msi.py | 4 | ||||
-rw-r--r-- | distutils/tests/test_bdist_wininst.py | 4 | ||||
-rw-r--r-- | distutils/tests/test_build_ext.py | 3 | ||||
-rw-r--r-- | distutils/tests/test_core.py | 10 | ||||
-rw-r--r-- | distutils/tests/test_dist.py | 3 | ||||
-rw-r--r-- | distutils/tests/test_extension.py | 4 | ||||
-rw-r--r-- | distutils/tests/test_file_util.py | 4 | ||||
-rw-r--r-- | distutils/tests/test_filelist.py | 16 | ||||
-rw-r--r-- | distutils/tests/test_register.py | 4 | ||||
-rw-r--r-- | distutils/tests/test_sdist.py | 4 | ||||
-rw-r--r-- | distutils/tests/test_spawn.py | 18 | ||||
-rw-r--r-- | distutils/tests/test_sysconfig.py | 6 | ||||
-rw-r--r-- | distutils/tests/test_unixccompiler.py | 4 |
18 files changed, 119 insertions, 45 deletions
diff --git a/distutils/command/build_py.py b/distutils/command/build_py.py index cf0ca57c..edc2171c 100644 --- a/distutils/command/build_py.py +++ b/distutils/command/build_py.py @@ -5,7 +5,7 @@ Implements the Distutils 'build_py' command.""" import os import importlib.util import sys -from glob import glob +import glob from distutils.core import Command from distutils.errors import * @@ -125,7 +125,7 @@ class build_py (Command): files = [] for pattern in globs: # Each pattern has to be converted to a platform-specific path - filelist = glob(os.path.join(src_dir, convert_path(pattern))) + filelist = glob.glob(os.path.join(glob.escape(src_dir), convert_path(pattern))) # Files that match more than one pattern are only added once files.extend([fn for fn in filelist if fn not in files and os.path.isfile(fn)]) @@ -216,7 +216,7 @@ class build_py (Command): def find_package_modules(self, package, package_dir): self.check_package(package, package_dir) - module_files = glob(os.path.join(package_dir, "*.py")) + module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py")) modules = [] setup_script = os.path.abspath(self.distribution.script_name) diff --git a/distutils/tests/__init__.py b/distutils/tests/__init__.py index 5d2e69e3..c7dcc7ec 100644 --- a/distutils/tests/__init__.py +++ b/distutils/tests/__init__.py @@ -15,26 +15,26 @@ by import rather than matching pre-defined names. import os import sys import unittest -import warnings from test.support import run_unittest +from .py38compat import save_restore_warnings_filters + here = os.path.dirname(__file__) or os.curdir def test_suite(): - old_filters = warnings.filters[:] suite = unittest.TestSuite() for fn in os.listdir(here): if fn.startswith("test") and fn.endswith(".py"): modname = "distutils.tests." + fn[:-3] - __import__(modname) + # bpo-40055: Save/restore warnings filters to leave them unchanged. + # Importing tests imports docutils which imports pkg_resources + # which adds a warnings filter. + with save_restore_warnings_filters(): + __import__(modname) module = sys.modules[modname] suite.addTest(module.test_suite()) - # bpo-40055: Save/restore warnings filters to leave them unchanged. - # Importing tests imports docutils which imports pkg_resources which adds a - # warnings filter. - warnings.filters[:] = old_filters return suite diff --git a/distutils/tests/py38compat.py b/distutils/tests/py38compat.py new file mode 100644 index 00000000..46ff5758 --- /dev/null +++ b/distutils/tests/py38compat.py @@ -0,0 +1,50 @@ +# flake8: noqa + +import contextlib + +try: + from test.support.warnings_helper import check_warnings +except (ModuleNotFoundError, ImportError): + from test.support import check_warnings + + +try: + from test.support.os_helper import ( + change_cwd, + rmtree, + EnvironmentVarGuard, + TESTFN, + unlink, + skip_unless_symlink, + temp_dir, + create_empty_file, + temp_cwd, + ) +except (ModuleNotFoundError, ImportError): + from test.support import ( + change_cwd, + rmtree, + EnvironmentVarGuard, + TESTFN, + unlink, + skip_unless_symlink, + temp_dir, + create_empty_file, + temp_cwd, + ) + + +# From Python 3.9 +@contextlib.contextmanager +def _save_restore_warnings_filters(): + old_filters = warnings.filters[:] + try: + yield + finally: + warnings.filters[:] = old_filters + + +try: + from test.support.warnings_helper import save_restore_warnings_filters +except (ModuleNotFoundError, ImportError): + save_restore_warnings_filters = _save_restore_warnings_filters diff --git a/distutils/tests/support.py b/distutils/tests/support.py index 259af882..b4410fc9 100644 --- a/distutils/tests/support.py +++ b/distutils/tests/support.py @@ -6,7 +6,8 @@ import tempfile import unittest import sysconfig from copy import deepcopy -import test.support + +from . import py38compat as os_helper from distutils import log from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL @@ -64,7 +65,7 @@ class TempdirManager(object): super().tearDown() while self.tempdirs: tmpdir = self.tempdirs.pop() - test.support.rmtree(tmpdir) + os_helper.rmtree(tmpdir) def mkdtemp(self): """Create a temporary directory that will be cleaned up. diff --git a/distutils/tests/test_archive_util.py b/distutils/tests/test_archive_util.py index e9aad0e4..ce6456dc 100644 --- a/distutils/tests/test_archive_util.py +++ b/distutils/tests/test_archive_util.py @@ -13,7 +13,10 @@ from distutils.archive_util import (check_archive_formats, make_tarball, ARCHIVE_FORMATS) from distutils.spawn import find_executable, spawn from distutils.tests import support -from test.support import check_warnings, run_unittest, patch, change_cwd +from test.support import run_unittest, patch + +from .py38compat import change_cwd +from .py38compat import check_warnings try: import grp diff --git a/distutils/tests/test_bdist_msi.py b/distutils/tests/test_bdist_msi.py index 418e60ec..937266f8 100644 --- a/distutils/tests/test_bdist_msi.py +++ b/distutils/tests/test_bdist_msi.py @@ -1,9 +1,11 @@ """Tests for distutils.command.bdist_msi.""" import sys import unittest -from test.support import run_unittest, check_warnings +from test.support import run_unittest from distutils.tests import support +from .py38compat import check_warnings + @unittest.skipUnless(sys.platform == 'win32', 'these tests require Windows') class BDistMSITestCase(support.TempdirManager, diff --git a/distutils/tests/test_bdist_wininst.py b/distutils/tests/test_bdist_wininst.py index 5c3d025d..31cf2628 100644 --- a/distutils/tests/test_bdist_wininst.py +++ b/distutils/tests/test_bdist_wininst.py @@ -2,7 +2,9 @@ import sys import platform import unittest -from test.support import run_unittest, check_warnings +from test.support import run_unittest + +from .py38compat import check_warnings from distutils.command.bdist_wininst import bdist_wininst from distutils.tests import support diff --git a/distutils/tests/test_build_ext.py b/distutils/tests/test_build_ext.py index 1aec1537..5a72458c 100644 --- a/distutils/tests/test_build_ext.py +++ b/distutils/tests/test_build_ext.py @@ -15,6 +15,7 @@ from distutils.errors import ( import unittest from test import support +from . import py38compat as os_helper from test.support.script_helper import assert_python_ok # http://bugs.python.org/issue4373 @@ -38,7 +39,7 @@ class BuildExtTestCase(TempdirManager, # bpo-30132: On Windows, a .pdb file may be created in the current # working directory. Create a temporary working directory to cleanup # everything at the end of the test. - change_cwd = support.change_cwd(self.tmp_dir) + change_cwd = os_helper.change_cwd(self.tmp_dir) change_cwd.__enter__() self.addCleanup(change_cwd.__exit__, None, None, None) diff --git a/distutils/tests/test_core.py b/distutils/tests/test_core.py index 27ce7324..666ff4a3 100644 --- a/distutils/tests/test_core.py +++ b/distutils/tests/test_core.py @@ -5,8 +5,8 @@ import distutils.core import os import shutil import sys -import test.support from test.support import captured_stdout, run_unittest +from . import py38compat as os_helper import unittest from distutils.tests import support from distutils import log @@ -62,13 +62,13 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase): super(CoreTestCase, self).tearDown() def cleanup_testfn(self): - path = test.support.TESTFN + path = os_helper.TESTFN if os.path.isfile(path): os.remove(path) elif os.path.isdir(path): shutil.rmtree(path) - def write_setup(self, text, path=test.support.TESTFN): + def write_setup(self, text, path=os_helper.TESTFN): f = open(path, "w") try: f.write(text) @@ -105,8 +105,8 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase): cwd = os.getcwd() # Create a directory and write the setup.py file there: - os.mkdir(test.support.TESTFN) - setup_py = os.path.join(test.support.TESTFN, "setup.py") + os.mkdir(os_helper.TESTFN) + setup_py = os.path.join(os_helper.TESTFN, "setup.py") distutils.core.run_setup( self.write_setup(setup_prints_cwd, path=setup_py)) diff --git a/distutils/tests/test_dist.py b/distutils/tests/test_dist.py index d431085b..45eadee8 100644 --- a/distutils/tests/test_dist.py +++ b/distutils/tests/test_dist.py @@ -12,8 +12,9 @@ from distutils.dist import Distribution, fix_help_options from distutils.cmd import Command from test.support import ( - TESTFN, captured_stdout, captured_stderr, run_unittest + captured_stdout, captured_stderr, run_unittest ) +from .py38compat import TESTFN from distutils.tests import support from distutils import log diff --git a/distutils/tests/test_extension.py b/distutils/tests/test_extension.py index e35f2738..2eb5b422 100644 --- a/distutils/tests/test_extension.py +++ b/distutils/tests/test_extension.py @@ -3,9 +3,11 @@ import unittest import os import warnings -from test.support import check_warnings, run_unittest +from test.support import run_unittest from distutils.extension import read_setup_file, Extension +from .py38compat import check_warnings + class ExtensionTestCase(unittest.TestCase): def test_read_setup_file(self): diff --git a/distutils/tests/test_file_util.py b/distutils/tests/test_file_util.py index a4e2d025..d2536075 100644 --- a/distutils/tests/test_file_util.py +++ b/distutils/tests/test_file_util.py @@ -8,7 +8,9 @@ from distutils.file_util import move_file, copy_file from distutils import log from distutils.tests import support from distutils.errors import DistutilsFileError -from test.support import run_unittest, unlink +from test.support import run_unittest +from .py38compat import unlink + class FileUtilTestCase(support.TempdirManager, unittest.TestCase): diff --git a/distutils/tests/test_filelist.py b/distutils/tests/test_filelist.py index 71fde2b7..d8e4b39f 100644 --- a/distutils/tests/test_filelist.py +++ b/distutils/tests/test_filelist.py @@ -8,11 +8,11 @@ from distutils.errors import DistutilsTemplateError from distutils.filelist import glob_to_re, translate_pattern, FileList from distutils import filelist -import test.support from test.support import captured_stdout, run_unittest from distutils.tests import support from .py35compat import adapt_glob +from . import py38compat as os_helper MANIFEST_IN = """\ @@ -298,9 +298,9 @@ class FileListTestCase(support.LoggingSilencer, class FindAllTestCase(unittest.TestCase): - @test.support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_missing_symlink(self): - with test.support.temp_cwd(): + with os_helper.temp_cwd(): os.symlink('foo', 'bar') self.assertEqual(filelist.findall(), []) @@ -310,13 +310,13 @@ class FindAllTestCase(unittest.TestCase): '.' as the parameter, the dot should be omitted from the results. """ - with test.support.temp_cwd(): + with os_helper.temp_cwd(): os.mkdir('foo') file1 = os.path.join('foo', 'file1.txt') - test.support.create_empty_file(file1) + os_helper.create_empty_file(file1) os.mkdir('bar') file2 = os.path.join('bar', 'file2.txt') - test.support.create_empty_file(file2) + os_helper.create_empty_file(file2) expected = [file2, file1] self.assertEqual(sorted(filelist.findall()), expected) @@ -325,9 +325,9 @@ class FindAllTestCase(unittest.TestCase): When findall is called with another path, the full path name should be returned. """ - with test.support.temp_dir() as temp_dir: + with os_helper.temp_dir() as temp_dir: file1 = os.path.join(temp_dir, 'file1.txt') - test.support.create_empty_file(file1) + os_helper.create_empty_file(file1) expected = [file1] self.assertEqual(filelist.findall(temp_dir), expected) diff --git a/distutils/tests/test_register.py b/distutils/tests/test_register.py index e68b0af3..84607f99 100644 --- a/distutils/tests/test_register.py +++ b/distutils/tests/test_register.py @@ -5,7 +5,9 @@ import getpass import urllib import warnings -from test.support import check_warnings, run_unittest +from test.support import run_unittest + +from .py38compat import check_warnings from distutils.command import register as register_module from distutils.command.register import register diff --git a/distutils/tests/test_sdist.py b/distutils/tests/test_sdist.py index 23db1269..b087a817 100644 --- a/distutils/tests/test_sdist.py +++ b/distutils/tests/test_sdist.py @@ -6,7 +6,9 @@ import warnings import zipfile from os.path import join from textwrap import dedent -from test.support import captured_stdout, check_warnings, run_unittest +from test.support import captured_stdout, run_unittest + +from .py38compat import check_warnings try: import zlib diff --git a/distutils/tests/test_spawn.py b/distutils/tests/test_spawn.py index adaa48ef..f620da78 100644 --- a/distutils/tests/test_spawn.py +++ b/distutils/tests/test_spawn.py @@ -4,9 +4,9 @@ import stat import sys import unittest.mock from test.support import run_unittest -from test import support as test_support from .py35compat import unix_shell +from . import py38compat as os_helper from distutils.spawn import find_executable from distutils.spawn import spawn @@ -46,9 +46,9 @@ class SpawnTestCase(support.TempdirManager, spawn([exe]) # should work without any error def test_find_executable(self): - with test_support.temp_dir() as tmp_dir: + with os_helper.temp_dir() as tmp_dir: # use TESTFN to get a pseudo-unique filename - program_noeext = test_support.TESTFN + program_noeext = os_helper.TESTFN # Give the temporary program an ".exe" suffix for all. # It's needed on Windows and not harmful on other platforms. program = program_noeext + ".exe" @@ -68,7 +68,7 @@ class SpawnTestCase(support.TempdirManager, self.assertEqual(rv, filename) # test find in the current directory - with test_support.change_cwd(tmp_dir): + with os_helper.change_cwd(tmp_dir): rv = find_executable(program) self.assertEqual(rv, program) @@ -78,7 +78,7 @@ class SpawnTestCase(support.TempdirManager, self.assertIsNone(rv) # PATH='': no match, except in the current directory - with test_support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['PATH'] = '' with unittest.mock.patch('distutils.spawn.os.confstr', return_value=tmp_dir, create=True), \ @@ -88,12 +88,12 @@ class SpawnTestCase(support.TempdirManager, self.assertIsNone(rv) # look in current directory - with test_support.change_cwd(tmp_dir): + with os_helper.change_cwd(tmp_dir): rv = find_executable(program) self.assertEqual(rv, program) # PATH=':': explicitly looks in the current directory - with test_support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['PATH'] = os.pathsep with unittest.mock.patch('distutils.spawn.os.confstr', return_value='', create=True), \ @@ -102,12 +102,12 @@ class SpawnTestCase(support.TempdirManager, self.assertIsNone(rv) # look in current directory - with test_support.change_cwd(tmp_dir): + with os_helper.change_cwd(tmp_dir): rv = find_executable(program) self.assertEqual(rv, program) # missing PATH: test os.confstr("CS_PATH") and os.defpath - with test_support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env.pop('PATH', None) # without confstr diff --git a/distutils/tests/test_sysconfig.py b/distutils/tests/test_sysconfig.py index d5076391..c7571942 100644 --- a/distutils/tests/test_sysconfig.py +++ b/distutils/tests/test_sysconfig.py @@ -10,7 +10,11 @@ import unittest from distutils import sysconfig from distutils.ccompiler import get_default_compiler from distutils.tests import support -from test.support import TESTFN, run_unittest, check_warnings, swap_item +from test.support import run_unittest, swap_item + +from .py38compat import TESTFN +from .py38compat import check_warnings + class SysconfigTestCase(support.EnvironGuard, unittest.TestCase): def setUp(self): diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index f2159662..1828ba1a 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -1,7 +1,9 @@ """Tests for distutils.unixccompiler.""" import sys import unittest -from test.support import EnvironmentVarGuard, run_unittest +from test.support import run_unittest + +from .py38compat import EnvironmentVarGuard from distutils import sysconfig from distutils.unixccompiler import UnixCCompiler |