Skip to content

Commit 281a55e

Browse files
committed
Removed %prep subsection, polished Shebang subsection.
1 parent 3b52499 commit 281a55e

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

application-modules.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ Let's take an example spec file and port it to illustrate the process. We start
3838

3939
As we will be including the executable (application) only in the Python 3 subpackage, you may be also able to get rid of some runtime dependencies (listed using the ``Requires:`` tags) in the Python 2 subpackage that were previously used only by the executable and are therefore no longer needed in that subpackage. However, figuring out what runtime dependencies are no longer needed is a problematic task, therefore if you are unsure of which dependencies can be omitted, you can skip this task.
4040

41-
.. include:: subsections/h3-prep.inc
42-
4341
.. include:: subsections/h3-build.inc
4442

4543
.. include:: subsections/h3-install.inc

applications.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ Change ``BuildRequires`` from ``python-devel`` to ``python3-devel`` and adjust a
2929
**It is very important that you don't use any Python 2 dependencies as that would make your package depend both on Python version 2 and version 3, which would render your porting efforts useless.**
3030

3131

32-
.. include:: subsections/h3-prep.inc
33-
34-
3532
%build
3633
^^^^^^
3734

subsections/h3-prep.inc

Lines changed: 0 additions & 6 deletions
This file was deleted.

subsections/h3-shebangs.inc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ As the porting of the spec file is nearly finished, build it and then run the fo
1010
.. code-block:: console
1111
1212
$ # You can run this in mock as both rpm and grep are already installed.
13-
$ rpm -qp --requires path/to/an.rpm | grep -E '/usr/bin/(python|env python)'
13+
$ rpm -qp --requires path/to/an.rpm | grep -E '/usr/bin/(python|env)'
1414
15-
This will list all the Python executables your RPM package depends on. If you find that an RPM package for Python 3 depends on Python 2 (either as ``/usr/bin/python`` or ``/usr/bin/env python``) you need to fix it.
15+
16+
This will list all the Python executables your RPM package depends on as well as the ``/usr/bin/env`` executable which usually invokes ``python``. The use of ``env`` is dangerous: applications should be using the safe system version of Python and not trust whatever version ``env`` might try to substitute. **If you find that an RPM package for Python 3 depends on Python 2 or** ``/usr/bin/env``, **you need to fix it**.
1617
1718
1819
Fixing shebangs
@@ -28,25 +29,27 @@ First find out what shebangs are used in your package by unpacking the sources f
2829
$ # Searches only Python shebangs
2930
$ grep -rE '^#!/usr/bin/(python|env python)' .
3031
31-
You will usually find one of these two shebangs::
32+
You will usually find one of these two shebangs:
33+
34+
.. code-block:: bash
3235
3336
#!/usr/bin/python
3437
#!/usr/bin/env python
3538
3639
It is advisable to change both of these to ``#!/usr/bin/python3``. ``/usr/bin/env`` can be useful for scripts, but applications should link to the system version of Python outright.
3740
38-
To change the shebangs in the files you can use one (or a combination) of the following commands, which you should place at the end of the ``%prep`` section.
41+
To change the shebangs in the files you can use one (or a combination) of the following commands, which you should place at the end of the ``%prep`` section. They will change the shebangs to point to the Python 3 interpreter stored in the ``${__python3}`` macro.
3942
4043
.. code-block:: console
4144
4245
$ # Change shebang in individual files
43-
$ sed -i '1s_^#!/usr/bin/\(python\|env python\)_#!/usr/bin/python3_' path/to/file1 file2 file3 ...
46+
$ sed -i '1s_^#!/usr/bin/\(python\|env python\)_#!%{__python3}_' path/to/file1 file2 file3 ...
4447
4548
$ # Change shebang in all relevant files in this directory and all subdirectories
4649
$ # See `man find` for how the `-exec command ;` syntax works
47-
$ find . -type f -exec sed -i '1s_^#!/usr/bin/\(python\|env python\)_#!/usr/bin/python3_' {} \;
50+
$ find . -type f -exec sed -i '1s_^#!/usr/bin/\(python\|env python\)_#!%{__python3}_' {} \;
4851
4952
$ # Change shebang in all relevant executable files in this directory and all subdirectories
50-
$ find . -type f -executable -exec sed -i '1s_^#!/usr/bin/\(python\|env python\)_#!/usr/bin/python3_' {} \;
53+
$ find . -type f -executable -exec sed -i '1s_^#!/usr/bin/\(python\|env python\)_#!%{__python3}_' {} \;
5154
5255
You don't have to worry about accidentally corrupting other files as these scripts will only change a file if the beginning of its first line exactly matches one of the two aforementioned shebangs.

0 commit comments

Comments
 (0)