aboutsummaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorMatt Davis <mrd@redhat.com>2021-09-23 15:30:53 -0700
committerMatt Davis <mrd@redhat.com>2021-09-23 15:34:34 -0700
commita6d384c52ea54ded80df27032c7b6d3a98b0c2fa (patch)
treeea856093e5ab2b505b2d445c56a7a95c91b80258 /setup.py
parent8f3f9795b4ccc7087c439aad8342eaf916f273d0 (diff)
downloadpyyaml-a6d384c52ea54ded80df27032c7b6d3a98b0c2fa.tar.gz
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
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/setup.py b/setup.py
index a9b5d90..ac378ba 100644
--- a/setup.py
+++ b/setup.py
@@ -32,6 +32,7 @@ CLASSIFIERS = [
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
+ "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
@@ -63,11 +64,15 @@ int main(void) {
"""
-import sys, os, os.path, platform, warnings
+import sys, os, os.path, pathlib, platform, shutil, tempfile, warnings
+
+# for newer setuptools, enable the embedded distutils before importing setuptools/distutils to avoid warnings
+os.environ['SETUPTOOLS_USE_DISTUTILS'] = 'local'
-from distutils import log
from setuptools import setup, Command, Distribution as _Distribution, Extension as _Extension
from setuptools.command.build_ext import build_ext as _build_ext
+# NB: distutils imports must remain below setuptools to ensure we use the embedded version
+from distutils import log
from distutils.errors import DistutilsError, CompileError, LinkError, DistutilsPlatformError
with_cython = False
@@ -246,11 +251,28 @@ class test(Command):
def run(self):
build_cmd = self.get_finalized_command('build')
build_cmd.run()
- sys.path.insert(0, build_cmd.build_lib)
- sys.path.insert(0, 'tests/lib')
- import test_all
- if not test_all.main([]):
- raise DistutilsError("Tests failed")
+
+ # running the tests this way can pollute the post-MANIFEST build sources
+ # (see https://github.com/yaml/pyyaml/issues/527#issuecomment-921058344)
+ # until we remove the test command, run tests from an ephemeral copy of the intermediate build sources
+ tempdir = tempfile.TemporaryDirectory(prefix='test_pyyaml')
+
+ try:
+ # have to create a subdir since we don't get dir_exists_ok on copytree until 3.8
+ temp_test_path = pathlib.Path(tempdir.name) / 'pyyaml'
+ shutil.copytree(build_cmd.build_lib, temp_test_path)
+ sys.path.insert(0, str(temp_test_path))
+ sys.path.insert(0, 'tests/lib')
+
+ import test_all
+ if not test_all.main([]):
+ raise DistutilsError("Tests failed")
+ finally:
+ try:
+ # this can fail under Windows; best-effort cleanup
+ tempdir.cleanup()
+ except Exception:
+ pass
cmdclass = {