|
32 | 32 | "Programming Language :: Python :: 3.7",
|
33 | 33 | "Programming Language :: Python :: 3.8",
|
34 | 34 | "Programming Language :: Python :: 3.9",
|
| 35 | + "Programming Language :: Python :: 3.10", |
35 | 36 | "Programming Language :: Python :: Implementation :: CPython",
|
36 | 37 | "Programming Language :: Python :: Implementation :: PyPy",
|
37 | 38 | "Topic :: Software Development :: Libraries :: Python Modules",
|
|
63 | 64 | """
|
64 | 65 |
|
65 | 66 |
|
66 |
| -import sys, os, os.path, platform, warnings |
| 67 | +import sys, os, os.path, pathlib, platform, shutil, tempfile, warnings |
| 68 | + |
| 69 | +# for newer setuptools, enable the embedded distutils before importing setuptools/distutils to avoid warnings |
| 70 | +os.environ['SETUPTOOLS_USE_DISTUTILS'] = 'local' |
67 | 71 |
|
68 |
| -from distutils import log |
69 | 72 | from setuptools import setup, Command, Distribution as _Distribution, Extension as _Extension
|
70 | 73 | from setuptools.command.build_ext import build_ext as _build_ext
|
| 74 | +# NB: distutils imports must remain below setuptools to ensure we use the embedded version |
| 75 | +from distutils import log |
71 | 76 | from distutils.errors import DistutilsError, CompileError, LinkError, DistutilsPlatformError
|
72 | 77 |
|
73 | 78 | with_cython = False
|
@@ -246,11 +251,28 @@ def finalize_options(self):
|
246 | 251 | def run(self):
|
247 | 252 | build_cmd = self.get_finalized_command('build')
|
248 | 253 | build_cmd.run()
|
249 |
| - sys.path.insert(0, build_cmd.build_lib) |
250 |
| - sys.path.insert(0, 'tests/lib') |
251 |
| - import test_all |
252 |
| - if not test_all.main([]): |
253 |
| - raise DistutilsError("Tests failed") |
| 254 | + |
| 255 | + # running the tests this way can pollute the post-MANIFEST build sources |
| 256 | + # (see https://github.com/yaml/pyyaml/issues/527#issuecomment-921058344) |
| 257 | + # until we remove the test command, run tests from an ephemeral copy of the intermediate build sources |
| 258 | + tempdir = tempfile.TemporaryDirectory(prefix='test_pyyaml') |
| 259 | + |
| 260 | + try: |
| 261 | + # have to create a subdir since we don't get dir_exists_ok on copytree until 3.8 |
| 262 | + temp_test_path = pathlib.Path(tempdir.name) / 'pyyaml' |
| 263 | + shutil.copytree(build_cmd.build_lib, temp_test_path) |
| 264 | + sys.path.insert(0, str(temp_test_path)) |
| 265 | + sys.path.insert(0, 'tests/lib') |
| 266 | + |
| 267 | + import test_all |
| 268 | + if not test_all.main([]): |
| 269 | + raise DistutilsError("Tests failed") |
| 270 | + finally: |
| 271 | + try: |
| 272 | + # this can fail under Windows; best-effort cleanup |
| 273 | + tempdir.cleanup() |
| 274 | + except Exception: |
| 275 | + pass |
254 | 276 |
|
255 | 277 |
|
256 | 278 | cmdclass = {
|
|
0 commit comments