From b9799cec15b079f996402ba484f75fc84cbf19c6 Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Fri, 26 Apr 2024 12:03:03 +0200 Subject: [PATCH 1/2] Fix: No traceback when Python interpreter is running with -P There was code in dnf and dnf-automatic to support running them from the git tree. This was a developer-oriented hack that should not exist in production code. It assumed that when running an installed dnf, the `sys.path[0]` contains `/usr/bin`. If not, it overwrites the contents of `sys.path[0]`. This is a problem when running the Python interpreter with the `-P` parameter (meaning: Don't automatically prepend a potentially unsafe path to sys.path such as the current directory, the script's directory or an empty string.) The fix removes this developer-oriented hack. Developers should instead set PYTHONPATH in the environment. --- bin/dnf-automatic.in | 4 ---- bin/dnf.in | 5 ----- 2 files changed, 9 deletions(-) diff --git a/bin/dnf-automatic.in b/bin/dnf-automatic.in index 17e35a058e..1fb712b094 100755 --- a/bin/dnf-automatic.in +++ b/bin/dnf-automatic.in @@ -27,10 +27,6 @@ if here == '/usr/bin': # we never import Python modules from /usr/bin # removing this lowers the risk of accidental imports of weird files del sys.path[0] -else: - # git checkout - dnf_toplevel = os.path.dirname(here) - sys.path[0] = dnf_toplevel import dnf.automatic.main sys.exit(dnf.automatic.main.main(sys.argv[1:])) diff --git a/bin/dnf.in b/bin/dnf.in index 55ceb3f2de..10716dec72 100755 --- a/bin/dnf.in +++ b/bin/dnf.in @@ -52,11 +52,6 @@ if here == '/usr/bin': # we never import Python modules from /usr/bin # removing this lowers the risk of accidental imports of weird files del sys.path[0] -else: - # git checkout - import os - dnf_toplevel = os.path.dirname(here) - sys.path[0] = dnf_toplevel from dnf.cli import main main.user_main(sys.argv[1:], exit_code=True) From c9da8e617c26204fd2cfc5cbc8909aba1d44b04a Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Fri, 26 Apr 2024 13:26:57 +0200 Subject: [PATCH 2/2] Allow `%py3_shebang_fix` macro to add `-P` argument to shebang lines There was a bug in dnf and dnf-automatic that caused traceback when running the Python interpreter with the `-P` argument. Since the bug has been fixed, the `-P` argument can be used. --- dnf.spec | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dnf.spec b/dnf.spec index 8f0e2b4a03..b3b305296f 100644 --- a/dnf.spec +++ b/dnf.spec @@ -257,10 +257,6 @@ rm %{buildroot}%{_mandir}/man5/%{name}.conf.5* %endif %if 0%{?fedora} >= 41 || 0%{?rhel} >= 10 -# Don't add -P to Python shebangs -# The executable Python scripts import each other -%undefine _py3_shebang_P - %py3_shebang_fix %{buildroot}%{_bindir}/dnf-3 %py3_shebang_fix %{buildroot}%{_bindir}/dnf-automatic %py3_shebang_fix %{buildroot}%{python3_sitelib}/%{name}/cli/completion_helper.py