Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 717
fix(gazelle): __init__.py in per-file targets#1582
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7da8e28
fix(gazelle): __init__.py in per-file targets
98bd160
Merge remote-tracking branch 'origin/main' into siddharthab/main
3706aa3
Restore package target name as __init__
87d0000
Guard behind a directive
9a32be8
Merge remote-tracking branch 'origin/main' into siddharthab/main
91455ad
Mention directive in README
2a3adbd
Merge remote-tracking branch 'origin/main' into siddharthab/main
ee3818a
Add to changelog
ea5663e
Update CHANGELOG.md
aignas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| load("@rules_python//python:defs.bzl", "py_library") | ||
| # gazelle:python_generation_mode file | ||
| # gazelle:python_generation_mode_per_file_include_init true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # gazelle:python_generation_mode_per_file_include_init true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,28 @@ | ||
| load("@rules_python//python:defs.bzl", "py_library", "py_test") | ||
| # gazelle:python_generation_mode_per_file_include_init true | ||
| py_library( | ||
siddharthab marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| name = "__init__", | ||
| srcs = ["__init__.py"], | ||
| visibility = ["//:__subpackages__"], | ||
| ) | ||
| py_library( | ||
| name = "bar", | ||
| srcs = [ | ||
| "__init__.py", | ||
| "bar.py", | ||
| ], | ||
| visibility = ["//:__subpackages__"], | ||
| ) | ||
| py_library( | ||
| name = "foo", | ||
| srcs = ["foo.py"], | ||
| srcs = [ | ||
| "__init__.py", | ||
| "foo.py", | ||
| ], | ||
| visibility = ["//:__subpackages__"], | ||
| ) | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -50,6 +50,10 @@ const ( | ||
| // GenerationMode represents the directive that controls the target generation | ||
| // mode. See below for the GenerationModeType constants. | ||
| GenerationMode = "python_generation_mode" | ||
| // GenerationModePerFileIncludeInit represents the directive that augments | ||
| // the "per_file" GenerationMode by including the package's __init__.py file. | ||
| // This is a boolean directive. | ||
| GenerationModePerFileIncludeInit = "python_generation_mode_per_file_include_init" | ||
siddharthab marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // LibraryNamingConvention represents the directive that controls the | ||
| // py_library naming convention. It interpolates $package_name$ with the | ||
| // Bazel package name. E.g. if the Bazel package name is `foo`, setting this | ||
| @@ -122,15 +126,16 @@ type Config struct { | ||
| pythonProjectRoot string | ||
| gazelleManifest *manifest.Manifest | ||
| excludedPatterns *singlylinkedlist.List | ||
| ignoreFiles map[string]struct{} | ||
| ignoreDependencies map[string]struct{} | ||
| validateImportStatements bool | ||
| coarseGrainedGeneration bool | ||
| perFileGeneration bool | ||
| libraryNamingConvention string | ||
| binaryNamingConvention string | ||
| testNamingConvention string | ||
| excludedPatterns *singlylinkedlist.List | ||
| ignoreFiles map[string]struct{} | ||
| ignoreDependencies map[string]struct{} | ||
| validateImportStatements bool | ||
| coarseGrainedGeneration bool | ||
| perFileGeneration bool | ||
| perFileGenerationIncludeInit bool | ||
| libraryNamingConvention string | ||
| binaryNamingConvention string | ||
| testNamingConvention string | ||
| } | ||
| // New creates a new Config. | ||
| @@ -139,18 +144,19 @@ func New( | ||
| pythonProjectRoot string, | ||
| ) *Config { | ||
| return &Config{ | ||
| extensionEnabled: true, | ||
| repoRoot: repoRoot, | ||
| pythonProjectRoot: pythonProjectRoot, | ||
| excludedPatterns: singlylinkedlist.New(), | ||
| ignoreFiles: make(map[string]struct{}), | ||
| ignoreDependencies: make(map[string]struct{}), | ||
| validateImportStatements: true, | ||
| coarseGrainedGeneration: false, | ||
| perFileGeneration: false, | ||
| libraryNamingConvention: packageNameNamingConventionSubstitution, | ||
| binaryNamingConvention: fmt.Sprintf("%s_bin", packageNameNamingConventionSubstitution), | ||
| testNamingConvention: fmt.Sprintf("%s_test", packageNameNamingConventionSubstitution), | ||
| extensionEnabled: true, | ||
| repoRoot: repoRoot, | ||
| pythonProjectRoot: pythonProjectRoot, | ||
| excludedPatterns: singlylinkedlist.New(), | ||
| ignoreFiles: make(map[string]struct{}), | ||
| ignoreDependencies: make(map[string]struct{}), | ||
| validateImportStatements: true, | ||
| coarseGrainedGeneration: false, | ||
| perFileGeneration: false, | ||
| perFileGenerationIncludeInit: false, | ||
| libraryNamingConvention: packageNameNamingConventionSubstitution, | ||
| binaryNamingConvention: fmt.Sprintf("%s_bin", packageNameNamingConventionSubstitution), | ||
| testNamingConvention: fmt.Sprintf("%s_test", packageNameNamingConventionSubstitution), | ||
| } | ||
| } | ||
| @@ -163,19 +169,20 @@ func (c *Config) Parent() *Config { | ||
| // current Config and sets itself as the parent to the child. | ||
| func (c *Config) NewChild() *Config { | ||
| return &Config{ | ||
| parent: c, | ||
| extensionEnabled: c.extensionEnabled, | ||
| repoRoot: c.repoRoot, | ||
| pythonProjectRoot: c.pythonProjectRoot, | ||
| excludedPatterns: c.excludedPatterns, | ||
| ignoreFiles: make(map[string]struct{}), | ||
| ignoreDependencies: make(map[string]struct{}), | ||
| validateImportStatements: c.validateImportStatements, | ||
| coarseGrainedGeneration: c.coarseGrainedGeneration, | ||
| perFileGeneration: c.perFileGeneration, | ||
| libraryNamingConvention: c.libraryNamingConvention, | ||
| binaryNamingConvention: c.binaryNamingConvention, | ||
| testNamingConvention: c.testNamingConvention, | ||
| parent: c, | ||
| extensionEnabled: c.extensionEnabled, | ||
| repoRoot: c.repoRoot, | ||
| pythonProjectRoot: c.pythonProjectRoot, | ||
| excludedPatterns: c.excludedPatterns, | ||
| ignoreFiles: make(map[string]struct{}), | ||
| ignoreDependencies: make(map[string]struct{}), | ||
| validateImportStatements: c.validateImportStatements, | ||
| coarseGrainedGeneration: c.coarseGrainedGeneration, | ||
| perFileGeneration: c.perFileGeneration, | ||
| perFileGenerationIncludeInit: c.perFileGenerationIncludeInit, | ||
| libraryNamingConvention: c.libraryNamingConvention, | ||
| binaryNamingConvention: c.binaryNamingConvention, | ||
| testNamingConvention: c.testNamingConvention, | ||
| } | ||
| } | ||
| @@ -344,6 +351,18 @@ func (c *Config) PerFileGeneration() bool { | ||
| return c.perFileGeneration | ||
| } | ||
| // SetPerFileGenerationIncludeInit sets whether py_library targets should | ||
| // include __init__.py files when PerFileGeneration() is true. | ||
| func (c *Config) SetPerFileGenerationIncludeInit(includeInit bool) { | ||
| c.perFileGenerationIncludeInit = includeInit | ||
| } | ||
| // PerFileGenerationIncludeInit returns whether py_library targets should | ||
| // include __init__.py files when PerFileGeneration() is true. | ||
| func (c *Config) PerFileGenerationIncludeInit() bool { | ||
| return c.perFileGenerationIncludeInit | ||
| } | ||
| // SetLibraryNamingConvention sets the py_library target naming convention. | ||
| func (c *Config) SetLibraryNamingConvention(libraryNamingConvention string) { | ||
| c.libraryNamingConvention = libraryNamingConvention | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.