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.
This commit is contained in:
Jaroslav Rohel 2024-04-26 12:03:03 +02:00 committed by Petr Pisar
parent 5c050ba232
commit c8dbe6ea40
2 changed files with 0 additions and 9 deletions

View File

@ -27,10 +27,6 @@ if here == '/usr/bin':
# we never import Python modules from /usr/bin # we never import Python modules from /usr/bin
# removing this lowers the risk of accidental imports of weird files # removing this lowers the risk of accidental imports of weird files
del sys.path[0] del sys.path[0]
else:
# git checkout
dnf_toplevel = os.path.dirname(here)
sys.path[0] = dnf_toplevel
import dnf.automatic.main import dnf.automatic.main
sys.exit(dnf.automatic.main.main(sys.argv[1:])) sys.exit(dnf.automatic.main.main(sys.argv[1:]))

View File

@ -52,11 +52,6 @@ if here == '/usr/bin':
# we never import Python modules from /usr/bin # we never import Python modules from /usr/bin
# removing this lowers the risk of accidental imports of weird files # removing this lowers the risk of accidental imports of weird files
del sys.path[0] 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 from dnf.cli import main
main.user_main(sys.argv[1:], exit_code=True) main.user_main(sys.argv[1:], exit_code=True)