Bug 2043652

Summary: /usr/bin/thg should not have -s "don't add user site directory to sys.path" in Python shebang
Product: [Fedora] Fedora Reporter: Simon Sapin <simon-bugzila-redhat>
Component: tortoisehgAssignee: Mads Kiilerich <mads>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 35CC: mads, ndbecker2
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: tortoisehg-6.0-3.fc36 tortoisehg-5.9.3-3.fc35 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-01-26 15:33:28 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Simon Sapin 2022-01-21 16:37:25 UTC
Description of problem:
The shebang is `#!/usr/bin/python3 -s`, which breaks user-installed Mercurial extensions


Version-Release number of selected component (if applicable):
5.9.3-2.fc35


How reproducible:
Always


Steps to Reproduce:
1. Install Mercurial and TortoiseHg from Fedora packages
2. The "evolve" Mercurial extension is not available as a Fedora package, so install it as a user: `pip install --user hg-evolve`
3. Enable it in ~/.hgrc:

    [extensions]
    topic =
    evolve =

4. Check installation: `hg help evolve`
5. Run `thg` for GUI visualization


Actual results:

On stderr:

    *** failed to import extension topic: No module named 'topic'
    *** failed to import extension evolve: No module named 'evolve'

In GUI: TortoiseHg starts but shows an incomplete (arguably incorrect) graph.


Expected results:
TortoiseHg can load user-install Mercurial extensions just like CLI `hg` can.


Additional info:
Running `python3 /usr/bin/thg` works as expected. The culprit is the `-s` flag that is part of the shebang line of /usr/bin/thg. This flag is not present upstream: https://foss.heptapod.net/mercurial/tortoisehg/thg/-/blob/branch/stable/thg so it is presumably added by Fedora packaging.

Per https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_shebangs "undefining the `%{py3_shebang_flags}` macro" would be appropriate here, though I don’t know how that can be done.

Comment 1 Mads Kiilerich 2022-01-26 10:39:02 UTC
Note to self:

This is caused by the %build section using %py3_build which expands to:
  /usr/bin/python3 setup.py build '--executable=/usr/bin/python3 -s'
using %py3_shebang_flags .

setup.py uses distutils, and in /usr/lib64/python3.10/distutils/command/build_scripts.py it uses this specified "executable" to adjust the #! line when copying the source 'thg' to 'build/scripts-3.10/thg'. In %install, %py3_install will install that into $RPM_BUILD_ROOT/usr/bin/thg .


-s is really a good thing for system installed python programs so user's can't break it, and sad that the Mercurial extension system is incompatible.

I will disable py3_shebang_flags.

(It also has the minor eye-hurting side effect that the #! line ends with a space ;-) )

Comment 2 Fedora Update System 2022-01-26 10:53:31 UTC
FEDORA-2022-0d11fa0da8 has been submitted as an update to Fedora 36. https://bodhi.fedoraproject.org/updates/FEDORA-2022-0d11fa0da8

Comment 3 Fedora Update System 2022-01-26 15:33:28 UTC
FEDORA-2022-0d11fa0da8 has been pushed to the Fedora 36 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 4 Fedora Update System 2022-01-26 19:21:08 UTC
FEDORA-2022-ccab8e7817 has been submitted as an update to Fedora 35. https://bodhi.fedoraproject.org/updates/FEDORA-2022-ccab8e7817

Comment 5 Neal Becker 2022-01-27 18:30:12 UTC
Thanks for finding this!  I've been wondering why I had trouble with thg finding my locally installed extensions.

Comment 6 Fedora Update System 2022-01-27 22:51:25 UTC
FEDORA-2022-ccab8e7817 has been pushed to the Fedora 35 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2022-ccab8e7817`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2022-ccab8e7817

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 7 Fedora Update System 2022-02-04 01:21:56 UTC
FEDORA-2022-ccab8e7817 has been pushed to the Fedora 35 stable repository.
If problem still persists, please make note of it in this bug report.