Add support for replace directive in go.mod files#4673
Open
uttam282005 wants to merge 11 commits intoaboutcode-org:developfrom
Open
Add support for replace directive in go.mod files#4673uttam282005 wants to merge 11 commits intoaboutcode-org:developfrom
replace directive in go.mod files#4673uttam282005 wants to merge 11 commits intoaboutcode-org:developfrom
Conversation
dc7c152 to
0b389bf
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds support for parsing replace directives in Go module files (go.mod), enabling ScanCode to properly handle both local path and remote package replacements commonly used in Go projects.
Changes:
- Added parsing logic for
replacedirectives in both inline and block-style formats - Implemented resolution of local replacement paths to extract package metadata from target go.mod files
- Enhanced package data model to track local replacements and their resolved dependencies
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/packagedcode/go_mod.py | Added replace directive parsing functions, regex patterns, and local_replacements tracking in GoModule class |
| src/packagedcode/golang.py | Added resolve_local_replacements method to resolve local paths and integrate resolved dependencies into package data |
| tests/packagedcode/test_golang.py | Added two new test cases for milvus and gopls projects with replace directives |
| tests/packagedcode/data/golang/gomod/milvus/go.mod | New test fixture with mixed local and remote replace directives |
| tests/packagedcode/data/golang/gomod/milvus/output.expected.json | Expected parsing output for milvus test |
| tests/packagedcode/data/golang/gomod/gopls/go.mod | New test fixture with local replace directive |
| tests/packagedcode/data/golang/gomod/gopls/output.expected.json | Expected parsing output for gopls test |
| tests/packagedcode/data/golang/gomod/opencensus-service/output.expected.json | Updated expected output to include replace directive results |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
4da4fd1 to
d6a0252
Compare
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.
Fixes #3492
go_mod.py)handle_replace_directive()function to parse and categorize replacements:excludelist (as it's being replaced)requirelist (remote) orlocal_replacements(local)golang.py)resolve_local_replacements()method that:../pkg/) to absolute pathsgo.modfile3. Assembly Integration
Modified
BaseGoModuleHandler.assemble()to:This PR is inspired by the work done by @shravankshenoy and maintainer reviews on PR #3693.
Tasks
Run tests locally to check for errors.