diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-01-14 18:43:48 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-01-14 18:43:48 -0500 |
commit | b5022cdbf60e1ba072af3af83c79df657272c56d (patch) | |
tree | ecd6bd6e623b9d75d866c8e310dbbd51f67630a7 | |
parent | d1bf0d2a92350b6dea783821868cc93aba17b813 (diff) | |
parent | b2701fb39252fc68b4f0b22c3a3b79039f4cc58e (diff) | |
download | python-setuptools-git-b5022cdbf60e1ba072af3af83c79df657272c56d.tar.gz |
Merge branch 'sys_argv' of https://github.com/aimileus/setuptools into maint/44.x
-rw-r--r-- | changelog.d/1704.change.rst | 1 | ||||
-rw-r--r-- | setuptools/build_meta.py | 7 | ||||
-rw-r--r-- | setuptools/tests/test_build_meta.py | 28 |
3 files changed, 36 insertions, 0 deletions
diff --git a/changelog.d/1704.change.rst b/changelog.d/1704.change.rst new file mode 100644 index 00000000..62450835 --- /dev/null +++ b/changelog.d/1704.change.rst @@ -0,0 +1 @@ +Set sys.argv[0] in setup script run by build_meta.__legacy__ diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index 10c4b528..eb9e815e 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -232,6 +232,12 @@ class _BuildMetaLegacyBackend(_BuildMetaBackend): if script_dir not in sys.path: sys.path.insert(0, script_dir) + # Some setup.py scripts (e.g. in pygame and numpy) use sys.argv[0] to + # get the directory of the source code. They expect it to refer to the + # setup.py script. + sys_argv_0 = sys.argv[0] + sys.argv[0] = setup_script + try: super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script) @@ -242,6 +248,7 @@ class _BuildMetaLegacyBackend(_BuildMetaBackend): # the original path so that the path manipulation does not persist # within the hook after run_setup is called. sys.path[:] = sys_path + sys.argv[0] = sys_argv_0 # The primary backend _BACKEND = _BuildMetaBackend() diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py index 326b4f5d..d68444f6 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -406,6 +406,28 @@ class TestBuildMetaBackend: assert expected == sorted(actual) + _sys_argv_0_passthrough = { + 'setup.py': DALS(""" + import os + import sys + + __import__('setuptools').setup( + name='foo', + version='0.0.0', + ) + + sys_argv = os.path.abspath(sys.argv[0]) + file_path = os.path.abspath('setup.py') + assert sys_argv == file_path + """) + } + + def test_sys_argv_passthrough(self, tmpdir_cwd): + build_files(self._sys_argv_0_passthrough) + build_backend = self.get_build_backend() + with pytest.raises(AssertionError): + build_backend.build_sdist("temp") + class TestBuildMetaLegacyBackend(TestBuildMetaBackend): backend_name = 'setuptools.build_meta:__legacy__' @@ -417,3 +439,9 @@ class TestBuildMetaLegacyBackend(TestBuildMetaBackend): build_backend = self.get_build_backend() build_backend.build_sdist("temp") + + def test_sys_argv_passthrough(self, tmpdir_cwd): + build_files(self._sys_argv_0_passthrough) + + build_backend = self.get_build_backend() + build_backend.build_sdist("temp") |