Skip to content

Commit d96e415

Browse files
committed
Make AppMap paths relative to starting directory
Record the current directory on startup, strip it from source file locations before adding them to an AppMap.
1 parent e54bc8b commit d96e415

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

appmap/_implementation/event.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import threading
77

8+
from .env import Env
89
from .utils import appmap_tls, split_function_name, fqname, FnType
910

1011
logger = logging.getLogger(__name__)
@@ -124,6 +125,8 @@ def make(fn, fntype):
124125

125126
try:
126127
path = inspect.getsourcefile(fn)
128+
if path.startswith(Env.current.root_dir):
129+
path = path[Env.current.root_dir_len:]
127130
except TypeError:
128131
path = '<builtin>'
129132

appmap/test/appmap_test_base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,11 @@ def normalize(dct):
6464
assert isinstance(elapsed, float)
6565
if 'git' in dct:
6666
self.normalize_git(dct.pop('git'))
67-
if 'location' in dct:
68-
path, line = dct['location'].split(':')
69-
path = os.path.basename(path)
70-
dct['location'] = ':'.join([path, line])
7167
if 'metadata' in dct:
7268
self.normalize_metadata(dct['metadata'])
7369
if 'object_id' in dct:
7470
object_id = dct.pop('object_id')
7571
assert isinstance(object_id, int)
76-
if 'path' in dct:
77-
dct['path'] = os.path.basename(dct['path'])
7872
if 'value' in dct:
7973
# This maps all object references to the same
8074
# location. We don't actually need to verify that the

appmap/test/data/expected.appmap.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{
2222
"name": "class_method",
2323
"type": "function",
24-
"location": "example_class.py:4",
24+
"location": "appmap/test/data/example_class.py:4",
2525
"static": true
2626
}
2727
]
@@ -33,13 +33,13 @@
3333
{
3434
"name": "static_method",
3535
"type": "function",
36-
"location": "example_class.py:18",
36+
"location": "appmap/test/data/example_class.py:18",
3737
"static": true
3838
},
3939
{
4040
"name": "test_exception",
4141
"type": "function",
42-
"location": "example_class.py:25",
42+
"location": "appmap/test/data/example_class.py:25",
4343
"static": false
4444
}
4545
]
@@ -51,7 +51,7 @@
5151
{
5252
"name": "instance_method",
5353
"type": "function",
54-
"location": "example_class.py:10",
54+
"location": "appmap/test/data/example_class.py:10",
5555
"static": false
5656
}
5757
]
@@ -63,7 +63,7 @@
6363
{
6464
"defined_class": "example_class.ExampleClass",
6565
"method_id": "static_method",
66-
"path": "example_class.py",
66+
"path": "appmap/test/data/example_class.py",
6767
"lineno": 18,
6868
"static": true,
6969
"parameters": [],
@@ -80,7 +80,7 @@
8080
{
8181
"defined_class": "example_class.ClassMethodMixin",
8282
"method_id": "class_method",
83-
"path": "example_class.py",
83+
"path": "appmap/test/data/example_class.py",
8484
"lineno": 4,
8585
"static": true,
8686
"receiver": {
@@ -103,7 +103,7 @@
103103
{
104104
"defined_class": "example_class.Super",
105105
"method_id": "instance_method",
106-
"path": "example_class.py",
106+
"path": "appmap/test/data/example_class.py",
107107
"lineno": 10,
108108
"static": false,
109109
"receiver": {
@@ -126,7 +126,7 @@
126126
{
127127
"defined_class": "example_class.ExampleClass",
128128
"method_id": "test_exception",
129-
"path": "example_class.py",
129+
"path": "appmap/test/data/example_class.py",
130130
"lineno": 25,
131131
"static": false,
132132
"receiver": {

0 commit comments

Comments
 (0)