Skip to content

Commit cdf413c

Browse files
committed
Use addModuleToTreeSet
1 parent b528dd8 commit cdf413c

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

gazelle/python/target.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ type targetBuilder struct {
3232
srcs *treeset.Set
3333
siblingSrcs *treeset.Set
3434
deps *treeset.Set
35-
pyiDeps *treeset.Set
3635
resolvedDeps *treeset.Set
3736
visibility *treeset.Set
3837
main *string
@@ -50,7 +49,6 @@ func newTargetBuilder(kind, name, pythonProjectRoot, bzlPackage string, siblingS
5049
srcs: treeset.NewWith(godsutils.StringComparator),
5150
siblingSrcs: siblingSrcs,
5251
deps: treeset.NewWith(moduleComparator),
53-
pyiDeps: treeset.NewWith(moduleComparator),
5452
resolvedDeps: treeset.NewWith(godsutils.StringComparator),
5553
visibility: treeset.NewWith(godsutils.StringComparator),
5654
}
@@ -83,12 +81,7 @@ func (t *targetBuilder) addModuleDependency(dep Module) *targetBuilder {
8381
dep.Name = importSpecFromSrc(t.pythonProjectRoot, t.bzlPackage, fileName).Imp
8482
}
8583

86-
// Add to appropriate dependency set based on whether it's type-checking only
87-
if dep.TypeCheckingOnly {
88-
t.pyiDeps.Add(dep)
89-
} else {
90-
t.deps.Add(dep)
91-
}
84+
addModuleToTreeSet(t.deps, dep)
9285
return t
9386
}
9487

@@ -171,24 +164,12 @@ func (t *targetBuilder) build() *rule.Rule {
171164
if t.imports != nil {
172165
r.SetAttr("imports", t.imports)
173166
}
174-
if combinedDeps := t.combinedDeps(); !combinedDeps.Empty() {
175-
r.SetPrivateAttr(config.GazelleImportsKey, combinedDeps)
167+
if !t.deps.Empty() {
168+
r.SetPrivateAttr(config.GazelleImportsKey, t.deps)
176169
}
177170
if t.testonly {
178171
r.SetAttr("testonly", true)
179172
}
180173
r.SetPrivateAttr(resolvedDepsKey, t.resolvedDeps)
181174
return r
182175
}
183-
184-
// Combine both regular and type-checking imports into a single set
185-
// for passing to the resolver. The resolver will distinguish them
186-
// based on the TypeCheckingOnly field.
187-
func (t *targetBuilder) combinedDeps() *treeset.Set {
188-
combinedDeps := treeset.NewWith(moduleComparator)
189-
// If an import is in both pyi_deps and deps, the one in deps will override the one in pyi_deps, resulting
190-
// in the resolver properly adding to deps instead of pyi_deps.
191-
combinedDeps.Add(t.pyiDeps.Values()...)
192-
combinedDeps.Add(t.deps.Values()...)
193-
return combinedDeps
194-
}

0 commit comments

Comments
 (0)