Skip to content

Annotation: include/ignore conftest #3076

@dougthor42

Description

@dougthor42

🚀 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.

} else if f == conftestFilename {
hasConftestFile = true

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))
}

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 issues

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions