Skip to content

Commit d93a616

Browse files
committed
fix: allow to specify the root folder
1 parent 25d4227 commit d93a616

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

python/private/pypi/namespace_pkgs.bzl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ EXTS = [
77
".pyc",
88
]
99

10-
def _get_files(files, ignored_dirnames = []):
10+
def _add_all(dirname, dirs):
11+
dir_path = "."
12+
for dir_name in dirname.split("/"):
13+
dir_path = "{}/{}".format(dir_path, dir_name)
14+
dirs[dir_path[2:]] = None
15+
16+
def _get_files(files, ignored_dirnames = [], root = None):
1117
dirs = {}
1218
ignored = {i: None for i in ignored_dirnames}
19+
20+
if root:
21+
_add_all(root, ignored)
22+
1323
for file in files:
1424
dirname, _, filename = file.rpartition("/")
1525

@@ -30,10 +40,7 @@ def _get_files(files, ignored_dirnames = []):
3040
if dirname in dirs or not dirname:
3141
continue
3242

33-
dir_path = "."
34-
for dir_name in dirname.split("/"):
35-
dir_path = "{}/{}".format(dir_path, dir_name)
36-
dirs[dir_path[2:]] = None
43+
_add_all(dirname, dirs)
3744

3845
return sorted([d for d in dirs if d not in ignored])
3946

tests/pypi/namespace_pkgs/namespace_pkgs_tests.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ _tests.append(test_in_current_dir)
2424

2525
def test_find_correct_namespace_packages(env):
2626
files = [
27-
"foo/bar/biz.py",
28-
"foo/bee/boo.py",
29-
"foo/buu/__init__.py",
30-
"foo/buu/bii.py",
27+
"nested/root/foo/bar/biz.py",
28+
"nested/root/foo/bee/boo.py",
29+
"nested/root/foo/buu/__init__.py",
30+
"nested/root/foo/buu/bii.py",
3131
]
3232

33-
got = namespace_pkgs.get_files(files)
33+
got = namespace_pkgs.get_files(files, root = "nested/root")
3434
expected = [
35-
"foo",
36-
"foo/bar",
37-
"foo/bee",
35+
"nested/root/foo",
36+
"nested/root/foo/bar",
37+
"nested/root/foo/bee",
3838
]
3939
env.expect.that_collection(got).contains_exactly(expected)
4040

0 commit comments

Comments
 (0)