Skip to content

Commit 461c8f4

Browse files
committed
Merge commit 'bbe8e80bcbafff8cf3d135d17a8526c8ac5f4b27' of https://github.com/pypa/distutils into refresh-distutils
2 parents aff64ae + bbe8e80 commit 461c8f4

18 files changed

+120
-46
lines changed

setuptools/_distutils/command/build_py.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import importlib.util
77
import sys
8-
from glob import glob
8+
import glob
99

1010
from distutils.core import Command
1111
from distutils.errors import *
@@ -125,7 +125,7 @@ def find_data_files(self, package, src_dir):
125125
files = []
126126
for pattern in globs:
127127
# Each pattern has to be converted to a platform-specific path
128-
filelist = glob(os.path.join(src_dir, convert_path(pattern)))
128+
filelist = glob.glob(os.path.join(glob.escape(src_dir), convert_path(pattern)))
129129
# Files that match more than one pattern are only added once
130130
files.extend([fn for fn in filelist if fn not in files
131131
and os.path.isfile(fn)])
@@ -216,7 +216,7 @@ def check_module(self, module, module_file):
216216

217217
def find_package_modules(self, package, package_dir):
218218
self.check_package(package, package_dir)
219-
module_files = glob(os.path.join(package_dir, "*.py"))
219+
module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py"))
220220
modules = []
221221
setup_script = os.path.abspath(self.distribution.script_name)
222222

setuptools/_distutils/tests/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@
1515
import os
1616
import sys
1717
import unittest
18-
import warnings
1918
from test.support import run_unittest
2019

20+
from .py38compat import save_restore_warnings_filters
21+
2122

2223
here = os.path.dirname(__file__) or os.curdir
2324

2425

2526
def test_suite():
26-
old_filters = warnings.filters[:]
2727
suite = unittest.TestSuite()
2828
for fn in os.listdir(here):
2929
if fn.startswith("test") and fn.endswith(".py"):
3030
modname = "distutils.tests." + fn[:-3]
31-
__import__(modname)
31+
# bpo-40055: Save/restore warnings filters to leave them unchanged.
32+
# Importing tests imports docutils which imports pkg_resources
33+
# which adds a warnings filter.
34+
with save_restore_warnings_filters():
35+
__import__(modname)
3236
module = sys.modules[modname]
3337
suite.addTest(module.test_suite())
34-
# bpo-40055: Save/restore warnings filters to leave them unchanged.
35-
# Importing tests imports docutils which imports pkg_resources which adds a
36-
# warnings filter.
37-
warnings.filters[:] = old_filters
3838
return suite
3939

4040

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# flake8: noqa
2+
3+
import contextlib
4+
5+
try:
6+
from test.support.warnings_helper import check_warnings
7+
except (ModuleNotFoundError, ImportError):
8+
from test.support import check_warnings
9+
10+
11+
try:
12+
from test.support.os_helper import (
13+
change_cwd,
14+
rmtree,
15+
EnvironmentVarGuard,
16+
TESTFN,
17+
unlink,
18+
skip_unless_symlink,
19+
temp_dir,
20+
create_empty_file,
21+
temp_cwd,
22+
)
23+
except (ModuleNotFoundError, ImportError):
24+
from test.support import (
25+
change_cwd,
26+
rmtree,
27+
EnvironmentVarGuard,
28+
TESTFN,
29+
unlink,
30+
skip_unless_symlink,
31+
temp_dir,
32+
create_empty_file,
33+
temp_cwd,
34+
)
35+
36+
37+
# From Python 3.9
38+
@contextlib.contextmanager
39+
def _save_restore_warnings_filters():
40+
old_filters = warnings.filters[:]
41+
try:
42+
yield
43+
finally:
44+
warnings.filters[:] = old_filters
45+
46+
47+
try:
48+
from test.support.warnings_helper import save_restore_warnings_filters
49+
except (ModuleNotFoundError, ImportError):
50+
save_restore_warnings_filters = _save_restore_warnings_filters

setuptools/_distutils/tests/support.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import unittest
77
import sysconfig
88
from copy import deepcopy
9-
import test.support
9+
10+
from . import py38compat as os_helper
1011

1112
from distutils import log
1213
from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
@@ -64,7 +65,7 @@ def tearDown(self):
6465
super().tearDown()
6566
while self.tempdirs:
6667
tmpdir = self.tempdirs.pop()
67-
test.support.rmtree(tmpdir)
68+
os_helper.rmtree(tmpdir)
6869

6970
def mkdtemp(self):
7071
"""Create a temporary directory that will be cleaned up.

setuptools/_distutils/tests/test_archive_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
ARCHIVE_FORMATS)
1414
from distutils.spawn import find_executable, spawn
1515
from distutils.tests import support
16-
from test.support import check_warnings, run_unittest, patch, change_cwd
16+
from test.support import run_unittest, patch
17+
18+
from .py38compat import change_cwd
19+
from .py38compat import check_warnings
1720

1821
try:
1922
import grp

setuptools/_distutils/tests/test_bdist_msi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Tests for distutils.command.bdist_msi."""
22
import sys
33
import unittest
4-
from test.support import run_unittest, check_warnings
4+
from test.support import run_unittest
55
from distutils.tests import support
66

7+
from .py38compat import check_warnings
8+
79

810
@unittest.skipUnless(sys.platform == 'win32', 'these tests require Windows')
911
class BDistMSITestCase(support.TempdirManager,

setuptools/_distutils/tests/test_bdist_wininst.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import sys
33
import platform
44
import unittest
5-
from test.support import run_unittest, check_warnings
5+
from test.support import run_unittest
6+
7+
from .py38compat import check_warnings
68

79
from distutils.command.bdist_wininst import bdist_wininst
810
from distutils.tests import support

setuptools/_distutils/tests/test_build_ext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import unittest
1717
from test import support
18+
from . import py38compat as os_helper
1819
from test.support.script_helper import assert_python_ok
1920

2021
# http://bugs.python.org/issue4373
@@ -38,7 +39,7 @@ def setUp(self):
3839
# bpo-30132: On Windows, a .pdb file may be created in the current
3940
# working directory. Create a temporary working directory to cleanup
4041
# everything at the end of the test.
41-
change_cwd = support.change_cwd(self.tmp_dir)
42+
change_cwd = os_helper.change_cwd(self.tmp_dir)
4243
change_cwd.__enter__()
4344
self.addCleanup(change_cwd.__exit__, None, None, None)
4445

setuptools/_distutils/tests/test_core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import os
66
import shutil
77
import sys
8-
import test.support
98
from test.support import captured_stdout, run_unittest
9+
from . import py38compat as os_helper
1010
import unittest
1111
from distutils.tests import support
1212
from distutils import log
@@ -62,13 +62,13 @@ def tearDown(self):
6262
super(CoreTestCase, self).tearDown()
6363

6464
def cleanup_testfn(self):
65-
path = test.support.TESTFN
65+
path = os_helper.TESTFN
6666
if os.path.isfile(path):
6767
os.remove(path)
6868
elif os.path.isdir(path):
6969
shutil.rmtree(path)
7070

71-
def write_setup(self, text, path=test.support.TESTFN):
71+
def write_setup(self, text, path=os_helper.TESTFN):
7272
f = open(path, "w")
7373
try:
7474
f.write(text)
@@ -105,8 +105,8 @@ def test_run_setup_uses_current_dir(self):
105105
cwd = os.getcwd()
106106

107107
# Create a directory and write the setup.py file there:
108-
os.mkdir(test.support.TESTFN)
109-
setup_py = os.path.join(test.support.TESTFN, "setup.py")
108+
os.mkdir(os_helper.TESTFN)
109+
setup_py = os.path.join(os_helper.TESTFN, "setup.py")
110110
distutils.core.run_setup(
111111
self.write_setup(setup_prints_cwd, path=setup_py))
112112

setuptools/_distutils/tests/test_dist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
from distutils.cmd import Command
1313

1414
from test.support import (
15-
TESTFN, captured_stdout, captured_stderr, run_unittest
15+
captured_stdout, captured_stderr, run_unittest
1616
)
17+
from .py38compat import TESTFN
1718
from distutils.tests import support
1819
from distutils import log
1920

setuptools/_distutils/tests/test_extension.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import os
44
import warnings
55

6-
from test.support import check_warnings, run_unittest
6+
from test.support import run_unittest
77
from distutils.extension import read_setup_file, Extension
88

9+
from .py38compat import check_warnings
10+
911
class ExtensionTestCase(unittest.TestCase):
1012

1113
def test_read_setup_file(self):

setuptools/_distutils/tests/test_file_util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from distutils import log
99
from distutils.tests import support
1010
from distutils.errors import DistutilsFileError
11-
from test.support import run_unittest, unlink
11+
from test.support import run_unittest
12+
from .py38compat import unlink
13+
1214

1315
class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
1416

setuptools/_distutils/tests/test_filelist.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from distutils.filelist import glob_to_re, translate_pattern, FileList
99
from distutils import filelist
1010

11-
import test.support
1211
from test.support import captured_stdout, run_unittest
1312
from distutils.tests import support
1413

1514
from .py35compat import adapt_glob
15+
from . import py38compat as os_helper
1616

1717

1818
MANIFEST_IN = """\
@@ -298,9 +298,9 @@ def test_process_template(self):
298298

299299

300300
class FindAllTestCase(unittest.TestCase):
301-
@test.support.skip_unless_symlink
301+
@os_helper.skip_unless_symlink
302302
def test_missing_symlink(self):
303-
with test.support.temp_cwd():
303+
with os_helper.temp_cwd():
304304
os.symlink('foo', 'bar')
305305
self.assertEqual(filelist.findall(), [])
306306

@@ -310,13 +310,13 @@ def test_basic_discovery(self):
310310
'.' as the parameter, the dot should be omitted from
311311
the results.
312312
"""
313-
with test.support.temp_cwd():
313+
with os_helper.temp_cwd():
314314
os.mkdir('foo')
315315
file1 = os.path.join('foo', 'file1.txt')
316-
test.support.create_empty_file(file1)
316+
os_helper.create_empty_file(file1)
317317
os.mkdir('bar')
318318
file2 = os.path.join('bar', 'file2.txt')
319-
test.support.create_empty_file(file2)
319+
os_helper.create_empty_file(file2)
320320
expected = [file2, file1]
321321
self.assertEqual(sorted(filelist.findall()), expected)
322322

@@ -325,9 +325,9 @@ def test_non_local_discovery(self):
325325
When findall is called with another path, the full
326326
path name should be returned.
327327
"""
328-
with test.support.temp_dir() as temp_dir:
328+
with os_helper.temp_dir() as temp_dir:
329329
file1 = os.path.join(temp_dir, 'file1.txt')
330-
test.support.create_empty_file(file1)
330+
os_helper.create_empty_file(file1)
331331
expected = [file1]
332332
self.assertEqual(filelist.findall(temp_dir), expected)
333333

setuptools/_distutils/tests/test_register.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import urllib
66
import warnings
77

8-
from test.support import check_warnings, run_unittest
8+
from test.support import run_unittest
9+
10+
from .py38compat import check_warnings
911

1012
from distutils.command import register as register_module
1113
from distutils.command.register import register

setuptools/_distutils/tests/test_sdist.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import zipfile
77
from os.path import join
88
from textwrap import dedent
9-
from test.support import captured_stdout, check_warnings, run_unittest
9+
from test.support import captured_stdout, run_unittest
10+
11+
from .py38compat import check_warnings
1012

1113
try:
1214
import zlib

0 commit comments

Comments
 (0)