You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: application-modules.rst
-2Lines changed: 0 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -38,8 +38,6 @@ Let's take an example spec file and port it to illustrate the process. We start
38
38
39
39
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.
Copy file name to clipboardExpand all lines: applications.rst
-3Lines changed: 0 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,6 @@ Change ``BuildRequires`` from ``python-devel`` to ``python3-devel`` and adjust a
29
29
**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.**
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**.
16
17
17
18
18
19
Fixing shebangs
@@ -28,25 +29,27 @@ First find out what shebangs are used in your package by unpacking the sources f
28
29
$ # Searches only Python shebangs
29
30
$ grep -rE '^#!/usr/bin/(python|env python)' .
30
31
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
32
35
33
36
#!/usr/bin/python
34
37
#!/usr/bin/env python
35
38
36
39
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.
37
40
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.
39
42
40
43
.. code-block:: console
41
44
42
45
$ # 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 ...
44
47
45
48
$ # Change shebang in all relevant files in this directory and all subdirectories
46
49
$ # 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}_' {} \;
48
51
49
52
$ # 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}_' {} \;
51
54
52
55
You don't have to worry about accidentally corrupting other files as these scripts will only change a fileif the beginning of its first line exactly matches one of the two aforementioned shebangs.
0 commit comments