Skip to content

Commit 36cd97c

Browse files
committed
Merge branch 'main' into feat/pypi-default-1
2 parents 7ef85aa + 175a336 commit 36cd97c

20 files changed

+101
-82
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ END_UNRELEASED_TEMPLATE
5454

5555
{#v0-0-0-changed}
5656
### Changed
57-
* Nothing changed.
57+
* (gazelle) Types for exposed members of `python.ParserOutput` are now all public.
5858

5959
{#v0-0-0-fixed}
6060
### Fixed

docs/requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ babel==2.17.0 \
1717
--hash=sha256:0c54cffb19f690cdcc52a3b50bcbf71e07a808d1c80d549f2459b9d2cf0afb9d \
1818
--hash=sha256:4d0b53093fdfb4b21c92b5213dba5a1b23885afa8383709427046b21c366e5f2
1919
# via sphinx
20-
certifi==2025.1.31 \
21-
--hash=sha256:3d5da6925056f6f18f119200434a4780a94263f10d1c21d032a6f6b2baa20651 \
22-
--hash=sha256:ca78db4565a652026a4db2bcdf68f2fb589ea80d0be70e03929ed730746b84fe
20+
certifi==2025.6.15 \
21+
--hash=sha256:2e0c7ce7cb5d8f8634ca55d2ba7e6ec2689a2fd6537d8dec1296a477a4910057 \
22+
--hash=sha256:d747aa5a8b9bbbb1bb8c22bb13e22bd1f18e9796defa16bab421f7f7a317323b
2323
# via requests
2424
charset-normalizer==3.4.1 \
2525
--hash=sha256:0167ddc8ab6508fe81860a57dd472b2ef4060e8d378f0cc555707126830f2537 \
@@ -291,9 +291,9 @@ readthedocs-sphinx-ext==2.2.5 \
291291
--hash=sha256:ee5fd5b99db9f0c180b2396cbce528aa36671951b9526bb0272dbfce5517bd27 \
292292
--hash=sha256:f8c56184ea011c972dd45a90122568587cc85b0127bc9cf064d17c68bc809daa
293293
# via rules-python-docs (docs/pyproject.toml)
294-
requests==2.32.3 \
295-
--hash=sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760 \
296-
--hash=sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6
294+
requests==2.32.4 \
295+
--hash=sha256:27babd3cda2a6d50b30443204ee89830707d396671944c998b5975b031ac2b2c \
296+
--hash=sha256:27d0316682c8a29834d3264820024b62a36942083d52caf2f14c0591336d3422
297297
# via
298298
# readthedocs-sphinx-ext
299299
# sphinx

gazelle/python/file_parser.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const (
4141

4242
type ParserOutput struct {
4343
FileName string
44-
Modules []module
45-
Comments []comment
44+
Modules []Module
45+
Comments []Comment
4646
HasMain bool
4747
}
4848

@@ -127,24 +127,24 @@ func (p *FileParser) parseMain(ctx context.Context, node *sitter.Node) bool {
127127
return false
128128
}
129129

130-
// parseImportStatement parses a node for an import statement, returning a `module` and a boolean
130+
// parseImportStatement parses a node for an import statement, returning a `Module` and a boolean
131131
// representing if the parse was OK or not.
132-
func parseImportStatement(node *sitter.Node, code []byte) (module, bool) {
132+
func parseImportStatement(node *sitter.Node, code []byte) (Module, bool) {
133133
switch node.Type() {
134134
case sitterNodeTypeDottedName:
135-
return module{
135+
return Module{
136136
Name: node.Content(code),
137137
LineNumber: node.StartPoint().Row + 1,
138138
}, true
139139
case sitterNodeTypeAliasedImport:
140140
return parseImportStatement(node.Child(0), code)
141141
case sitterNodeTypeWildcardImport:
142-
return module{
142+
return Module{
143143
Name: "*",
144144
LineNumber: node.StartPoint().Row + 1,
145145
}, true
146146
}
147-
return module{}, false
147+
return Module{}, false
148148
}
149149

150150
// parseImportStatements parses a node for import statements, returning true if the node is
@@ -188,7 +188,7 @@ func (p *FileParser) parseImportStatements(node *sitter.Node) bool {
188188
// It updates FileParser.output.Comments with the parsed comment.
189189
func (p *FileParser) parseComments(node *sitter.Node) bool {
190190
if node.Type() == sitterNodeTypeComment {
191-
p.output.Comments = append(p.output.Comments, comment(node.Content(p.code)))
191+
p.output.Comments = append(p.output.Comments, Comment(node.Content(p.code)))
192192
return true
193193
}
194194
return false

gazelle/python/file_parser_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestParseImportStatements(t *testing.T) {
2727
name string
2828
code string
2929
filepath string
30-
result []module
30+
result []Module
3131
}{
3232
{
3333
name: "not has import",
@@ -39,7 +39,7 @@ func TestParseImportStatements(t *testing.T) {
3939
name: "has import",
4040
code: "import unittest\nimport os.path\nfrom foo.bar import abc.xyz",
4141
filepath: "abc.py",
42-
result: []module{
42+
result: []Module{
4343
{
4444
Name: "unittest",
4545
LineNumber: 1,
@@ -66,7 +66,7 @@ func TestParseImportStatements(t *testing.T) {
6666
import unittest
6767
`,
6868
filepath: "abc.py",
69-
result: []module{
69+
result: []Module{
7070
{
7171
Name: "unittest",
7272
LineNumber: 2,
@@ -79,7 +79,7 @@ func TestParseImportStatements(t *testing.T) {
7979
name: "invalid syntax",
8080
code: "import os\nimport",
8181
filepath: "abc.py",
82-
result: []module{
82+
result: []Module{
8383
{
8484
Name: "os",
8585
LineNumber: 1,
@@ -92,7 +92,7 @@ func TestParseImportStatements(t *testing.T) {
9292
name: "import as",
9393
code: "import os as b\nfrom foo import bar as c# 123",
9494
filepath: "abc.py",
95-
result: []module{
95+
result: []Module{
9696
{
9797
Name: "os",
9898
LineNumber: 1,
@@ -111,7 +111,7 @@ func TestParseImportStatements(t *testing.T) {
111111
{
112112
name: "complex import",
113113
code: "from unittest import *\nfrom foo import (bar as c, baz, qux as d)\nfrom . import abc",
114-
result: []module{
114+
result: []Module{
115115
{
116116
Name: "unittest.*",
117117
LineNumber: 1,
@@ -152,7 +152,7 @@ func TestParseComments(t *testing.T) {
152152
units := []struct {
153153
name string
154154
code string
155-
result []comment
155+
result []Comment
156156
}{
157157
{
158158
name: "not has comment",
@@ -162,17 +162,17 @@ func TestParseComments(t *testing.T) {
162162
{
163163
name: "has comment",
164164
code: "# a = 1\n# b = 2",
165-
result: []comment{"# a = 1", "# b = 2"},
165+
result: []Comment{"# a = 1", "# b = 2"},
166166
},
167167
{
168168
name: "has comment in if",
169169
code: "if True:\n # a = 1\n # b = 2",
170-
result: []comment{"# a = 1", "# b = 2"},
170+
result: []Comment{"# a = 1", "# b = 2"},
171171
},
172172
{
173173
name: "has comment inline",
174174
code: "import os# 123\nfrom pathlib import Path as b#456",
175-
result: []comment{"# 123", "#456"},
175+
result: []Comment{"# 123", "#456"},
176176
},
177177
}
178178
for _, u := range units {
@@ -248,7 +248,7 @@ func TestParseFull(t *testing.T) {
248248
output, err := p.Parse(context.Background())
249249
assert.NoError(t, err)
250250
assert.Equal(t, ParserOutput{
251-
Modules: []module{{Name: "bar.abc", LineNumber: 1, Filepath: "foo/a.py", From: "bar"}},
251+
Modules: []Module{{Name: "bar.abc", LineNumber: 1, Filepath: "foo/a.py", From: "bar"}},
252252
Comments: nil,
253253
HasMain: false,
254254
FileName: "a.py",

gazelle/python/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
471471

472472
for _, pyTestTarget := range pyTestTargets {
473473
if conftest != nil {
474-
pyTestTarget.addModuleDependency(module{Name: strings.TrimSuffix(conftestFilename, ".py")})
474+
pyTestTarget.addModuleDependency(Module{Name: strings.TrimSuffix(conftestFilename, ".py")})
475475
}
476476
pyTest := pyTestTarget.build()
477477

gazelle/python/parser.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ func removeDupesFromStringTreeSetSlice(array []string) []string {
145145
return dedupe
146146
}
147147

148-
// module represents a fully-qualified, dot-separated, Python module as seen on
148+
// Module represents a fully-qualified, dot-separated, Python module as seen on
149149
// the import statement, alongside the line number where it happened.
150-
type module struct {
150+
type Module struct {
151151
// The fully-qualified, dot-separated, Python module name as seen on import
152152
// statements.
153153
Name string `json:"name"`
@@ -162,7 +162,7 @@ type module struct {
162162

163163
// moduleComparator compares modules by name.
164164
func moduleComparator(a, b interface{}) int {
165-
return godsutils.StringComparator(a.(module).Name, b.(module).Name)
165+
return godsutils.StringComparator(a.(Module).Name, b.(Module).Name)
166166
}
167167

168168
// annotationKind represents Gazelle annotation kinds.
@@ -176,12 +176,12 @@ const (
176176
annotationKindIncludeDep annotationKind = "include_dep"
177177
)
178178

179-
// comment represents a Python comment.
180-
type comment string
179+
// Comment represents a Python comment.
180+
type Comment string
181181

182182
// asAnnotation returns an annotation object if the comment has the
183183
// annotationPrefix.
184-
func (c *comment) asAnnotation() (*annotation, error) {
184+
func (c *Comment) asAnnotation() (*annotation, error) {
185185
uncomment := strings.TrimLeft(string(*c), "# ")
186186
if !strings.HasPrefix(uncomment, annotationPrefix) {
187187
return nil, nil
@@ -215,7 +215,7 @@ type annotations struct {
215215

216216
// annotationsFromComments returns all the annotations parsed out of the
217217
// comments of a Python module.
218-
func annotationsFromComments(comments []comment) (*annotations, error) {
218+
func annotationsFromComments(comments []Comment) (*annotations, error) {
219219
ignore := make(map[string]struct{})
220220
includeDeps := []string{}
221221
for _, comment := range comments {

gazelle/python/resolve.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (py *Resolver) Resolve(
151151
hasFatalError := false
152152
MODULES_LOOP:
153153
for it.Next() {
154-
mod := it.Value().(module)
154+
mod := it.Value().(Module)
155155
moduleParts := strings.Split(mod.Name, ".")
156156
possibleModules := []string{mod.Name}
157157
for len(moduleParts) > 1 {
@@ -214,7 +214,7 @@ func (py *Resolver) Resolve(
214214
matches := ix.FindRulesByImportWithConfig(c, imp, languageName)
215215
if len(matches) == 0 {
216216
// Check if the imported module is part of the standard library.
217-
if isStdModule(module{Name: moduleName}) {
217+
if isStdModule(Module{Name: moduleName}) {
218218
continue MODULES_LOOP
219219
} else if cfg.ValidateImportStatements() {
220220
err := fmt.Errorf(

gazelle/python/std_modules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func init() {
3434
}
3535
}
3636

37-
func isStdModule(m module) bool {
37+
func isStdModule(m Module) bool {
3838
_, ok := stdModules[m.Name]
3939
return ok
4040
}

gazelle/python/std_modules_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
func TestIsStdModule(t *testing.T) {
24-
assert.True(t, isStdModule(module{Name: "unittest"}))
25-
assert.True(t, isStdModule(module{Name: "os.path"}))
26-
assert.False(t, isStdModule(module{Name: "foo"}))
24+
assert.True(t, isStdModule(Module{Name: "unittest"}))
25+
assert.True(t, isStdModule(Module{Name: "os.path"}))
26+
assert.False(t, isStdModule(Module{Name: "foo"}))
2727
}

gazelle/python/target.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (t *targetBuilder) addSrcs(srcs *treeset.Set) *targetBuilder {
6969
}
7070

7171
// addModuleDependency adds a single module dep to the target.
72-
func (t *targetBuilder) addModuleDependency(dep module) *targetBuilder {
72+
func (t *targetBuilder) addModuleDependency(dep Module) *targetBuilder {
7373
fileName := dep.Name + ".py"
7474
if dep.From != "" {
7575
fileName = dep.From + ".py"
@@ -87,7 +87,7 @@ func (t *targetBuilder) addModuleDependency(dep module) *targetBuilder {
8787
func (t *targetBuilder) addModuleDependencies(deps *treeset.Set) *targetBuilder {
8888
it := deps.Iterator()
8989
for it.Next() {
90-
t.addModuleDependency(it.Value().(module))
90+
t.addModuleDependency(it.Value().(Module))
9191
}
9292
return t
9393
}

0 commit comments

Comments
 (0)