diff options
Diffstat (limited to 'setuptools')
-rw-r--r-- | setuptools/build_meta.py | 35 | ||||
-rw-r--r-- | setuptools/build_meta_legacy.py | 53 | ||||
-rw-r--r-- | setuptools/tests/test_build_meta.py | 17 |
3 files changed, 49 insertions, 56 deletions
diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index 8e31a04d..e16f319e 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -40,6 +40,7 @@ __all__ = ['get_requires_for_build_sdist', 'prepare_metadata_for_build_wheel', 'build_wheel', 'build_sdist', + 'legacy', 'SetupRequirementsError'] class SetupRequirementsError(BaseException): @@ -187,6 +188,36 @@ class _BuildMetaBackend(object): return _file_with_extension(sdist_directory, '.tar.gz') +class _BuildMetaLegacyBackend(_BuildMetaBackend): + """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. + """ + 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 original path + + script_dir = os.path.dirname(os.path.abspath(setup_script)) + if script_dir not in sys.path: + sys.path.insert(0, script_dir) + + try: + super(_BuildMetaLegacyBackend, + self).run_setup(setup_script=setup_script) + finally: + # While PEP 517 frontends should be calling each hook in a fresh + # subprocess according to the standard (and thus it should not be + # strictly necessary to restore the old sys.path), we'll restore + # the original path so that the path manipulation does not persist + # within the hook after run_setup is called. + sys.path[:] = sys_path + +# The primary backend _BACKEND = _BuildMetaBackend() get_requires_for_build_wheel = _BACKEND.get_requires_for_build_wheel @@ -194,3 +225,7 @@ 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 + + +# The legacy backend +legacy = _BuildMetaLegacyBackend() diff --git a/setuptools/build_meta_legacy.py b/setuptools/build_meta_legacy.py deleted file mode 100644 index 3d209711..00000000 --- a/setuptools/build_meta_legacy.py +++ /dev/null @@ -1,53 +0,0 @@ -"""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 os -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 original path - - script_dir = os.path.dirname(os.path.abspath(setup_script)) - if script_dir not in sys.path: - sys.path.insert(0, script_dir) - - try: - super(_BuildMetaLegacyBackend, - self).run_setup(setup_script=setup_script) - finally: - # While PEP 517 frontends should be calling each hook in a fresh - # subprocess according to the standard (and thus it should not be - # strictly necessary to restore the old sys.path), we'll restore - # the original path so that the path manipulation does not persist - # within the hook after run_setup is called. - sys.path[:] = sys_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 b29d6f29..42e3098a 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -23,7 +23,6 @@ class BuildBackendBase: self.env = env self.backend_name = backend_name - class BuildBackend(BuildBackendBase): """PEP 517 Build Backend""" @@ -43,12 +42,24 @@ class BuildBackend(BuildBackendBase): class BuildBackendCaller(BuildBackendBase): + def __init__(self, *args, **kwargs): + super(BuildBackendCaller, self).__init__(*args, **kwargs) + + (self.backend_name, _, + self.backend_obj) = self.backend_name.partition(':') + def __call__(self, name, *args, **kw): """Handles aribrary function invocations on the build backend.""" os.chdir(self.cwd) os.environ.update(self.env) mod = importlib.import_module(self.backend_name) - return getattr(mod, name)(*args, **kw) + + if self.backend_obj: + backend = getattr(mod, self.backend_obj) + else: + backend = mod + + return getattr(backend, name)(*args, **kw) defns = [ @@ -259,7 +270,7 @@ class TestBuildMetaBackend: class TestBuildMetaLegacyBackend(TestBuildMetaBackend): - backend_name = 'setuptools.build_meta_legacy' + backend_name = 'setuptools.build_meta:legacy' # build_meta_legacy-specific tests def test_build_sdist_relative_path_import(self, tmpdir_cwd): |