After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 782298 - Hardcoded path #!/usr/bin/python3 found in build-aux/post-install.py
Hardcoded path #!/usr/bin/python3 found in build-aux/post-install.py
Status: RESOLVED FIXED
Product: gnome-clocks
Classification: Applications
Component: general
3.25.x
Other FreeBSD
: Normal normal
: ---
Assigned To: Clocks maintainer(s)
Clocks maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2017-05-07 13:59 UTC by Ting-Wei Lan
Modified: 2018-01-02 18:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
build: fix the path to python3 for mesonscripts/post_install.py (643 bytes, patch)
2017-05-07 14:00 UTC, Ting-Wei Lan
none Details | Review
build: fix the path to python3 for build-aux/post-install.py (624 bytes, patch)
2017-12-27 03:31 UTC, Ting-Wei Lan
none Details | Review
build: Use python3 found by meson to run build-aux/post-install.py (1.30 KB, patch)
2018-01-02 18:27 UTC, Ting-Wei Lan
committed Details | Review

Description Ting-Wei Lan 2017-05-07 13:59:33 UTC
Some systems don't install python in /usr/bin, so using the hardcoded /usr/bin/python3 path may cause 'no such file or directory' error when the script is run.
Comment 1 Ting-Wei Lan 2017-05-07 14:00:18 UTC
Created attachment 351299 [details] [review]
build: fix the path to python3 for mesonscripts/post_install.py
Comment 2 Jeremy Bicha 2017-10-15 18:38:57 UTC
What kind of system would we want to run gnome-clocks in that doesn't have python3 installed system-wide?
Comment 3 Ting-Wei Lan 2017-10-16 09:21:41 UTC
This problem was found on FreeBSD and python was installed system-wide with packages. The problem is that many *BSD systems use two prefixes: /usr is reserved for the base system. Packages are not considered part of the operating system, so they are installed into /usr/local, /usr/pkg or other user-chosen prefixes. Python is not included in the base system, so it cannot be installed into /usr.
Comment 4 Ting-Wei Lan 2017-12-27 03:31:35 UTC
Created attachment 365999 [details] [review]
build: fix the path to python3 for build-aux/post-install.py
Comment 5 Jeremy Bicha 2017-12-27 04:13:53 UTC
I still don't like these changes.

Debian automatically rewrites the shebangs for packaged Python scripts to have them work consistently and appropriately for Debian. (The GNOME Tweaks shebang on Debian is /usr/bin/python3 ).

Why can't BSD do that too if they're going to have an unusual system?

I do not think it's right for whatever version of Python a user has locally installed to be used to run GNOME Tweaks. I want the system Python 3 only to be used.
Comment 6 Ting-Wei Lan 2017-12-27 15:09:56 UTC
(In reply to Jeremy Bicha from comment #5)
> I still don't like these changes.
> 
> Debian automatically rewrites the shebangs for packaged Python scripts to
> have them work consistently and appropriately for Debian. (The GNOME Tweaks
> shebang on Debian is /usr/bin/python3 ).

Using absolute path in shebangs of packaged scripts is correct and recommended. FreeBSD does do the same thing, so the shebang of gnome-tweak-tool on FreeBSD is /usr/local/bin/python2.7. (FreeBSD still uses GNOME 3.18 so it is python2)

However, I think the rule of using hard-coded path only applies to files provided by distributions. We cannot expect all distributions to install python3 to the same path, and the only portable absolute paths are /bin/sh and /usr/bin/env. The proper way of hard-coding paths of interpreters into scripts is to use '#!@PYTHON@' in shebangs and ask the build system to replace them with the path it find. You only rely on PATH to find python3 at build time. After the package is installed, it becomes an absolute path specific to a distribution so users cannot change it with PATH. Thus, we follow the recommendation of distributions without hard-coding non-portable paths in sources.

> 
> Why can't BSD do that too if they're going to have an unusual system?
> 

I think the problem is not 'why we cannot do' but 'why we have to do'. Yes, FreeBSD ports has the ability to patch shebangs by setting one variable in Makefile. It can even patch outdated configure or libtool scripts to fix common problems by setting a variable. However, if users decide to build software from sources by themselves, they will wonder why they cannot build it while the version in FreeBSD ports can be built successfully without any patch files.

I use JHBuild to build GNOME directly from upstream git repositories in order to catch problems early. I think it is good to reduce the number of downstream patches, so everything can be tested easily.

> I do not think it's right for whatever version of Python a user has locally
> installed to be used to run GNOME Tweaks. I want the system Python 3 only to
> be used.

build-aux/post-install.py is not an installed script. It is only used during 'ninja install'. It is not something users can use after installation is done. Since we are required to rely on PATH to find python3 during 'configure' and 'build' phases, I don't know why we cannot use '#!/usr/bin/env python3' in a script used for installation. build-aux/post-install.py is not gnome-tweak-tool and it should never be packaged.
Comment 7 Jeremy Bicha 2017-12-27 16:49:14 UTC
Oh, I'm not the GNOME Clocks maintainer. I didn't read my bug mail closely enough to see that this wasn't for GNOME Tweaks, so never mind.
Comment 8 Paolo Borelli 2017-12-28 21:14:59 UTC
I do not have strong objections, but I guess my question is: what does meson do? meson itself is written in python so we should do the same.

Also, is there a way to ask meson to run these kind of scripts with the same interpreter used to run meson itself?
Comment 9 Ting-Wei Lan 2017-12-29 08:52:54 UTC
(In reply to Paolo Borelli from comment #8)
> I do not have strong objections, but I guess my question is: what does meson
> do? meson itself is written in python so we should do the same.
> 

meson.py in the source repository uses '#!/usr/bin/env python3'. meson installed on the system uses the absolute path to python used to run 'setup.py'.

For example, on FreeBSD, if I install meson with 'python3 setup.py install', the shebang of the installed meson script is '#!/usr/local/bin/python3'. If I install it with 'python3.6 setup.py install', the shabang is '#!/usr/local/bin/python3.6'.

> Also, is there a way to ask meson to run these kind of scripts with the same
> interpreter used to run meson itself?

Meson has a module called 'Python 3', so I think we can do it this way:

python3 = import('python3')
meson.add_install_script(python3.find_python().path(),
  join_paths(meson.source_root(), 'build-aux', 'post-install.py'))
Comment 10 Paolo Borelli 2018-01-01 15:40:48 UTC
sounds good
Comment 11 Ting-Wei Lan 2018-01-02 18:27:35 UTC
Created attachment 366213 [details] [review]
build: Use python3 found by meson to run build-aux/post-install.py
Comment 12 Paolo Borelli 2018-01-02 18:37:25 UTC
Review of attachment 366213 [details] [review]:

If it is tested, sure, go ahead. Thanks!

Can you do the same for baobab?
Comment 13 Ting-Wei Lan 2018-01-02 18:48:26 UTC
Yes, I attached a new patch to baobab.

Attachment 366213 [details] pushed as 6541a87 - build: Use python3 found by meson to run build-aux/post-install.py