python / python/cpython

Incorrect handling of backslashes in RECORD file by importlib.metadata

Abierto
#149,137 7 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib topic-importlib type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug report

Bug description:

The class importlib.metadata.PackagePath does not correctly handle backslashes in the RECORD dist-info file.
According to the specs, backslashes are allowed:

The path may be either absolute, or relative to the directory containing the .dist-info directory (commonly, the site-packages directory). On Windows, directories may be separated either by forward- or backslashes (/ or \).

This leads to PackagePath.name wrongfully returning the entire path instead of just the filename.

Steps for Reprocution

As an example, take ruff 0.14.14 on Windows

RECORD file contents
..\..\Scripts\ruff.exe,sha256=HJzLwAeBnSdcuXo602XCKCTuDMMrn5dZPIEzmZ0w6QY,31781376
ruff-0.14.14.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
ruff-0.14.14.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
ruff-0.14.14.dist-info\METADATA,sha256=QD17c7tQSny5DBVcDewbxp32FVd0m05EfaH_AQvKuhQ,26651
ruff-0.14.14.dist-info\RECORD,,
ruff-0.14.14.dist-info\WHEEL,sha256=jsSEiVNsW1dJj5gDaReR40i7mhgBjWtms6nAD6EViXU,94
ruff-0.14.14.dist-info\licenses\LICENSE,sha256=JZfYVBIrd93HGXFWTKI1CjdghXXOMkrcVlCisgUcjxg,20731
ruff\__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
ruff\__main__.py,sha256=w1Ehfzzy8tMM7r7dFrKmi3DkmTZyV_xJ40K_sxoO6X0,2908
pip install "ruff==0.14.14"
import importlib.metadata
from pathlib import Path

for pkg in importlib.metadata.distributions():
    if pkg.name == "ruff":
        for file in pkg.files:
            print(file.name, Path(file).name)
Expected Output
ruff.exe ruff.exe
INSTALLER INSTALLER
REQUESTED REQUESTED
METADATA METADATA
RECORD RECORD
WHEEL WHEEL
LICENSE LICENSE
__init__.py __init__.py
__main__.py __main__.py
Actual Output
..\..\Scripts\ruff.exe ruff.exe
INSTALLER INSTALLER
REQUESTED REQUESTED
ruff-0.14.14.dist-info\METADATA METADATA
ruff-0.14.14.dist-info\RECORD RECORD
ruff-0.14.14.dist-info\WHEEL WHEEL
ruff-0.14.14.dist-info\licenses\LICENSE LICENSE
ruff\__init__.py __init__.py
ruff\__main__.py __main__.py
CPython versions tested on:

3.14

Operating systems tested on:

Windows

Linked PRs
  • gh-149540

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.

Línea de trabajo

Comienza con importlib.metadata.PackagePath y reproduce el caso de Windows utilizando el contenido de RECORD y el ejemplo del issue. Se considera terminado cuando PackagePath.name devuelve únicamente el nombre del archivo para las rutas separadas por barras invertidas, mientras que los casos mostrados con barras diagonales siguen produciendo los nombres esperados.

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

Evaluación

Stack tecnológico
python
Área
tooling
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.