Skip to content

Commit a6d384c

Browse files
committed
Various setup fixes
* enable use of setuptools-embedded distutils * list 3.10 support * remove setup.cfg (and deprecated metadata in it) * run tests on ephemeral copy of intermediate build bits
1 parent 8f3f979 commit a6d384c

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

setup.cfg

-25
This file was deleted.

setup.py

+29-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"Programming Language :: Python :: 3.7",
3333
"Programming Language :: Python :: 3.8",
3434
"Programming Language :: Python :: 3.9",
35+
"Programming Language :: Python :: 3.10",
3536
"Programming Language :: Python :: Implementation :: CPython",
3637
"Programming Language :: Python :: Implementation :: PyPy",
3738
"Topic :: Software Development :: Libraries :: Python Modules",
@@ -63,11 +64,15 @@
6364
"""
6465

6566

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'
6771

68-
from distutils import log
6972
from setuptools import setup, Command, Distribution as _Distribution, Extension as _Extension
7073
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
7176
from distutils.errors import DistutilsError, CompileError, LinkError, DistutilsPlatformError
7277

7378
with_cython = False
@@ -246,11 +251,28 @@ def finalize_options(self):
246251
def run(self):
247252
build_cmd = self.get_finalized_command('build')
248253
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
254276

255277

256278
cmdclass = {

0 commit comments

Comments
 (0)