Skip to content

Commit a895540

Browse files
authored
fix(tracer): emit relative paths (#5)
1 parent 7755f61 commit a895540

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/trace.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ def _register_builtin_types(self) -> None:
6464

6565
# -------------------------------------------------------------------- paths
6666
def _register_path(self, path: str) -> int:
67+
"""Register a source file path and emit a ``Path`` event."""
68+
69+
if path:
70+
abs_path = os.path.abspath(path)
71+
try:
72+
path = os.path.relpath(abs_path, self.program_dir)
73+
except ValueError:
74+
path = abs_path
75+
6776
if path not in self.path_map:
6877
self.path_map[path] = len(self.paths)
6978
self.paths.append(path)

tests/fixtures/array_sum.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
}
6262
},
6363
{
64-
"Path": "/workspace/codetracer-python-recorder/tests/programs/array_sum.py"
64+
"Path": "array_sum.py"
6565
},
6666
{
6767
"Function": {

tests/fixtures/calc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
}
6262
},
6363
{
64-
"Path": "/workspace/codetracer-python-recorder/tests/programs/calc.py"
64+
"Path": "calc.py"
6565
},
6666
{
6767
"Function": {

0 commit comments

Comments
 (0)