Skip to content

Commit 899eb2e

Browse files
rustyconoverclaude
andcommitted
storage profile: normalise paths so attribution works on Windows
A code object's filename can differ from the package directory in drive letter case or separators on Windows, so every frame missed the vgi checks and no RPC was attributed (the Windows CI lanes counted 0 of 147). Compare normcase'd paths, and always display call sites with '/'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzrG3FzSh28NiZ8UnVtRbk
1 parent 067e931 commit 899eb2e

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

‎vgi/_storage_profile.py‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@
9696
_MAX_SCOPES = 2_000
9797
_MAX_RPCS = 200_000
9898

99-
_VGI_DIR = os.path.dirname(os.path.abspath(__file__))
99+
# normcase: on Windows a code object's filename can differ from these in drive
100+
# letter case or separators, and every comparison below must still match.
101+
_VGI_DIR = os.path.normcase(os.path.dirname(os.path.abspath(__file__)))
100102
_VGI_PARENT = os.path.dirname(_VGI_DIR)
101103
_STORAGE_MODULES = frozenset(
102104
{
@@ -113,7 +115,7 @@
113115
# ---------------------------------------------------------------------------
114116

115117

116-
_STDLIB_DIR = os.path.dirname(os.path.abspath(os.__file__))
118+
_STDLIB_DIR = os.path.normcase(os.path.dirname(os.path.abspath(os.__file__)))
117119

118120
# _classify kinds.
119121
_K_STORAGE = 0 # a storage module: skipped when choosing the call site
@@ -125,16 +127,25 @@
125127

126128
@functools.lru_cache(maxsize=4096)
127129
def _classify(filename: str) -> tuple[str, int]:
128-
"""Return ``(display_path, kind)`` for a code object's filename."""
129-
path = os.path.abspath(filename)
130+
"""Return ``(display_path, kind)`` for a code object's filename.
131+
132+
The display path always uses ``/`` so reports read the same on every OS.
133+
"""
134+
display, kind = _classify_native(filename)
135+
return display.replace(os.sep, "/"), kind
136+
137+
138+
def _classify_native(filename: str) -> tuple[str, int]:
139+
"""`_classify` with the platform's separators."""
140+
path = os.path.normcase(os.path.abspath(filename))
130141
if path.startswith(_VGI_DIR + os.sep):
131142
rel = os.path.relpath(path, _VGI_PARENT)
132143
base = os.path.basename(path)
133144
if os.path.dirname(path) == _VGI_DIR and base in _STORAGE_MODULES:
134145
return rel, _K_STORAGE
135-
if rel.startswith(os.path.join("vgi", "_test_fixtures") + os.sep):
146+
if rel.startswith(os.path.normcase(os.path.join("vgi", "_test_fixtures")) + os.sep):
136147
return rel, _K_USER
137-
return rel, _K_WORKER if rel == os.path.join("vgi", "worker.py") else _K_VGI
148+
return rel, _K_WORKER if rel == os.path.normcase(os.path.join("vgi", "worker.py")) else _K_VGI
138149
parts = path.split(os.sep)
139150
for marker in ("site-packages", "dist-packages"):
140151
if marker in parts:

0 commit comments

Comments
 (0)