Skip to content

Commit

Permalink
Add build_meta_legacy backend
Browse files Browse the repository at this point in the history
This is part of the solution to GH pypa#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.
  • Loading branch information
pganssle committed Jan 27, 2019
1 parent eef9582 commit 9e95853
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
44 changes: 44 additions & 0 deletions setuptools/build_meta_legacy.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def test_build_sdist_relative_path_import(self, build_backend, tmpdir_cwd):
build_backend.build_sdist("temp")


@pytest.mark.xfail
class TestBuildMetaLegacyBackend(TestBuildMetaBackend):
backend_name = 'setuptools.build_meta_legacy'

Expand Down

0 comments on commit 9e95853

Please sign in to comment.