Skip to content

Commit f7969dd

Browse files
committed
update
1 parent f2fb7b0 commit f7969dd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

gazelle/python/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
133133
}
134134
}
135135
// filter out targets that are ignored
136-
otherFileRules := make([]*rule.Rule, 0)
136+
var otherFileRules []*rule.Rule
137137
if args.File != nil {
138138
for _, target := range args.File.Rules {
139139
if cfg.IgnoreTarget(target.Name()) {

gazelle/pythonconfig/pythonconfig.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ const (
112112
// like "import a" can be resolved to sibling modules. When disabled, they
113113
// can only be resolved as an absolute import.
114114
PythonResolveSiblingImports = "python_resolve_sibling_imports"
115+
// PythonIgnoreTarget represents the directive that controls whether to ignore the specific target.
116+
PythonIgnoreTarget = "python_ignore_target"
115117
)
116118

117119
// GenerationModeType represents one of the generation modes for the Python
@@ -204,6 +206,7 @@ type Config struct {
204206
generatePyiDeps bool
205207
generateProto bool
206208
resolveSiblingImports bool
209+
ignoredTargets map[string]struct{}
207210
}
208211

209212
type LabelNormalizationType int
@@ -244,6 +247,7 @@ func New(
244247
generatePyiDeps: false,
245248
generateProto: false,
246249
resolveSiblingImports: false,
250+
ignoredTargets: make(map[string]struct{}),
247251
}
248252
}
249253

@@ -281,6 +285,7 @@ func (c *Config) NewChild() *Config {
281285
generatePyiDeps: c.generatePyiDeps,
282286
generateProto: c.generateProto,
283287
resolveSiblingImports: c.resolveSiblingImports,
288+
ignoredTargets: make(map[string]struct{}),
284289
}
285290
}
286291

@@ -610,6 +615,17 @@ func (c *Config) ResolveSiblingImports() bool {
610615
return c.resolveSiblingImports
611616
}
612617

618+
// SetIgnoreTarget sets the target to be ignored.
619+
func (c *Config) AddIgnoreTarget(target string) {
620+
c.ignoredTargets[target] = struct{}{}
621+
}
622+
623+
// IgnoreTarget returns whether the target should be ignored.
624+
func (c *Config) IgnoreTarget(target string) bool {
625+
_, ignores := c.ignoredTargets[target]
626+
return ignores
627+
}
628+
613629
// FormatThirdPartyDependency returns a label to a third-party dependency performing all formating and normalization.
614630
func (c *Config) FormatThirdPartyDependency(repositoryName string, distributionName string) label.Label {
615631
conventionalDistributionName := strings.ReplaceAll(c.labelConvention, distributionNameLabelConventionSubstitution, distributionName)

0 commit comments

Comments
 (0)