profiling.sampling reports third-party modules as stdlib when site-packages is inside the stdlib directory
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
阅读 Lib/profiling/sampling/module_utils.py,尤其是 extract_module_name() 和 get_python_path_info() 提供的路径信息。使用 sysconfig.get_path('purelib') 和给定的代码片段重现报告中的情况,然后检查现有的 profiling sampling 测试。完成标准是:最具体的匹配目录优先;出现平局时标准库优先;示例将 requests.api 分类为 site-packages,且不会误分类标准库文件。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Python
- 星标
- 77.6k
- 派生
- 37.6k
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 573
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
stdlib type-bug
难度 2/5 1-3 小时 新手友好度 68/100
python/cpython#159044 · 4 条评论 ·
维护者通常 1 天内回复
-
A minor problem with the section "6.10.2. Membership test operations" from the language reference.未关闭docs
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Docs: socket.htons() and friends raise ValueError for negative input since 3.14可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭docs
难度 1/5 1-3 小时 新手友好度 78/100
python/cpython#159012 · 1 条评论 ·
维护者通常 1 天内回复
-
stdlib type-bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
lazy import of `_sysconfig` in `Lib/ctypes/__init__.py` is eager on android and cygwin可能已有人在做 @sillyfellow21 于 5 天前认领。 未关闭tests topic-lazy-imports
难度 2/5 1-3 小时 新手友好度 74/100
python/cpython#158684 · 4 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
MystenLabs/MemWal#1163 · 2 条评论 ·
维护者通常 1 天内回复
-
infertopics leaves new nodes without a topic when untopiced neighbours outnumber topiced ones可能已有人在做 @moneebullah25 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
ClanGenOfficial/clangen#6254 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
FinanceFlash/unvibecode#218 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复