Skip to content

Commit

Permalink
Merge branch 'maint/44.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jan 14, 2020
2 parents 18a3cae + b5022cd commit c389dd1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/1704.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set sys.argv[0] in setup script run by build_meta.__legacy__
7 changes: 7 additions & 0 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ def run_setup(self, setup_script='setup.py'):
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)
Expand All @@ -242,6 +248,7 @@ def run_setup(self, setup_script='setup.py'):
# 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()
Expand Down
28 changes: 28 additions & 0 deletions setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,28 @@ def run():

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__'
Expand All @@ -417,3 +439,9 @@ def test_build_sdist_relative_path_import(self, tmpdir_cwd):

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")

0 comments on commit c389dd1

Please sign in to comment.