Skip to content

Commit

Permalink
Various setup fixes
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nitzmahone committed Sep 23, 2021
1 parent 8f3f979 commit 478c141
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
25 changes: 0 additions & 25 deletions setup.cfg

This file was deleted.

35 changes: 28 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"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",
Expand Down Expand Up @@ -63,11 +64,14 @@
"""


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
from distutils import log
from distutils.errors import DistutilsError, CompileError, LinkError, DistutilsPlatformError

with_cython = False
Expand Down Expand Up @@ -246,11 +250,28 @@ def finalize_options(self):
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 = {
Expand Down

0 comments on commit 478c141

Please sign in to comment.