-
-
Notifications
You must be signed in to change notification settings - Fork 650
feat(gazelle): Add ancestor conftest.py files #3498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thejcannon
wants to merge
3
commits into
bazel-contrib:main
Choose a base branch
from
thejcannon:jcannon/ancestor-conftest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+31
−8
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,24 @@ func matchesAnyGlob(s string, globs []string) bool { | |
| return false | ||
| } | ||
|
|
||
| // findConftestPaths returns package paths containing conftest.py, from currentPkg | ||
| // up through ancestors, stopping at pythonProjectRoot (or repo root if empty). | ||
| func findConftestPaths(repoRoot, currentPkg, pythonProjectRoot string) []string { | ||
| var result []string | ||
| for pkg := currentPkg; ; pkg = filepath.Dir(pkg) { | ||
| if pkg == "." { | ||
| pkg = "" | ||
| } | ||
| if _, err := os.Stat(filepath.Join(repoRoot, pkg, conftestFilename)); err == nil { | ||
| result = append(result, pkg) | ||
| } | ||
| if pkg == "" || pkg == pythonProjectRoot { | ||
| break | ||
| } | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| // GenerateRules extracts build metadata from source files in a directory. | ||
| // GenerateRules is called in each directory where an update is requested | ||
| // in depth-first post-order. | ||
|
|
@@ -481,14 +499,15 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes | |
| } | ||
|
|
||
| for _, pyTestTarget := range pyTestTargets { | ||
| if conftest != nil { | ||
| conftestModule := Module{Name: importSpecFromSrc(pythonProjectRoot, args.Rel, conftestFilename).Imp} | ||
| if pyTestTarget.annotations.includePytestConftest == nil { | ||
| // unset; default behavior | ||
| pyTestTarget.addModuleDependency(conftestModule) | ||
| } else if *pyTestTarget.annotations.includePytestConftest { | ||
| // set; add if true, do not add if false | ||
| pyTestTarget.addModuleDependency(conftestModule) | ||
| shouldAddConftest := pyTestTarget.annotations.includePytestConftest == nil || | ||
| *pyTestTarget.annotations.includePytestConftest | ||
|
|
||
| if shouldAddConftest { | ||
| for _, conftestPkg := range findConftestPaths(args.Config.RepoRoot, args.Rel, pythonProjectRoot) { | ||
| conftestModule := Module{ | ||
| Name: importSpecFromSrc(pythonProjectRoot, conftestPkg, conftestFilename).Imp, | ||
| } | ||
| pyTestTarget.deps.Add(conftestModule) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why you changed from |
||
| } | ||
| } | ||
| pyTest := pyTestTarget.build() | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,5 +23,6 @@ py_test( | |
| deps = [ | ||
| ":bar", | ||
| ":conftest", | ||
| "//:conftest", | ||
| ], | ||
| ) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N.B.: There are valid cases where there exists one or more conftest.py files that are above
pythonProjectRoot:I think we should ignore the
pythonProjectRootand only stop at the Bazel module root when searching.