-
-
Notifications
You must be signed in to change notification settings - Fork 610
Labels
gazelleGazelle plugin related issuesGazelle plugin related issues
Description
🚀 feature request
Relevant Rules
gazelle
Description
Gazelle will automatically add a dep on :conftest
to py_test targets if the directory has a conftest.py
file.
rules_python/gazelle/python/generate.go
Lines 126 to 127 in 5c68ff9
} else if f == conftestFilename { | |
hasConftestFile = true |
rules_python/gazelle/python/generate.go
Lines 364 to 394 in 5c68ff9
var conftest *rule.Rule | |
if hasConftestFile { | |
deps, _, annotations, err := parser.parseSingle(conftestFilename) | |
if err != nil { | |
log.Fatalf("ERROR: %v\n", err) | |
} | |
// Check if a target with the same name we are generating already | |
// exists, and if it is of a different kind from the one we are | |
// generating. If so, we have to throw an error since Gazelle won't | |
// generate it correctly. | |
if err := ensureNoCollision(args.File, conftestTargetname, actualPyLibraryKind); err != nil { | |
fqTarget := label.New("", args.Rel, conftestTargetname) | |
err := fmt.Errorf("failed to generate target %q of kind %q: %w. ", | |
fqTarget.String(), actualPyLibraryKind, err) | |
collisionErrors.Add(err) | |
} | |
conftestTarget := newTargetBuilder(pyLibraryKind, conftestTargetname, pythonProjectRoot, args.Rel, pyFileNames). | |
addSrc(conftestFilename). | |
addModuleDependencies(deps). | |
addResolvedDependencies(annotations.includeDeps). | |
addVisibility(visibility). | |
setTestonly(). | |
generateImportsAttribute() | |
conftest = conftestTarget.build() | |
result.Gen = append(result.Gen, conftest) | |
result.Imports = append(result.Imports, conftest.PrivateAttr(config.GazelleImportsKey)) | |
} |
rules_python/gazelle/python/generate.go
Lines 468 to 470 in 5c68ff9
if conftest != nil { | |
pyTestTarget.addModuleDependency(Module{Name: strings.TrimSuffix(conftestFilename, ".py")}) | |
} |
If the file doesn't need conftest.py
, this can result in pulling in a large dep tree unnecessarily.
Describe the solution you'd like
Python annotation # gazelle:include_conftest false
.
- When
false
, force-exclude add the dep. - When
true
, force-add the dep. This is equivalent to the# gazelle:include_dep :conftest
directive. - Defaults to unset, which is the same as the current behavior
Describe alternatives you've considered
None.
Metadata
Metadata
Assignees
Labels
gazelleGazelle plugin related issuesGazelle plugin related issues