Skip to content

[BUG] Setuptools 76.0.0 breaks shebang generation during script installation #4883

@isuftin

Description

@isuftin

setuptools version

setuptools==76.0.0

Python version

3.9

OS

RHEL 9

Additional environment information

No response

Description

At least for installing AWS's cfn-bootstrap set of scripting, the latest version of setuptools seems to break the shebang.

Via setuptools 76.x

python3 --version
Python 3.9.21

pip --version
pip 21.3.1 from /usr/lib/python3.9/site-packages/pip (python 3.9)

 python3 -m pip install --force-reinstall --no-cache https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
Collecting https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  Downloading https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz (549 kB)
     |████████████████████████████████| 549 kB 32.5 MB/s
  Preparing metadata (setup.py) ... done
Collecting python-daemon<2.3,>=2.2.4
  Downloading python_daemon-2.2.4-py2.py3-none-any.whl (35 kB)
Collecting chevron
  Downloading chevron-0.14.0-py3-none-any.whl (11 kB)
Collecting docutils
  Downloading docutils-0.21.2-py3-none-any.whl (587 kB)
     |████████████████████████████████| 587 kB 21.7 MB/s
Collecting setuptools
  Downloading setuptools-76.0.0-py3-none-any.whl (1.2 MB)
     |████████████████████████████████| 1.2 MB 40.1 MB/s
Collecting lockfile>=0.10
  Downloading lockfile-0.12.2-py2.py3-none-any.whl (13 kB)
Using legacy 'setup.py install' for aws-cfn-bootstrap, since package 'wheel' is not installed.
Installing collected packages: setuptools, lockfile, docutils, python-daemon, chevron, aws-cfn-bootstrap
  Attempting uninstall: setuptools
    Found existing installation: setuptools 76.0.0
    Uninstalling setuptools-76.0.0:
      Successfully uninstalled setuptools-76.0.0
  Attempting uninstall: lockfile
    Found existing installation: lockfile 0.12.2
    Uninstalling lockfile-0.12.2:
      Successfully uninstalled lockfile-0.12.2
  Attempting uninstall: docutils
    Found existing installation: docutils 0.21.2
    Uninstalling docutils-0.21.2:
      Successfully uninstalled docutils-0.21.2
  Attempting uninstall: python-daemon
    Found existing installation: python-daemon 2.2.4
    Uninstalling python-daemon-2.2.4:
      Successfully uninstalled python-daemon-2.2.4
  Attempting uninstall: chevron
    Found existing installation: chevron 0.14.0
    Uninstalling chevron-0.14.0:
      Successfully uninstalled chevron-0.14.0
  Attempting uninstall: aws-cfn-bootstrap
    Found existing installation: aws-cfn-bootstrap 2.0
    Uninstalling aws-cfn-bootstrap-2.0:
      Successfully uninstalled aws-cfn-bootstrap-2.0
    Running setup.py install for aws-cfn-bootstrap ... done
Successfully installed aws-cfn-bootstrap-2.0 chevron-0.14.0 docutils-0.21.2 lockfile-0.12.2 python-daemon-2.2.4 setuptools-76.0.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

cat /usr/local/bin/cfn-hup | head -n3
#!python

# ==============================================================================

/usr/local/bin/cfn-hup --help
bash: /usr/local/bin/cfn-hup: python: bad interpreter: No such file or directory

With setuptools <76

python3 -m pip install --force-reinstall --no-cache https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz "setuptools<76"
Collecting https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  Downloading https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz (549 kB)
     |████████████████████████████████| 549 kB 12.9 MB/s
  Preparing metadata (setup.py) ... done
Collecting setuptools<76
  Downloading setuptools-75.9.1-py3-none-any.whl (1.2 MB)
     |████████████████████████████████| 1.2 MB 10.9 MB/s
Collecting python-daemon<2.3,>=2.2.4
  Downloading python_daemon-2.2.4-py2.py3-none-any.whl (35 kB)
Collecting chevron
  Downloading chevron-0.14.0-py3-none-any.whl (11 kB)
Collecting docutils
  Downloading docutils-0.21.2-py3-none-any.whl (587 kB)
     |████████████████████████████████| 587 kB 41.4 MB/s
Collecting lockfile>=0.10
  Downloading lockfile-0.12.2-py2.py3-none-any.whl (13 kB)
Using legacy 'setup.py install' for aws-cfn-bootstrap, since package 'wheel' is not installed.
Installing collected packages: setuptools, lockfile, docutils, python-daemon, chevron, aws-cfn-bootstrap
  Attempting uninstall: setuptools
    Found existing installation: setuptools 76.0.0
    Uninstalling setuptools-76.0.0:
      Successfully uninstalled setuptools-76.0.0
  Attempting uninstall: lockfile
    Found existing installation: lockfile 0.12.2
    Uninstalling lockfile-0.12.2:
      Successfully uninstalled lockfile-0.12.2
  Attempting uninstall: docutils
    Found existing installation: docutils 0.21.2
    Uninstalling docutils-0.21.2:
      Successfully uninstalled docutils-0.21.2
  Attempting uninstall: python-daemon
    Found existing installation: python-daemon 2.2.4
    Uninstalling python-daemon-2.2.4:
      Successfully uninstalled python-daemon-2.2.4
  Attempting uninstall: chevron
    Found existing installation: chevron 0.14.0
    Uninstalling chevron-0.14.0:
      Successfully uninstalled chevron-0.14.0
  Attempting uninstall: aws-cfn-bootstrap
    Found existing installation: aws-cfn-bootstrap 2.0
    Uninstalling aws-cfn-bootstrap-2.0:
      Successfully uninstalled aws-cfn-bootstrap-2.0
    Running setup.py install for aws-cfn-bootstrap ... done
Successfully installed aws-cfn-bootstrap-2.0 chevron-0.14.0 docutils-0.21.2 lockfile-0.12.2 python-daemon-2.2.4 setuptools-75.9.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

 cat /usr/local/bin/cfn-hup | head -n3
#!/bin/python3

# ==============================================================================

/usr/local/bin/cfn-hup --help
Usage: cfn-hup [options]

Options:
  -h, --help            show this help message and exit
  -c CONFIG_PATH, --config=CONFIG_PATH
                        The configuration directory (default: /etc/cfn)
  --no-daemon           Do not daemonize
  -v, --verbose         Enables verbose logging

It looks like 76.x introduced this regression. I'm not sure if there's a better method of forcing setuptools to properly set the shebang line?

Expected behavior

setuptools sets the correct shebang line in scripts installed via pip

How to Reproduce

docker run --rm  redhat/ubi9 /bin/bash -c "yum install -y python3 python3-pip &&  python3 -m pip install --force-reinstall --no-cache https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz && /usr/local/bin/cfn-hup"

Output

Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Red Hat Universal Base Image 9 (RPMs) - BaseOS  567 kB/s | 525 kB     00:00
Red Hat Universal Base Image 9 (RPMs) - AppStre 2.6 MB/s | 2.3 MB     00:00
Red Hat Universal Base Image 9 (RPMs) - CodeRea 413 kB/s | 281 kB     00:00
Package python3-3.9.21-1.el9_5.x86_64 is already installed.
Dependencies resolved.
================================================================================
 Package             Arch      Version            Repository               Size
================================================================================
Installing:
 python3-pip         noarch    21.3.1-1.el9       ubi-9-appstream-rpms    2.0 M
Installing weak dependencies:
 libxcrypt-compat    x86_64    4.4.18-3.el9       ubi-9-appstream-rpms     91 k

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 2.1 M
Installed size: 9.0 M
Downloading Packages:
(1/2): libxcrypt-compat-4.4.18-3.el9.x86_64.rpm 225 kB/s |  91 kB     00:00
(2/2): python3-pip-21.3.1-1.el9.noarch.rpm      3.5 MB/s | 2.0 MB     00:00
--------------------------------------------------------------------------------
Total                                           3.5 MB/s | 2.1 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : libxcrypt-compat-4.4.18-3.el9.x86_64                   1/2
  Installing       : python3-pip-21.3.1-1.el9.noarch                        2/2
  Running scriptlet: python3-pip-21.3.1-1.el9.noarch                        2/2
  Verifying        : libxcrypt-compat-4.4.18-3.el9.x86_64                   1/2
  Verifying        : python3-pip-21.3.1-1.el9.noarch                        2/2
Installed products updated.

Installed:
  libxcrypt-compat-4.4.18-3.el9.x86_64      python3-pip-21.3.1-1.el9.noarch

Complete!
Collecting https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  Downloading https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz (549 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Collecting python-daemon<2.3,>=2.2.4
  Downloading python_daemon-2.2.4-py2.py3-none-any.whl (35 kB)
Collecting chevron
  Downloading chevron-0.14.0-py3-none-any.whl (11 kB)
Collecting docutils
  Downloading docutils-0.21.2-py3-none-any.whl (587 kB)
Collecting setuptools
  Downloading setuptools-76.0.0-py3-none-any.whl (1.2 MB)
Collecting lockfile>=0.10
  Downloading lockfile-0.12.2-py2.py3-none-any.whl (13 kB)
Using legacy 'setup.py install' for aws-cfn-bootstrap, since package 'wheel' is not installed.
Installing collected packages: setuptools, lockfile, docutils, python-daemon, chevron, aws-cfn-bootstrap
    Running setup.py install for aws-cfn-bootstrap: started
    Running setup.py install for aws-cfn-bootstrap: finished with status 'done'
Successfully installed aws-cfn-bootstrap-2.0 chevron-0.14.0 docutils-0.21.2 lockfile-0.12.2 python-daemon-2.2.4 setuptools-76.0.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
/bin/bash: /usr/local/bin/cfn-hup: python: bad interpreter: No such file or directory

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssues that need to be evaluated for severity and status.bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions