Skip to content

Use robust shebang manipulation also for (data)/scripts (e.g. to support spaces in venv paths) #13389

Open
@flying-sheep

Description

@flying-sheep

Description

pip install adds the target interpreter’s path to script shebangs both for scripts defined via entry points and for scripts in (data)/scripts (i.e. the wheel path pkg_name-1.2.2.data/scripts/).

However for the latter, it uses more brittle code to create the shebang.

So this:

exename = sys.executable.encode(sys.getfilesystemencoding())
firstline = b"#!" + exename + os.linesep.encode("ascii")

should be changed to use this code:

def _get_shebang(self, encoding, post_interp=b'', options=None):

See: ranger/ranger#2941 (comment)
See also:

Expected behavior

Shebang is correctly modified

pip version

25.0.1

Python version

3.13

OS

Linux/MacOS

How to Reproduce & Output

$ mkdir "path with spaces"
$ cd "path with spaces"
$ python -m venv .venv
$ .venv/bin/pip install ranger-fm==1.9.4
$ head -n1 .venv/bin/ranger
#!/home/me/path with spaces/.venv/bin/python
$ .venv/bin/ranger
zsh:1: .venv/bin/ranger: bad interpreter: /home/me/path: no such file or directory

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugA confirmed bug or unintended behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions