Skip to content

Commit b1e98bf

Browse files
committed
Only add conftest dep when includePytestConftest is nil or true
Also pass annotations around on all generated rules
1 parent 94a6ade commit b1e98bf

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

gazelle/python/generate.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
260260
addSrc(filename).
261261
addModuleDependencies(mainModules[filename]).
262262
addResolvedDependencies(annotations.includeDeps).
263-
generateImportsAttribute().build()
263+
generateImportsAttribute().
264+
setAnnotations(*annotations).
265+
build()
264266
result.Gen = append(result.Gen, pyBinary)
265267
result.Imports = append(result.Imports, pyBinary.PrivateAttr(config.GazelleImportsKey))
266268
}
@@ -301,6 +303,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
301303
addModuleDependencies(allDeps).
302304
addResolvedDependencies(annotations.includeDeps).
303305
generateImportsAttribute().
306+
setAnnotations(*annotations).
304307
build()
305308

306309
if pyLibrary.IsEmpty(py.Kinds()[pyLibrary.Kind()]) {
@@ -353,6 +356,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
353356
addSrc(pyBinaryEntrypointFilename).
354357
addModuleDependencies(deps).
355358
addResolvedDependencies(annotations.includeDeps).
359+
setAnnotations(*annotations).
356360
generateImportsAttribute()
357361

358362
pyBinary := pyBinaryTarget.build()
@@ -383,6 +387,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
383387
addSrc(conftestFilename).
384388
addModuleDependencies(deps).
385389
addResolvedDependencies(annotations.includeDeps).
390+
setAnnotations(*annotations).
386391
addVisibility(visibility).
387392
setTestonly().
388393
generateImportsAttribute()
@@ -414,6 +419,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
414419
addSrcs(srcs).
415420
addModuleDependencies(deps).
416421
addResolvedDependencies(annotations.includeDeps).
422+
setAnnotations(*annotations).
417423
generateImportsAttribute()
418424
}
419425
if (!cfg.PerPackageGenerationRequireTestEntryPoint() || hasPyTestEntryPointFile || hasPyTestEntryPointTarget || cfg.CoarseGrainedGeneration()) && !cfg.PerFileGeneration() {
@@ -466,7 +472,14 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
466472

467473
for _, pyTestTarget := range pyTestTargets {
468474
if conftest != nil {
469-
pyTestTarget.addModuleDependency(Module{Name: strings.TrimSuffix(conftestFilename, ".py")})
475+
conftestModule := Module{Name: strings.TrimSuffix(conftestFilename, ".py")}
476+
if pyTestTarget.annotations.includePytestConftest == nil {
477+
// unset; default behavior
478+
pyTestTarget.addModuleDependency(conftestModule)
479+
} else if *pyTestTarget.annotations.includePytestConftest {
480+
// set; add if true, do not add if false
481+
pyTestTarget.addModuleDependency(conftestModule)
482+
}
470483
}
471484
pyTest := pyTestTarget.build()
472485

0 commit comments

Comments
 (0)