Python extractor: use relative paths in diagnostic locations#21847
Open
redsun82 wants to merge 2 commits into
Open
Python extractor: use relative paths in diagnostic locations#21847redsun82 wants to merge 2 commits into
redsun82 wants to merge 2 commits into
Conversation
Diagnostic `Location.file` fields contained absolute filesystem paths, causing the GitHub UI to generate broken file links with runner paths like `/home/runner/work/...`. Now paths are relativized against the source root (`LGTM_SRC` or cwd), falling back to absolute if the file is outside the source root. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the Python extractor’s diagnostic emission to prefer repo-relative paths in SARIF locations/messages so GitHub UI links resolve correctly instead of pointing at absolute runner paths.
Changes:
- Added
_get_source_root()/_relative_path()helpers to relativize diagnostic file paths againstLGTM_SRC(fallbackos.getcwd()). - Updated
syntax_error_message,recursion_error_message, andinternal_error_messageto use repo-relative paths forLocation.file(and markdown text for syntax errors). - Updated CLI integration test expectations to match relative paths.
Show a summary per file
| File | Description |
|---|---|
| python/extractor/semmle/logging.py | Introduces path-relativization helper and applies it to diagnostic locations/messages. |
| python/extractor/cli-integration-test/writing-diagnostics/diagnostics.expected | Adjusts expected diagnostics output to use repo-relative paths. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 9
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When CodeQL reports parsing errors, the GitHub UI generates file links with absolute runner paths (
/home/runner/work/...) instead of repo-relative paths. This happens because diagnostic SARIF entries in the Python extractor contain absolute filesystem paths inLocation.file.The fix adds a
_relative_path()helper insemmle/logging.pythat relativizes paths against the source root (LGTM_SRCenv var, oros.getcwd()as fallback). Paths outside the source root (e.g. library files) are left absolute to avoid confusing../..relative paths.All three diagnostic emission functions (
syntax_error_message,recursion_error_message,internal_error_message) now use this helper for theirLocation.fileand markdown message text.Partially addresses #21802 (Python portion; tree-sitter languages handled separately).