DevHeads.net

python3 entry_points console scripts packaging question

Hi,

Some context first, skip to the end if you want.

We have a few python packages at $work with setuptools entry_points
console scripts - basically setuptools creates a small python script for
you loading a module and calling the function you specified.

For example, clustershell here defines four commands (clubak cluset
clush and nodeset) here:
<a href="https://github.com/cea-hpc/clustershell/blob/master/setup.py#L57" title="https://github.com/cea-hpc/clustershell/blob/master/setup.py#L57">https://github.com/cea-hpc/clustershell/blob/master/setup.py#L57</a>

Setuptool embeds whatever python command was executed for running
setup.py at the start of the script, so if the command used in the spec
file was %py3_install as per the guidelines or even %{__python3}
setup.py something, you will get a #!/usr/bin/python3 shebang in your
scripts.

On the other hand, the script depends on what just got installed in
/usr/lib/python3.x/site-packages, so if python3 gets a major upgrade and
the /usr/bin/python3 link changes, the script will stop working
complaining that whatever it tried to import does not exist, while in
reality everything is still there, works if you run it with the right
python version, and the rpm requires ensure this properly.

For packages in fedora this doesn't matter as much as there is a python
mass rebuild when this happens, but I'm not sure it happens with epel
version bump, and it certainly doesn't happen for our internal packages
(hence this message!)

Now for the big question, should we try using `python%{python3_version}`
or fixing the link in scripts somehow for our rpms ?
Can anyone think of a cleaner way?

Another idea that just came to mind would be to try to write in the spec
file that we require /usr/bin/python3 to point to a specific version, so
that at least it fails to upgrade, but that doesn't sound much better
and I wouldn't know how to do that anyway.

Thanks,

Comments

Re: python3 entry_points console scripts packaging question

By =?UTF-8?B?TWlyb... at 11/27/2019 - 10:32

On 27. 11. 19 16:20, Dominique Martinet wrote:
If I understand this properly, your package requires (in Fedora):

- /usr/bin/python3
- python3.8dist(setuptools)

And in Fedora, when you ahve both of those, it also means that /usr/bin/python3
is Python 3.8.

However, this might not be the case for EPELs. The easiest way to ensure a
specific shebang is:

%global __python3 /usr/bin/python%{python3_version}