-
-
Notifications
You must be signed in to change notification settings - Fork 631
gazelle: Add Gazelle directive # gazelle:python_ignore_target target #3197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,8 @@ const ( | |
// like "import a" can be resolved to sibling modules. When disabled, they | ||
// can only be resolved as an absolute import. | ||
PythonResolveSiblingImports = "python_resolve_sibling_imports" | ||
// PythonIgnoreTarget represents the directive that controls whether to ignore the specific target. | ||
PythonIgnoreTarget = "python_ignore_target" | ||
) | ||
|
||
// GenerationModeType represents one of the generation modes for the Python | ||
|
@@ -204,6 +206,7 @@ type Config struct { | |
generatePyiDeps bool | ||
generateProto bool | ||
resolveSiblingImports bool | ||
ignoredTargets map[string]struct{} | ||
} | ||
|
||
type LabelNormalizationType int | ||
|
@@ -244,6 +247,7 @@ func New( | |
generatePyiDeps: false, | ||
generateProto: false, | ||
resolveSiblingImports: false, | ||
ignoredTargets: make(map[string]struct{}), | ||
} | ||
} | ||
|
||
|
@@ -281,6 +285,7 @@ func (c *Config) NewChild() *Config { | |
generatePyiDeps: c.generatePyiDeps, | ||
generateProto: c.generateProto, | ||
resolveSiblingImports: c.resolveSiblingImports, | ||
ignoredTargets: make(map[string]struct{}), | ||
} | ||
} | ||
|
||
|
@@ -610,6 +615,17 @@ func (c *Config) ResolveSiblingImports() bool { | |
return c.resolveSiblingImports | ||
} | ||
|
||
// SetIgnoreTarget sets the target to be ignored. | ||
func (c *Config) AddIgnoreTarget(target string) { | ||
c.ignoredTargets[target] = struct{}{} | ||
} | ||
|
||
// IgnoreTarget returns whether the target should be ignored. | ||
func (c *Config) IgnoreTarget(target string) bool { | ||
_, ignores := c.ignoredTargets[target] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder... should we support wildcards/globbing/regex? And how about the # gazelle:python_ignore_target //$python_root$/foo/bar:*_foo
py_library(name = "bar_foo", ...) # ignored
py_library(name = "bar_bar", ...) # not ignored
py_library(name = "foo_foo", ...) # ignored Regex is probably too complex, especially if we want to support the |
||
return ignores | ||
} | ||
|
||
// FormatThirdPartyDependency returns a label to a third-party dependency performing all formating and normalization. | ||
func (c *Config) FormatThirdPartyDependency(repositoryName string, distributionName string) label.Label { | ||
conventionalDistributionName := strings.ReplaceAll(c.labelConvention, distributionNameLabelConventionSubstitution, distributionName) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this
IsIgnoredTarget
.