Modify interpreter directives in Python scripts
Modify the packaged Python scripts so that they conform to the expected format.
Before you begin
- Some of the interpreter directives in your Python scripts cause a build error.
About this task
In Red Hat Enterprise Linux (RHEL) 10, executable Python scripts are expected to use interpreter directives, also known as hashbangs or shebangs, that explicitly specify at a minimum the major Python version. For example:
#!/usr/bin/python3
#!/usr/bin/python3.12
The /usr/lib/rpm/redhat/brp-mangle-shebangsbuildroot policy (BRP) script is run automatically when building any RPM package, and attempts to correct interpreter directives in all executable files. The BRP script generates errors when encountering a Python script with an ambiguous interpreter directive, for example, #!/usr/bin/python or #!/usr/bin/env python.
Procedure
- Use the following macro in the
%prepsection of yourspecfile:%py3_shebang_fix <SCRIPTNAME> ...SCRIPTNAME can be any file, directory, or a list of files and directories.
As a result, all listed files and all
.pyfiles in listed directories have their interpreter directives modified to point to%{python3}. Existing flags from the original interpreter directive will be preserved and additional flags defined in the%{py3_shebang_flags}macro will be added. You can redefine the%{py3_shebang_flags}macro in yourspecfile to change the flags that will be added. - Modify the packaged Python scripts so that they conform to the expected format.