Skip to content

Commit 9e95853

Browse files
committed
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.
1 parent eef9582 commit 9e95853

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

setuptools/build_meta_legacy.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Compatibility backend for setuptools
2+
3+
This is a version of setuptools.build_meta that endeavors to maintain backwards
4+
compatibility with pre-PEP 517 modes of invocation. It exists as a temporary
5+
bridge between the old packaging mechanism and the new packaging mechanism,
6+
and will eventually be removed.
7+
"""
8+
9+
import sys
10+
11+
from setuptools.build_meta import _BuildMetaBackend
12+
from setuptools.build_meta import SetupRequirementsError
13+
14+
15+
__all__ = ['get_requires_for_build_sdist',
16+
'get_requires_for_build_wheel',
17+
'prepare_metadata_for_build_wheel',
18+
'build_wheel',
19+
'build_sdist',
20+
'SetupRequirementsError']
21+
22+
23+
class _BuildMetaLegacyBackend(_BuildMetaBackend):
24+
def run_setup(self, setup_script='setup.py'):
25+
# In order to maintain compatibility with scripts assuming that
26+
# the setup.py script is in a directory on the PYTHONPATH, inject
27+
# '' into sys.path. (pypa/setuptools#1642)
28+
sys_path = list(sys.path) # Save the old path
29+
if '' not in sys.path:
30+
sys.path.insert(0, '')
31+
32+
super(_BuildMetaLegacyBackend,
33+
self).run_setup(setup_script=setup_script)
34+
35+
sys.path = sys_path # Restore the old path
36+
37+
38+
_BACKEND = _BuildMetaLegacyBackend()
39+
40+
get_requires_for_build_wheel = _BACKEND.get_requires_for_build_wheel
41+
get_requires_for_build_sdist = _BACKEND.get_requires_for_build_sdist
42+
prepare_metadata_for_build_wheel = _BACKEND.prepare_metadata_for_build_wheel
43+
build_wheel = _BACKEND.build_wheel
44+
build_sdist = _BACKEND.build_sdist

setuptools/tests/test_build_meta.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ def test_build_sdist_relative_path_import(self, build_backend, tmpdir_cwd):
251251
build_backend.build_sdist("temp")
252252

253253

254-
@pytest.mark.xfail
255254
class TestBuildMetaLegacyBackend(TestBuildMetaBackend):
256255
backend_name = 'setuptools.build_meta_legacy'
257256

0 commit comments

Comments
 (0)