From a6d384c52ea54ded80df27032c7b6d3a98b0c2fa Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 23 Sep 2021 15:30:53 -0700 Subject: [PATCH] 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 --- setup.cfg | 25 ------------------------- setup.py | 36 +++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 32 deletions(-) delete mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b186858a..00000000 --- a/setup.cfg +++ /dev/null @@ -1,25 +0,0 @@ - -# The INCLUDE and LIB directories to build the '_yaml' extension. -# You may also set them using the options '-I' and '-L'. -[build_ext] - -# List of directories to search for 'yaml.h' (separated by ':'). -#include_dirs=/usr/local/include:../../include - -# List of directories to search for 'libyaml.a' (separated by ':'). -#library_dirs=/usr/local/lib:../../lib - -# An alternative compiler to build the extension. -#compiler=mingw32 - -# Additional preprocessor definitions might be required. -#define=YAML_DECLARE_STATIC - -# The following options are used to build PyYAML Windows installer -# for Python 2.7 on my PC: -#include_dirs=../../../libyaml/tags/0.1.4/include -#library_dirs=../../../libyaml/tags/0.1.4/win32/vs2008/output/release/lib -#define=YAML_DECLARE_STATIC - -[metadata] -license_file = LICENSE \ No newline at end of file diff --git a/setup.py b/setup.py index a9b5d902..ac378bae 100644 --- a/setup.py +++ b/setup.py @@ -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", @@ -63,11 +64,15 @@ """ -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 @@ 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 = {