From 93d5b398b69496190da06740e3b29d5f90817ae7 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Sun, 27 Jan 2019 12:31:28 -0500 Subject: [PATCH] Add build_meta_legacy backend This is part of the solution to GH #1642, it is a backwards-compatibility backend that can be used as a default PEP 517 backend for projects that use setuptools but haven't opted in to build_meta. --- setuptools/build_meta_legacy.py | 44 +++++++++++++++++++++++++++++ setuptools/tests/test_build_meta.py | 1 - 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 setuptools/build_meta_legacy.py diff --git a/setuptools/build_meta_legacy.py b/setuptools/build_meta_legacy.py new file mode 100644 index 00000000000..7eed41f111f --- /dev/null +++ b/setuptools/build_meta_legacy.py @@ -0,0 +1,44 @@ +"""Compatibility backend for setuptools + +This is a version of setuptools.build_meta that endeavors to maintain backwards +compatibility with pre-PEP 517 modes of invocation. It exists as a temporary +bridge between the old packaging mechanism and the new packaging mechanism, +and will eventually be removed. +""" + +import sys + +from setuptools.build_meta import _BuildMetaBackend +from setuptools.build_meta import SetupRequirementsError + + +__all__ = ['get_requires_for_build_sdist', + 'get_requires_for_build_wheel', + 'prepare_metadata_for_build_wheel', + 'build_wheel', + 'build_sdist', + 'SetupRequirementsError'] + + +class _BuildMetaLegacyBackend(_BuildMetaBackend): + def run_setup(self, setup_script='setup.py'): + # In order to maintain compatibility with scripts assuming that + # the setup.py script is in a directory on the PYTHONPATH, inject + # '' into sys.path. (pypa/setuptools#1642) + sys_path = list(sys.path) # Save the old path + if '' not in sys.path: + sys.path.insert(0, '') + + super(_BuildMetaLegacyBackend, + self).run_setup(setup_script=setup_script) + + sys.path = sys_path # Restore the old path + + +_BACKEND = _BuildMetaLegacyBackend() + +get_requires_for_build_wheel = _BACKEND.get_requires_for_build_wheel +get_requires_for_build_sdist = _BACKEND.get_requires_for_build_sdist +prepare_metadata_for_build_wheel = _BACKEND.prepare_metadata_for_build_wheel +build_wheel = _BACKEND.build_wheel +build_sdist = _BACKEND.build_sdist diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py index 5d97ebcec26..b29d6f29e52 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -258,7 +258,6 @@ def test_build_sdist_relative_path_import(self, tmpdir_cwd): build_backend.build_sdist("temp") -@pytest.mark.xfail class TestBuildMetaLegacyBackend(TestBuildMetaBackend): backend_name = 'setuptools.build_meta_legacy'