|
96 | 96 | _MAX_SCOPES = 2_000 |
97 | 97 | _MAX_RPCS = 200_000 |
98 | 98 |
|
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__))) |
100 | 102 | _VGI_PARENT = os.path.dirname(_VGI_DIR) |
101 | 103 | _STORAGE_MODULES = frozenset( |
102 | 104 | { |
|
113 | 115 | # --------------------------------------------------------------------------- |
114 | 116 |
|
115 | 117 |
|
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__))) |
117 | 119 |
|
118 | 120 | # _classify kinds. |
119 | 121 | _K_STORAGE = 0 # a storage module: skipped when choosing the call site |
|
125 | 127 |
|
126 | 128 | @functools.lru_cache(maxsize=4096) |
127 | 129 | 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)) |
130 | 141 | if path.startswith(_VGI_DIR + os.sep): |
131 | 142 | rel = os.path.relpath(path, _VGI_PARENT) |
132 | 143 | base = os.path.basename(path) |
133 | 144 | if os.path.dirname(path) == _VGI_DIR and base in _STORAGE_MODULES: |
134 | 145 | 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): |
136 | 147 | 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 |
138 | 149 | parts = path.split(os.sep) |
139 | 150 | for marker in ("site-packages", "dist-packages"): |
140 | 151 | if marker in parts: |
|
0 commit comments