Skip to content

Commit c389dd1

Browse files
committed
Merge branch 'maint/44.x'
2 parents 18a3cae + b5022cd commit c389dd1

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

changelog.d/1704.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set sys.argv[0] in setup script run by build_meta.__legacy__

setuptools/build_meta.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ def run_setup(self, setup_script='setup.py'):
232232
if script_dir not in sys.path:
233233
sys.path.insert(0, script_dir)
234234

235+
# Some setup.py scripts (e.g. in pygame and numpy) use sys.argv[0] to
236+
# get the directory of the source code. They expect it to refer to the
237+
# setup.py script.
238+
sys_argv_0 = sys.argv[0]
239+
sys.argv[0] = setup_script
240+
235241
try:
236242
super(_BuildMetaLegacyBackend,
237243
self).run_setup(setup_script=setup_script)
@@ -242,6 +248,7 @@ def run_setup(self, setup_script='setup.py'):
242248
# the original path so that the path manipulation does not persist
243249
# within the hook after run_setup is called.
244250
sys.path[:] = sys_path
251+
sys.argv[0] = sys_argv_0
245252

246253
# The primary backend
247254
_BACKEND = _BuildMetaBackend()

setuptools/tests/test_build_meta.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,28 @@ def run():
406406

407407
assert expected == sorted(actual)
408408

409+
_sys_argv_0_passthrough = {
410+
'setup.py': DALS("""
411+
import os
412+
import sys
413+
414+
__import__('setuptools').setup(
415+
name='foo',
416+
version='0.0.0',
417+
)
418+
419+
sys_argv = os.path.abspath(sys.argv[0])
420+
file_path = os.path.abspath('setup.py')
421+
assert sys_argv == file_path
422+
""")
423+
}
424+
425+
def test_sys_argv_passthrough(self, tmpdir_cwd):
426+
build_files(self._sys_argv_0_passthrough)
427+
build_backend = self.get_build_backend()
428+
with pytest.raises(AssertionError):
429+
build_backend.build_sdist("temp")
430+
409431

410432
class TestBuildMetaLegacyBackend(TestBuildMetaBackend):
411433
backend_name = 'setuptools.build_meta:__legacy__'
@@ -417,3 +439,9 @@ def test_build_sdist_relative_path_import(self, tmpdir_cwd):
417439

418440
build_backend = self.get_build_backend()
419441
build_backend.build_sdist("temp")
442+
443+
def test_sys_argv_passthrough(self, tmpdir_cwd):
444+
build_files(self._sys_argv_0_passthrough)
445+
446+
build_backend = self.get_build_backend()
447+
build_backend.build_sdist("temp")

0 commit comments

Comments
 (0)