Skip to content

In build_scripts, unconditionally set shebang to #!python. #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2025

Conversation

jaraco
Copy link
Member

@jaraco jaraco commented Mar 8, 2025

In the past, distutils then Setuptools was a (/the) primary installer for packages. It therefore took on the responsibility of rewriting Python shebangs in scripts.

Later, Setuptools became primarily a build backend and defers to installers (pip, uv, ...) to do the rewriting. Yet, the rewrite logic remained in Setuptools and leads to complications (see astral-sh/uv#2744).

This change removes that rewriting logic, replacing it with a static #!python shebang to be rewritten by the installers.

I note that the test suite continues to pass unchanged, so the legacy behavior is not captured in the tests. Furthermore, I don't personally install explicit scripts in any of my packages (as they tend to be non-portable). We'll need to find another way to validate the impact of this change.

Closes pypa/setuptools#4863.

@jaraco jaraco force-pushed the debt/unify-shebang branch from ad516a6 to eecd653 Compare March 9, 2025 00:02
@jaraco jaraco merged commit 5589d75 into main Mar 9, 2025
44 checks passed
@jaraco jaraco deleted the debt/unify-shebang branch March 9, 2025 00:33
@hroncok
Copy link
Contributor

hroncok commented Mar 13, 2025

This seems to break the deprecated but still possible way of setup.py build --executable="/usr/bin/python3 -sP" + setup.py install (no external installers involved).

@abravalheri
Copy link
Contributor

This seems to break the deprecated but still possible way of setup.py build --executable="/usr/bin/python3 -sP" + setup.py install (no external installers involved).

This is related to the discussion in pypa/setuptools#4883.

My personal view is to prioritize non deprecated workflows. If the transition to non-deprecated workflows is not viable for all users that require such feature, I would welcome viable alternative approaches via PR contributions from the interested parties (which solve simultaneously the problem in pypa/setuptools#4863 and the one described in #332 (comment)).

jwilk added a commit to jwilk/pydiatra that referenced this pull request Mar 29, 2025
"setup.py install" is helplessly broken since setuptools v76:
pypa/distutils#332

When we're at it, test "pip install" more thoroughly.
if not sysconfig.python_build:
executable = self.executable
else:
executable = os.path.join(
sysconfig.get_config_var("BINDIR"),
"python{}{}".format(
sysconfig.get_config_var("VERSION"),
sysconfig.get_config_var("EXE"),
),
)
post_interp = shebang_match.group(1) or ''
shebang = "#!" + executable + post_interp + "\n"
shebang = f"#!python{post_interp}\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the wrong approach. This code belongs to the build_scripts code, which may be invoked via the CLI, and even receives a executable argument, which is now explicitly ignored.

The #!python functionality is part of PEP 427, and as such, should be implemented in the wheel building code, not here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems bdist_wheel already implements this functionality itself, so the build_editable issue seems like a bug on the setuptools.build_meta backend. I believe fixing it should be as simple as setting executable there to python, just like bdist_wheel does.

https://github.com/pypa/wheel/blob/c8f1f09d1abee526851b4e058331db5489a335c4/src/wheel/_bdist_wheel.py#L382-L384

@FFY00
Copy link
Member

FFY00 commented Apr 22, 2025

My personal view is to prioritize non deprecated workflows. If the transition to non-deprecated workflows is not viable for all users that require such feature, I would welcome viable alternative approaches via PR contributions from the interested parties (which solve simultaneously the problem in pypa/setuptools#4863 and the one described in #332 (comment)).

There's a reason we have a setuptools.build_meta:__legacy__ and setuptools.build_meta backend. I don't think we should be making backward-incompatible changes to the legacy code unless strictly necessary.

In this case, it seems the change was exclusively motivated by a feature of the new backend, and it doesn't seem to me like there's a particular technical requirement for changes to the legacy code, so I can't see the justification for this approach.

@hroncok
Copy link
Contributor

hroncok commented Apr 22, 2025

Im Fedora, we needed to revert this entirely.

@0-wiz-0
Copy link

0-wiz-0 commented Apr 22, 2025

We've also reverted this change in the setuptools package in pkgsrc.

jaraco added a commit that referenced this pull request May 3, 2025
clrpackages pushed a commit to clearlinux-pkgs/pypi-setuptools that referenced this pull request May 6, 2025
…version 80.3.1

Jason R. Coombs (25):
      Remove reference in test_windows_wrappers to easy_install.
      Moved some fixtures out of test_easy_install.
      Moved scripts functionality into its own module.
      Reference utility functions from _shutil.
      Remove easy_install and package_index.
      Revert "Merge pull request pypa/distutils#332 from pypa/debt/unify-shebang"
      Remove support for special executable under a Python build.
      In build_editable, ensure that 'executable' is hard-coded to #!python for portability.
      Add news fragment.
      Fix import.
      Cast is unnecessary, apparently
      Bump version: 80.1.0 → 80.2.0
      Replace copy of license with an SPDX identifier. (jaraco/skeleton#171)
      Add news fragment.
      Update tests in setuptools/dist not to rely on Setuptools having a license file.
      Rely on path.Path for directory context.
      Add news fragment.
      Bump version: 80.2.0 → 80.3.0
      Moved pbr setup into a fixture.
      Add a failing integration test. Ref #4976
      Restore ScriptWriter and sys_executable properties.
      Render the attributes dynamically.
      Add the deprecation warning to attribute access.
      Add news fragment.
      Bump version: 80.3.0 → 80.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] build_editable does not emit #!python shebang for scripts
5 participants