CWD is not in sys.path when "-P" is used

Abierto
#15,214 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
python
Área
cli

Línea de trabajo

Comienza con la función init_path y el cambio vinculado; después, reproduce la invocación de IPython al estilo de Fedora /usr/bin/python3 -P mientras inspeccionas sys.path. Compara el comportamiento entre los modos de ejecución de Python documentados y actualiza la implementación o el docstring para que el manejo de CWD coincida con el modo real; se considera terminado cuando la inconsistencia reportada esté resuelta y verificada.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

I've got a report from a user after the fresh release of Fedora 44, where IPython 9.9 is included. You can read it here, but I'll sum it up below as well: https://bugzilla.redhat.com/show_bug.cgi?id=2479711

Since IPython 9.7.0, CWD is not in sys.path when you use a system-installed IPython from RPM packages.

The problem is caused by this change: https://github.com/ipython/ipython/commit/bb8b2bab0f68088b15a4da0cd7ec6e6bfcafd6c9

and the fact that "-P" flag is by default in all Python shebangs for all executable files in Fedora. For IPython, /usr/bin/ipython looks like:

#! /usr/bin/python3 -P
import sys
from IPython import start_ipython
if __name__ == '__main__':
    if sys.argv[0].endswith('.exe'):
        sys.argv[0] = sys.argv[0][:-4]
    sys.exit(start_ipython())

The commit linked above mentions this:

sys.flags.safe_path is python's equivalent to of the ipython flag
ignore_cwd. It is most often set by PYTHONSAFEPATH or by running
python with -P.

which is not entirely true because what is omitted from sys.path when you use "-P" depends on how the python/script/module is run, see: https://docs.python.org/3/using/cmdline.html#cmdoption-P

We've implemented the default "-P" option in this Fedora change because we wanted to avoid /usr/bin to be in the sys.path which caused strange behavior sometimes.

So now, with "-P" in the shebang, we don't have CWD in sys.path but when we remove the flag, we do have /usr/bin/ there, which we want to avoid.

Because the commit message and the docstring of the init_path function are not entirely correct, I consider this to be a bug in IPython. Whether CWD should be omitted or not depends on how the Python is executed, not just on the "-P" flag or the corresponding env variable.

Lenguaje dominante
Python
Estrellas
16.8k
Forks
4.5k
Merge medio
1 d 2 h
PR fusionados (30 d)
6

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ipython/ipython

Todos los issues de ipython/ipython

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.