Gentoo Archives: gentoo-dev

From: Arfrever Frehtes Taifersar Arahesis <Arfrever@g.o>
To: Gentoo Development <gentoo-dev@l.g.o>
Subject: [gentoo-dev] Versioning of Python scripts
Date: Sat, 19 Dec 2009 15:23:00
Message-Id: 200912191624.55244.Arfrever@gentoo.org
1 Distutils/Setuptools/Distribute modify shebangs of installed Python scripts, so that they
2 contain path of Python interpreter with version included (e.g. "#!/usr/bin/python3.2").
3 This behavior has both advantage and disadvantages:
4 - Scripts of packages supporting only e.g. Python 2 can be executed (without necessity
5 of using of e.g. "python2 /usr/bin/${script}") after activating of e.g. Python 3.
6 - Scripts of packages supporting multiple Python versions ignore active Python version.
7 - Scripts of packages supporting multiple Python versions cannot be easily (without
8 necessity of using of e.g. "python3.1 /usr/bin/${script}") executed with a Python
9 version different than active Python version.
10 The best solution, which removes these 2 disadvantages and preserves the advantage, seems
11 to be to rename Python scripts to include Python version [1] in filenames, and create wrapper
12 scripts, which call appropriate target scripts [2]. Some files sometimes try to execute
13 e.g. "/usr/bin/python /usr/bin/${script}", so wrapper scripts must be implemented in Python.
14 Wrapper scripts try to execute "${wrapper_script}-${PYTHON_ABI}" files (e.g. "py.test" will
15 execute "py.test-3.1", when Python 3.1 is set as active Python version).
16
17 distutils.eclass will automatically rename some scripts [3] in "${D}usr/bin" and call
18 the function, which generates wrapper scripts. In case somebody is interested in reading of
19 source code of python_generate_wrapper_scripts() function and potential suggesting of
20 improvements, I'm attaching this function and 2 example wrapper scripts. I'm planning to
21 commit addition of this function in next week.
22
23 [1] Actually Python ABI.
24 [2] Wrapper scripts can also be created for ELF target files (e.g. "mpipython").
25 [3] Only scripts of packages supporting installation for multiple Python versions will be
26 renamed. Scripts, whose filenames end in [[:digit:]]+\.[[:digit:]]+, won't be renamed.
27
28 --
29 Arfrever Frehtes Taifersar Arahesis

Attachments

File name MIME type
python_generate_wrapper_scripts.function text/plain
sphinx-build text/x-python
py.test text/x-python
signature.asc application/pgp-signature

Replies

Subject Author
Re: [gentoo-dev] Versioning of Python scripts Brian Harring <ferringb@×××××.com>
Re: [gentoo-dev] Versioning of Python scripts Peter Volkov <pva@g.o>