Skip to content

Commit 11ed07a

Browse files
authored
chore: relax suffix cond site-packages search for modules (#15123)
This came up reviewing some Exception Replay snapshots where the paths took the form: > /usr/local/runfiles/pypi_linux_x86_64_parsimonious/site-packages/parsimonious/expressions.py Rather than add another case for this, we can remove the suffix check since we're looping over `path.parents` anyways. This should improve the third-party detection for more unconvential build environments beyond bazel.
1 parent a139e88 commit 11ed07a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

ddtrace/internal/packages.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ def _root_module(path: Path) -> str:
142142
pass
143143

144144
# Bazel runfiles support: we assume that these paths look like
145-
# /some/path.runfiles/.../site-packages/<root_module>/...
146-
if any(p.suffix == ".runfiles" for p in path.parents):
147-
for s in path.parents:
148-
if s.parent.name == "site-packages":
149-
return s.name
145+
# /some/path.runfiles/<distribution_name>/site-packages/<root_module>/...
146+
# /usr/local/runfiles/<distribution_name>/site-packages/<root_module>/...
147+
for s in path.parents:
148+
if s.parent.name == "site-packages":
149+
return s.name
150150

151151
msg = f"Could not find root module for path {path}"
152152
raise ValueError(msg)

tests/internal/test_packages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_third_party_packages_symlinks(tmp_path):
129129
symlink_file = runfiles_path / "test.py"
130130
os.symlink(code_file, symlink_file)
131131

132-
assert is_user_code(code_file)
132+
assert not is_user_code(code_file)
133133
# Symlinks with `.runfiles` in the path should not be considered user code.
134134
from ddtrace.internal.compat import Path
135135

0 commit comments

Comments
 (0)