From 7ee802341eb1b9a544ed216dae8adc461008dba8 Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Tue, 27 Feb 2024 10:40:37 -0800 Subject: [PATCH 1/9] Add test case --- .../directive_python_visibility/BUILD.in | 4 ++++ .../directive_python_visibility/BUILD.out | 16 +++++++++++++++ .../directive_python_visibility/README.md | 4 ++++ .../directive_python_visibility/WORKSPACE | 1 + .../directive_python_visibility/foo.py | 2 ++ .../subdir/BUILD.in | 4 ++++ .../subdir/BUILD.out | 20 +++++++++++++++++++ .../subdir/__init__.py | 0 .../directive_python_visibility/subdir/bar.py | 0 .../directive_python_visibility/test.yaml | 17 ++++++++++++++++ 10 files changed, 68 insertions(+) create mode 100644 gazelle/python/testdata/directive_python_visibility/BUILD.in create mode 100644 gazelle/python/testdata/directive_python_visibility/BUILD.out create mode 100644 gazelle/python/testdata/directive_python_visibility/README.md create mode 100644 gazelle/python/testdata/directive_python_visibility/WORKSPACE create mode 100644 gazelle/python/testdata/directive_python_visibility/foo.py create mode 100644 gazelle/python/testdata/directive_python_visibility/subdir/BUILD.in create mode 100644 gazelle/python/testdata/directive_python_visibility/subdir/BUILD.out create mode 100644 gazelle/python/testdata/directive_python_visibility/subdir/__init__.py create mode 100644 gazelle/python/testdata/directive_python_visibility/subdir/bar.py create mode 100644 gazelle/python/testdata/directive_python_visibility/test.yaml diff --git a/gazelle/python/testdata/directive_python_visibility/BUILD.in b/gazelle/python/testdata/directive_python_visibility/BUILD.in new file mode 100644 index 0000000000..c1ba9e455e --- /dev/null +++ b/gazelle/python/testdata/directive_python_visibility/BUILD.in @@ -0,0 +1,4 @@ +# Directives can be added in any order. They will be ordered alphabetically +# when added. +# gazelle:python_visibility //tests:__pkg__ +# gazelle:python_visibility //bar:baz diff --git a/gazelle/python/testdata/directive_python_visibility/BUILD.out b/gazelle/python/testdata/directive_python_visibility/BUILD.out new file mode 100644 index 0000000000..70715e86fa --- /dev/null +++ b/gazelle/python/testdata/directive_python_visibility/BUILD.out @@ -0,0 +1,16 @@ +load("@rules_python//python:defs.bzl", "py_library") + +# Directives can be added in any order. They will be ordered alphabetically +# when added. +# gazelle:python_visibility //tests:__pkg__ +# gazelle:python_visibility //bar:baz + +py_library( + name = "directive_python_visibility", + srcs = ["foo.py"], + visibility = [ + "//:__subpackages__", + "//bar:baz", + "//tests:__pkg__", + ], +) diff --git a/gazelle/python/testdata/directive_python_visibility/README.md b/gazelle/python/testdata/directive_python_visibility/README.md new file mode 100644 index 0000000000..51ab7aef6b --- /dev/null +++ b/gazelle/python/testdata/directive_python_visibility/README.md @@ -0,0 +1,4 @@ +# Directive: `python_visibility` + +This test case asserts that the `# gazelle:python_visibility` directive correctly +appends multiple labels to the target's `visibility` parameter. diff --git a/gazelle/python/testdata/directive_python_visibility/WORKSPACE b/gazelle/python/testdata/directive_python_visibility/WORKSPACE new file mode 100644 index 0000000000..faff6af87a --- /dev/null +++ b/gazelle/python/testdata/directive_python_visibility/WORKSPACE @@ -0,0 +1 @@ +# This is a Bazel workspace for the Gazelle test data. diff --git a/gazelle/python/testdata/directive_python_visibility/foo.py b/gazelle/python/testdata/directive_python_visibility/foo.py new file mode 100644 index 0000000000..98907eb794 --- /dev/null +++ b/gazelle/python/testdata/directive_python_visibility/foo.py @@ -0,0 +1,2 @@ +def func(): + print("library_func") diff --git a/gazelle/python/testdata/directive_python_visibility/subdir/BUILD.in b/gazelle/python/testdata/directive_python_visibility/subdir/BUILD.in new file mode 100644 index 0000000000..5193e69587 --- /dev/null +++ b/gazelle/python/testdata/directive_python_visibility/subdir/BUILD.in @@ -0,0 +1,4 @@ +# python_visibilty directive applies to all child bazel packages. +# Thus, the generated file for this package will also have vis for +# //tests:__pkg__ and //bar:baz in addition to the default. +# gazelle:python_visibility //tests:__subpackages__ diff --git a/gazelle/python/testdata/directive_python_visibility/subdir/BUILD.out b/gazelle/python/testdata/directive_python_visibility/subdir/BUILD.out new file mode 100644 index 0000000000..722c840432 --- /dev/null +++ b/gazelle/python/testdata/directive_python_visibility/subdir/BUILD.out @@ -0,0 +1,20 @@ +load("@rules_python//python:defs.bzl", "py_library") + +# python_visibilty directive applies to all child bazel packages. +# Thus, the generated file for this package will also have vis for +# //tests:__pkg__ and //bar:baz in addition to the default. +# gazelle:python_visibility //tests:__subpackages__ + +py_library( + name = "subdir", + srcs = [ + "__init__.py", + "bar.py", + ], + visibility = [ + "//:__subpackages__", + "//bar:baz", + "//tests:__pkg__", + "//tests:__subpackages__", + ], +) diff --git a/gazelle/python/testdata/directive_python_visibility/subdir/__init__.py b/gazelle/python/testdata/directive_python_visibility/subdir/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gazelle/python/testdata/directive_python_visibility/subdir/bar.py b/gazelle/python/testdata/directive_python_visibility/subdir/bar.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gazelle/python/testdata/directive_python_visibility/test.yaml b/gazelle/python/testdata/directive_python_visibility/test.yaml new file mode 100644 index 0000000000..2410223e59 --- /dev/null +++ b/gazelle/python/testdata/directive_python_visibility/test.yaml @@ -0,0 +1,17 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +expect: + exit_code: 0 From 8c4680d6b8e11c542d95396967847bec24741fa1 Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Tue, 27 Feb 2024 11:32:42 -0800 Subject: [PATCH 2/9] Add python_visibility directive --- gazelle/python/configure.go | 3 +++ gazelle/python/generate.go | 5 ++++- gazelle/python/target.go | 8 +++++--- gazelle/pythonconfig/pythonconfig.go | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/gazelle/python/configure.go b/gazelle/python/configure.go index 69d276266e..8aec1502ea 100644 --- a/gazelle/python/configure.go +++ b/gazelle/python/configure.go @@ -63,6 +63,7 @@ func (py *Configurer) KnownDirectives() []string { pythonconfig.LibraryNamingConvention, pythonconfig.BinaryNamingConvention, pythonconfig.TestNamingConvention, + pythonconfig.ExtraVisibility, } } @@ -162,6 +163,8 @@ func (py *Configurer) Configure(c *config.Config, rel string, f *rule.File) { config.SetBinaryNamingConvention(strings.TrimSpace(d.Value)) case pythonconfig.TestNamingConvention: config.SetTestNamingConvention(strings.TrimSpace(d.Value)) + case pythonconfig.ExtraVisibility: + config.AppendExtraVisibility(strings.TrimSpace(d.Value)) } } diff --git a/gazelle/python/generate.go b/gazelle/python/generate.go index ba273be2b7..4d254810d9 100644 --- a/gazelle/python/generate.go +++ b/gazelle/python/generate.go @@ -212,7 +212,10 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes } parser := newPython3Parser(args.Config.RepoRoot, args.Rel, cfg.IgnoresDependency) - visibility := fmt.Sprintf("//%s:__subpackages__", pythonProjectRoot) + // TODO(gh-1682): Add support for default_visibility directive and replace + // the initil visibility value. + visibility := []string{fmt.Sprintf("//%s:__subpackages__", pythonProjectRoot)} + visibility = append(visibility, cfg.ExtraVisibility()...) var result language.GenerateResult result.Gen = make([]*rule.Rule, 0) diff --git a/gazelle/python/target.go b/gazelle/python/target.go index e3104058b2..a941a7cc7e 100644 --- a/gazelle/python/target.go +++ b/gazelle/python/target.go @@ -99,9 +99,11 @@ func (t *targetBuilder) addResolvedDependency(dep string) *targetBuilder { return t } -// addVisibility adds a visibility to the target. -func (t *targetBuilder) addVisibility(visibility string) *targetBuilder { - t.visibility.Add(visibility) +// addVisibility adds visibility labels to the target. +func (t *targetBuilder) addVisibility(visibility []string) *targetBuilder { + for _, item := range visibility { + t.visibility.Add(item) + } return t } diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go index cecf9dcea0..8f897dda25 100644 --- a/gazelle/pythonconfig/pythonconfig.go +++ b/gazelle/pythonconfig/pythonconfig.go @@ -67,6 +67,10 @@ const ( // naming convention. See python_library_naming_convention for more info on // the package name interpolation. TestNamingConvention = "python_test_naming_convention" + // ExtraVisibility represents the directive that controls what additional + // visibility labels are added to generated targets. It mimics the behavior + // of the `go_visibility` directive. + ExtraVisibility = "python_visibility" ) // GenerationModeType represents one of the generation modes for the Python @@ -136,6 +140,7 @@ type Config struct { libraryNamingConvention string binaryNamingConvention string testNamingConvention string + extraVisibility []string } // New creates a new Config. @@ -157,6 +162,7 @@ func New( libraryNamingConvention: packageNameNamingConventionSubstitution, binaryNamingConvention: fmt.Sprintf("%s_bin", packageNameNamingConventionSubstitution), testNamingConvention: fmt.Sprintf("%s_test", packageNameNamingConventionSubstitution), + extraVisibility: []string{}, } } @@ -183,6 +189,7 @@ func (c *Config) NewChild() *Config { libraryNamingConvention: c.libraryNamingConvention, binaryNamingConvention: c.binaryNamingConvention, testNamingConvention: c.testNamingConvention, + extraVisibility: c.extraVisibility, } } @@ -388,3 +395,13 @@ func (c *Config) SetTestNamingConvention(testNamingConvention string) { func (c *Config) RenderTestName(packageName string) string { return strings.ReplaceAll(c.testNamingConvention, packageNameNamingConventionSubstitution, packageName) } + +// AppendExtraVisibility adds additional items to the target's visibility. +func (c *Config) AppendExtraVisibility(visibility string) { + c.extraVisibility = append(c.extraVisibility, visibility) +} + +// ExtraVisibility returns the target's visibility. +func (c *Config) ExtraVisibility() []string { + return c.extraVisibility +} From 4fe0e695bd70dc705cb5ced25adf0eaa89ddad8b Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Tue, 27 Feb 2024 12:44:33 -0800 Subject: [PATCH 3/9] Update README --- gazelle/README.md | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/gazelle/README.md b/gazelle/README.md index c1221a6015..ee990c504f 100644 --- a/gazelle/README.md +++ b/gazelle/README.md @@ -198,6 +198,54 @@ Python-specific directives are as follows: | Controls the `py_test` naming convention. Follows the same interpolation rules as `python_library_naming_convention`. | | | `# gazelle:resolve py ...` | n/a | | Instructs the plugin what target to add as a dependency to satisfy a given import statement. The syntax is `# gazelle:resolve py import-string label` where `import-string` is the symbol in the python `import` statement, and `label` is the Bazel label that Gazelle should write in `deps`. | | +| [`# gazelle:python_visibility label`](#directive-python_visibility) | | +| Append additional visibility labels to each generated target. This directive can be set multiple times. | | + + +#### Directive: `python_visibility`: + +Append additional `visibility` labels to each generated target. + +This directive can be set multiple times. The generated `visibility` attribute +will include the default visibility and all labels defined by this directive. +All labels will be ordered alphabetically. + + +```starlark +# ./BUILD.bazel +# gazelle:python_visibility //tests:__pkg__ +# gazelle:python_visibility //bar:baz + +py_library( + ... + visibility = [ + "//:__subpackages__", # default visibility + "//bar:baz", + "//tests:__pkg__", + ], + ... +) +``` + +Child Bazel packages inherit values from parents. + +```starlark +# ./bar/BUILD.bazel +# gazelle:python_visibility //tests:__subpackages__ + +py_library( + ... + visibility = [ + "//:__subpackages__", # default visibility + "//bar:baz", # defined in ../BUILD.bazel + "//tests:__pkg__", # defined in ../BUILD.bazel + "//tests:__subpackages__", # defined in this ./BUILD.bazel + ], + ... +) + +``` + ### Libraries From 6127e39aacabc3e1d25fd16b03848c341067db6d Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Tue, 27 Feb 2024 14:16:28 -0800 Subject: [PATCH 4/9] spelling --- gazelle/python/generate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gazelle/python/generate.go b/gazelle/python/generate.go index 4d254810d9..c38ab97d69 100644 --- a/gazelle/python/generate.go +++ b/gazelle/python/generate.go @@ -213,7 +213,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes parser := newPython3Parser(args.Config.RepoRoot, args.Rel, cfg.IgnoresDependency) // TODO(gh-1682): Add support for default_visibility directive and replace - // the initil visibility value. + // the initial visibility value. visibility := []string{fmt.Sprintf("//%s:__subpackages__", pythonProjectRoot)} visibility = append(visibility, cfg.ExtraVisibility()...) From afcec2b1b7960a237fc676e457af282c90f5ba3f Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Tue, 27 Feb 2024 19:38:59 -0800 Subject: [PATCH 5/9] Move things around in README.md --- gazelle/README.md | 76 +++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/gazelle/README.md b/gazelle/README.md index 64bb040588..ac71c0b890 100644 --- a/gazelle/README.md +++ b/gazelle/README.md @@ -202,6 +202,42 @@ Python-specific directives are as follows: | Append additional visibility labels to each generated target. This directive can be set multiple times. | | +#### Directive: `python_root`: + +Set this directive within the Bazel package that you want to use as the Python root. +For example, if using a `src` dir (as recommended by the [Python Packaging User +Guide][python-packaging-user-guide]), then set this directive in `src/BUILD.bazel`: + +```starlark +# ./src/BUILD.bazel +# Tell gazelle that are python root is the same dir as this Bazel package. +# gazelle:python_root +``` + +Note that the directive does not have any arguments. + +Gazelle will then add the necessary `imports` attribute to all targets that it +generates: + +```starlark +# in ./src/foo/BUILD.bazel +py_libary( + ... + imports = [".."], # Gazelle adds this + ... +) + +# in ./src/foo/bar/BUILD.bazel +py_libary( + ... + imports = ["../.."], # Gazelle adds this + ... +) +``` + +[python-packaging-user-guide]: https://github.com/pypa/packaging.python.org/blob/4c86169a/source/tutorials/packaging-projects.rst + + #### Directive: `python_visibility`: Append additional `visibility` labels to each generated target. @@ -210,7 +246,6 @@ This directive can be set multiple times. The generated `visibility` attribute will include the default visibility and all labels defined by this directive. All labels will be ordered alphabetically. - ```starlark # ./BUILD.bazel # gazelle:python_visibility //tests:__pkg__ @@ -227,7 +262,7 @@ py_library( ) ``` -Child Bazel packages inherit values from parents. +Child Bazel packages inherit values from parents: ```starlark # ./bar/BUILD.bazel @@ -247,43 +282,6 @@ py_library( ``` - -#### Directive: `python_root`: - -Set this directive within the Bazel package that you want to use as the Python root. -For example, if using a `src` dir (as recommended by the [Python Packaging User -Guide][python-packaging-user-guide]), then set this directive in `src/BUILD.bazel`: - -```starlark -# ./src/BUILD.bazel -# Tell gazelle that are python root is the same dir as this Bazel package. -# gazelle:python_root -``` - -Note that the directive does not have any arguments. - -Gazelle will then add the necessary `imports` attribute to all targets that it -generates: - -```starlark -# in ./src/foo/BUILD.bazel -py_libary( - ... - imports = [".."], # Gazelle adds this - ... -) - -# in ./src/foo/bar/BUILD.bazel -py_libary( - ... - imports = ["../.."], # Gazelle adds this - ... -) -``` - -[python-packaging-user-guide]: https://github.com/pypa/packaging.python.org/blob/4c86169a/source/tutorials/packaging-projects.rst - - ### Libraries Python source files are those ending in `.py` but not ending in `_test.py`. From e3ec8787abe3ac75affcf89bc9e7f0ea02bb2e68 Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Tue, 27 Feb 2024 19:39:55 -0800 Subject: [PATCH 6/9] s/append/appends/g in readme per code review. --- gazelle/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gazelle/README.md b/gazelle/README.md index ac71c0b890..00170345e7 100644 --- a/gazelle/README.md +++ b/gazelle/README.md @@ -199,7 +199,7 @@ Python-specific directives are as follows: | `# gazelle:resolve py ...` | n/a | | Instructs the plugin what target to add as a dependency to satisfy a given import statement. The syntax is `# gazelle:resolve py import-string label` where `import-string` is the symbol in the python `import` statement, and `label` is the Bazel label that Gazelle should write in `deps`. | | | [`# gazelle:python_visibility label`](#directive-python_visibility) | | -| Append additional visibility labels to each generated target. This directive can be set multiple times. | | +| Appends additional visibility labels to each generated target. This directive can be set multiple times. | | #### Directive: `python_root`: @@ -240,7 +240,7 @@ py_libary( #### Directive: `python_visibility`: -Append additional `visibility` labels to each generated target. +Appends additional `visibility` labels to each generated target. This directive can be set multiple times. The generated `visibility` attribute will include the default visibility and all labels defined by this directive. From ccb9b490f0f4fa344955e6991d283f66a269e86f Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Tue, 27 Feb 2024 19:41:31 -0800 Subject: [PATCH 7/9] s/Extra//g per code review --- gazelle/python/configure.go | 6 +++--- gazelle/python/generate.go | 2 +- gazelle/pythonconfig/pythonconfig.go | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gazelle/python/configure.go b/gazelle/python/configure.go index 8aec1502ea..431568829b 100644 --- a/gazelle/python/configure.go +++ b/gazelle/python/configure.go @@ -63,7 +63,7 @@ func (py *Configurer) KnownDirectives() []string { pythonconfig.LibraryNamingConvention, pythonconfig.BinaryNamingConvention, pythonconfig.TestNamingConvention, - pythonconfig.ExtraVisibility, + pythonconfig.Visibility, } } @@ -163,8 +163,8 @@ func (py *Configurer) Configure(c *config.Config, rel string, f *rule.File) { config.SetBinaryNamingConvention(strings.TrimSpace(d.Value)) case pythonconfig.TestNamingConvention: config.SetTestNamingConvention(strings.TrimSpace(d.Value)) - case pythonconfig.ExtraVisibility: - config.AppendExtraVisibility(strings.TrimSpace(d.Value)) + case pythonconfig.Visibility: + config.AppendVisibility(strings.TrimSpace(d.Value)) } } diff --git a/gazelle/python/generate.go b/gazelle/python/generate.go index c38ab97d69..e9d35d4e87 100644 --- a/gazelle/python/generate.go +++ b/gazelle/python/generate.go @@ -215,7 +215,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes // TODO(gh-1682): Add support for default_visibility directive and replace // the initial visibility value. visibility := []string{fmt.Sprintf("//%s:__subpackages__", pythonProjectRoot)} - visibility = append(visibility, cfg.ExtraVisibility()...) + visibility = append(visibility, cfg.Visibility()...) var result language.GenerateResult result.Gen = make([]*rule.Rule, 0) diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go index 8f897dda25..e984ac8853 100644 --- a/gazelle/pythonconfig/pythonconfig.go +++ b/gazelle/pythonconfig/pythonconfig.go @@ -67,10 +67,10 @@ const ( // naming convention. See python_library_naming_convention for more info on // the package name interpolation. TestNamingConvention = "python_test_naming_convention" - // ExtraVisibility represents the directive that controls what additional + // Visibility represents the directive that controls what additional // visibility labels are added to generated targets. It mimics the behavior // of the `go_visibility` directive. - ExtraVisibility = "python_visibility" + Visibility = "python_visibility" ) // GenerationModeType represents one of the generation modes for the Python @@ -396,12 +396,12 @@ func (c *Config) RenderTestName(packageName string) string { return strings.ReplaceAll(c.testNamingConvention, packageNameNamingConventionSubstitution, packageName) } -// AppendExtraVisibility adds additional items to the target's visibility. -func (c *Config) AppendExtraVisibility(visibility string) { +// AppendVisibility adds additional items to the target's visibility. +func (c *Config) AppendVisibility(visibility string) { c.extraVisibility = append(c.extraVisibility, visibility) } -// ExtraVisibility returns the target's visibility. -func (c *Config) ExtraVisibility() []string { +// Visibility returns the target's visibility. +func (c *Config) Visibility() []string { return c.extraVisibility } From dbe47244b023c3314faaf60870a105f5e134666c Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Thu, 29 Feb 2024 20:21:59 -0800 Subject: [PATCH 8/9] Remove TODO --- gazelle/python/generate.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/gazelle/python/generate.go b/gazelle/python/generate.go index e9d35d4e87..6973d2ded8 100644 --- a/gazelle/python/generate.go +++ b/gazelle/python/generate.go @@ -212,8 +212,6 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes } parser := newPython3Parser(args.Config.RepoRoot, args.Rel, cfg.IgnoresDependency) - // TODO(gh-1682): Add support for default_visibility directive and replace - // the initial visibility value. visibility := []string{fmt.Sprintf("//%s:__subpackages__", pythonProjectRoot)} visibility = append(visibility, cfg.Visibility()...) From c48a65b0181748fe6ed857e16e04dc4da41036b8 Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Thu, 29 Feb 2024 20:26:32 -0800 Subject: [PATCH 9/9] _actually_ remove all the 'extra' prefixes. --- gazelle/pythonconfig/pythonconfig.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go index e984ac8853..e350a7cb60 100644 --- a/gazelle/pythonconfig/pythonconfig.go +++ b/gazelle/pythonconfig/pythonconfig.go @@ -140,7 +140,7 @@ type Config struct { libraryNamingConvention string binaryNamingConvention string testNamingConvention string - extraVisibility []string + visibility []string } // New creates a new Config. @@ -162,7 +162,7 @@ func New( libraryNamingConvention: packageNameNamingConventionSubstitution, binaryNamingConvention: fmt.Sprintf("%s_bin", packageNameNamingConventionSubstitution), testNamingConvention: fmt.Sprintf("%s_test", packageNameNamingConventionSubstitution), - extraVisibility: []string{}, + visibility: []string{}, } } @@ -189,7 +189,7 @@ func (c *Config) NewChild() *Config { libraryNamingConvention: c.libraryNamingConvention, binaryNamingConvention: c.binaryNamingConvention, testNamingConvention: c.testNamingConvention, - extraVisibility: c.extraVisibility, + visibility: c.visibility, } } @@ -398,10 +398,10 @@ func (c *Config) RenderTestName(packageName string) string { // AppendVisibility adds additional items to the target's visibility. func (c *Config) AppendVisibility(visibility string) { - c.extraVisibility = append(c.extraVisibility, visibility) + c.visibility = append(c.visibility, visibility) } // Visibility returns the target's visibility. func (c *Config) Visibility() []string { - return c.extraVisibility + return c.visibility }