Skip to content

Commit 5f39475

Browse files
authored
Merge pull request #838 from davidgiven/banner
Fix ab bug where glob's exclude=[] wasn't working as expected.
2 parents a5539f3 + eefbaaf commit 5f39475

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

build/protobuf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
PROTO_SEPARATOR = ";" if (platform.system() == "Windows") else ":"
1313

14+
1415
def _getprotodeps(deps):
1516
r = set()
1617
for d in deps:

build/utils.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,37 @@ def collectattrs(*, targets, name, initial=[]):
4040

4141
@functools.cache
4242
def _glob_to_re(glob_str):
43-
opts = re.compile('([.]|[*][*]/|[*]|[?])|(.)')
44-
out = ''
45-
for (pattern_match, literal_text) in opts.findall(glob_str):
46-
if pattern_match == '.':
47-
out += '[.]'
48-
elif pattern_match == '**/':
49-
out += '(?:.*/)?'
50-
elif pattern_match == '*':
51-
out += '[^/]*'
52-
elif pattern_match == '?':
53-
out += '.'
43+
if glob_str.startswith("./"):
44+
glob_str = normpath(join(getcwd(), glob_str))
45+
46+
opts = re.compile("([.]|[*][*]/|[*]|[?])|(.)")
47+
out = ""
48+
for pattern_match, literal_text in opts.findall(glob_str):
49+
if pattern_match == ".":
50+
out += "[.]"
51+
elif pattern_match == "**/":
52+
out += "(?:.*/)?"
53+
elif pattern_match == "*":
54+
out += "[^/]*"
55+
elif pattern_match == "?":
56+
out += "."
5457
elif literal_text:
5558
out += literal_text
5659
return re.compile(out)
5760

61+
5862
def _glob_filter(paths, pattern):
5963
r = _glob_to_re(pattern)
6064
for f in paths:
6165
if r.match(f):
6266
yield f
6367

68+
6469
def _glob_matches(path, pattern):
6570
r = _glob_to_re(pattern)
6671
return r.match(path)
6772

73+
6874
def glob(include=["*"], exclude=[], dir=None, relative_to="."):
6975
if not dir:
7076
dir = getcwd()
@@ -77,15 +83,15 @@ def iterate():
7783
for dirpath, dirnames, filenames in walk(
7884
dir, topdown=True, followlinks=True
7985
):
80-
dirpath = relpath(dirpath, dir)
86+
dirpath = relpath(dirpath, relative_to)
8187
filenames = [normpath(join(dirpath, f)) for f in filenames]
8288
matching = set()
8389
for p in include:
84-
matching.update(_glob_filter(filenames, p))
90+
matching.update([f for f in _glob_filter(filenames, p)])
8591
for p in exclude:
86-
matching = [n for n in matching if not _glob_matches(n, p)]
92+
matching = [n for n in matching if not _glob_matches(n, p)]
8793
for f in matching:
88-
yield normpath(relpath(join(dir, f), relative_to))
94+
yield f
8995

9096
return list(iterate())
9197

0 commit comments

Comments
 (0)