Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d278223

Browse filesBrowse files
authored
[gazelle] Use filepath.WalkDir instead of filepath.Walk (bazel-contrib#770)
1 parent 4b3c2b3 commit d278223
Copy full SHA for d278223

File tree

Expand file treeCollapse file tree

2 files changed

+8
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-8
lines changed

‎gazelle/README.md

Copy file name to clipboardExpand all lines: gazelle/README.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This directory contains a plugin for
44
[Gazelle](https://github.com/bazelbuild/bazel-gazelle)
55
that generates BUILD file content for Python code.
66

7+
It requires Go 1.16+ to compile.
8+
79
## Installation
810

911
First, you'll need to add Gazelle to your `WORKSPACE` file.

‎gazelle/generate.go

Copy file name to clipboardExpand all lines: gazelle/generate.go
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package python
22

33
import (
44
"fmt"
5+
"io/fs"
56
"log"
67
"os"
78
"path/filepath"
@@ -29,9 +30,6 @@ const (
2930

3031
var (
3132
buildFilenames = []string{"BUILD", "BUILD.bazel"}
32-
// errHaltDigging is an error that signals whether the generator should halt
33-
// digging the source tree searching for modules in subdirectories.
34-
errHaltDigging = fmt.Errorf("halt digging")
3533
)
3634

3735
// GenerateRules extracts build metadata from source files in a directory.
@@ -106,9 +104,9 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
106104
// boundaryPackages represents child Bazel packages that are used as a
107105
// boundary to stop processing under that tree.
108106
boundaryPackages := make(map[string]struct{})
109-
err := filepath.Walk(
107+
err := filepath.WalkDir(
110108
filepath.Join(args.Dir, d),
111-
func(path string, info os.FileInfo, err error) error {
109+
func(path string, entry fs.DirEntry, err error) error {
112110
if err != nil {
113111
return err
114112
}
@@ -120,7 +118,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
120118
return nil
121119
}
122120
}
123-
if info.IsDir() {
121+
if entry.IsDir() {
124122
// If we are visiting a directory, we determine if we should
125123
// halt digging the tree based on a few criterias:
126124
// 1. The directory has a BUILD or BUILD.bazel files. Then
@@ -135,7 +133,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
135133
}
136134

137135
if !cfg.CoarseGrainedGeneration() && hasEntrypointFile(path) {
138-
return errHaltDigging
136+
return fs.SkipDir
139137
}
140138

141139
return nil
@@ -168,7 +166,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
168166
return nil
169167
},
170168
)
171-
if err != nil && err != errHaltDigging {
169+
if err != nil {
172170
log.Printf("ERROR: %v\n", err)
173171
return language.GenerateResult{}
174172
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.