Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

profiling.sampling reports third-party modules as stdlib when site-packages is inside the stdlib directory

Đang mở Phù hợp với người mới
#158,986 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

Đọc Lib/profiling/sampling/module_utils.py, đặc biệt là extract_module_name() và thông tin đường dẫn từ get_python_path_info(). Tái hiện trường hợp được báo cáo bằng sysconfig.get_path('purelib') và đoạn mã được cung cấp, sau đó kiểm tra các bài kiểm thử profiling sampling hiện có. Công việc hoàn tất khi thư mục khớp cụ thể nhất được ưu tiên, thư viện chuẩn được ưu tiên khi hòa và ví dụ phân loại requests.api là site-packages mà không phân loại sai các tệp thư viện chuẩn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

stdlib topic-profiling type-bug

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
Ngôn ngữ chính
Python
Star
77.6k
Fork
37.6k
Merge trung bình
1 ngày 20 giờ
Pull request đã merge (30 ngày)
593

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.