profiling.sampling reports third-party modules as stdlib when site-packages is inside the stdlib directory
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 72/100
Rechercherichtung
Lies Lib/profiling/sampling/module_utils.py, insbesondere extract_module_name() und die Pfadinformationen von get_python_path_info(). Reproduziere den gemeldeten Fall mit sysconfig.get_path('purelib') und dem bereitgestellten Snippet und suche anschließend nach vorhandenen Tests für Profiling-Sampling. Das Ziel ist erreicht, wenn das spezifischste passende Verzeichnis gewinnt, die Standardbibliothek bei Gleichstand gewinnt und das Beispiel requests.api als site-packages klassifiziert, ohne Dateien der Standardbibliothek falsch zu klassifizieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Bug report
Bug description:
profiling.sampling.module_utils.extract_module_name() checks the stdlib directory before the site-packages directories. In a regular (non-venv) installation site-packages is a subdirectory of the stdlib directory (Lib\site-packages on Windows, lib/pythonX.Y/site-packages for python.org, pyenv, conda or Docker builds, and Lib/site-packages in a source build), so every file installed there matches the stdlib check first.
import os
import sysconfig
from profiling.sampling.module_utils import extract_module_name, get_python_path_info
path_info = get_python_path_info()
filename = os.path.join(sysconfig.get_path('purelib'), 'requests', 'api.py')
print(extract_module_name(filename, path_info))
Output (Windows, <prefix>\Lib is the stdlib directory and <prefix>\Lib\site-packages is the site-packages directory):
('site-packages.requests.api', 'stdlib')
Expected:
('requests.api', 'site-packages')
As a result, the heatmap index lists third-party code under "Standard Library", inside a folder named site-packages, instead of under "Site Packages", and the flamegraph labels of such frames look like get (site-packages.requests.api:10). Doc/library/profiling.sampling.rst describes the heatmap index as organized by type (stdlib, site-packages, project). Only virtual environments (and the user site directory), where site-packages is not inside the stdlib directory, are classified correctly.
Simply checking site-packages first is not enough: on Windows site.getsitepackages() also returns sys.prefix, which is a parent of the stdlib directory and would then capture the stdlib files. The most specific (longest) matching directory should win, with stdlib winning a tie.
CPython versions tested on:
CPython main branch
(Lib/profiling/sampling/module_utils.py is identical on the 3.15 branch.)
Operating systems tested on:
Windows
Linked PRs
- gh-158993
- Vorherrschende Sprache
- Python
- Sterne
- 77.6k
- Forks
- 37.6k
- Ø Merge
- 1 T. 20 Std.
- Gemergte PRs (30 T.)
- 593
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/cpython
-
docs
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 1 Tag
-
docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
python/cpython#159061 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
3.14 3.15 3.16 stdlib type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
python/cpython#159044 · 7 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
A minor problem with the section "6.10.2. Membership test operations" from the language reference.Offendocs pending
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
python/cpython#159034 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Docs: socket.htons() and friends raise ValueError for negative input since 3.14Evtl. vergeben @vetrovk hat das vor 1 Tag übernommen. Offendocs
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 78/100
python/cpython#159012 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
aicell-lab/bioengine#232 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
modelscope/evalscope#1836 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
jbaruch/speaker-toolkit#480 ·
Maintainer antworten meist innerhalb von 1 Tag