Skip to content

Commit df07bb2

Browse files
committed
fix: Fix filtering of files with default exclude filter patterns
1 parent 4bbdacd commit df07bb2

File tree

4 files changed

+49
-33
lines changed

4 files changed

+49
-33
lines changed

docs/en/guides/packaging_components.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ As a component developer, you may want to choose what files from the component d
170170
exclude:
171171
- "*.py" # Exclude all Python files
172172
- "**/*.list" # Exclude `.list` files in all directories
173-
- "big_dir/**/*" # Exclude files in `big_dir` directory (but empty directory will be added to archive anyway)
173+
- "big_dir/**/*" # Exclude `big_dir` directory and its content
174174
include:
175175
- "**/.DS_Store" # Include files excluded by default
176176

docs/en/reference/manifest_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Example:
151151
exclude:
152152
- "*.py" # Exclude all Python files
153153
- "**/*.list" # Exclude `.list` files in all directories
154-
- "big_dir/**/*" # Exclude files in `big_dir` directory (but the empty directory will be added to the archive anyway)
154+
- "big_dir/**/*" # Exclude `big_dir` directory and its content
155155
include:
156156
- "**/.DS_Store" # Include files excluded by default
157157

idf_component_tools/file_tools.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,16 @@ def exclude_paths(pattern):
7979
if exclude_default:
8080
for pattern in DEFAULT_EXCLUDE:
8181
exclude_paths(pattern)
82-
if pattern.endswith('/**/*'):
83-
exclude_paths(pattern[: pattern.rindex('/**/*')])
8482

8583
# Exclude user patterns
8684
for pattern in exclude:
8785
exclude_paths(pattern)
8886

87+
# Exclude all the directories
88+
for path in list(paths):
89+
if path.is_dir():
90+
paths.remove(path)
91+
8992
# Include everything that was explicitly added
9093
for pattern in include:
9194
include_paths(pattern)

tests/test_file_tools.py

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,50 @@ def assets_path(tmp_path, fixtures_path):
2222
# Avoid `dirs_exist_ok=True` missing in python 2
2323
subdir = tmp_path / 'sub'
2424
shutil.copytree(templatepath.as_posix(), subdir.as_posix())
25-
return subdir.as_posix()
25+
return subdir
2626

2727

2828
def test_filtered_path_default(assets_path):
2929
assert filtered_paths(assets_path) == {
30-
Path(assets_path, '1.txt'),
31-
Path(assets_path, 'ignore.dir'),
32-
Path(assets_path, 'ignore.dir', 'file.txt'),
33-
Path(assets_path, 'ignore.me'),
30+
assets_path / '1.txt',
31+
assets_path / 'ignore.dir' / 'file.txt',
32+
assets_path / 'ignore.me',
3433
}
3534

3635

3736
def test_filtered_path_no_default(assets_path):
3837
assert filtered_paths(assets_path, exclude_default=False) == {
39-
Path(assets_path, '1.txt'),
40-
Path(assets_path, 'ignore.dir'),
41-
Path(assets_path, 'ignore.dir', 'file.txt'),
42-
Path(assets_path, 'ignore.me'),
43-
Path(assets_path, '.gitlab-ci.yml'),
38+
assets_path / '1.txt',
39+
assets_path / 'ignore.dir' / 'file.txt',
40+
assets_path / 'ignore.me',
41+
assets_path / '.gitlab-ci.yml',
4442
}
4543

4644

47-
def test_filtered_path_exclude_file(assets_path):
45+
def test_filtered_path_exclude_file_and_empty_dirs(assets_path):
4846
assert filtered_paths(assets_path, exclude=['**/file.txt']) == {
49-
Path(assets_path, '1.txt'),
50-
Path(assets_path, 'ignore.dir'),
51-
Path(assets_path, 'ignore.me'),
47+
assets_path / '1.txt',
48+
assets_path / 'ignore.me',
5249
}
5350

5451

55-
def test_filtered_path_keep_empty_dir(assets_path):
52+
def test_filtered_path_exclude_file_and_empty_dir_kept(assets_path):
53+
assert filtered_paths(assets_path, exclude=['**/file.txt'], include=['ignore.dir']) == {
54+
assets_path / '1.txt',
55+
assets_path / 'ignore.me',
56+
assets_path / 'ignore.dir',
57+
}
58+
59+
60+
def test_filtered_path_removes_empty_dir(assets_path):
5661
assert filtered_paths(
5762
assets_path,
5863
exclude=[
5964
'ignore.dir/**/*',
6065
],
6166
) == {
62-
Path(assets_path, '1.txt'),
63-
Path(assets_path, 'ignore.me'),
64-
Path(assets_path, 'ignore.dir'),
67+
assets_path / '1.txt',
68+
assets_path / 'ignore.me',
6569
}
6670

6771

@@ -73,29 +77,38 @@ def test_filtered_path_exclude_empty_dir(assets_path):
7377
'ignore.dir/*',
7478
],
7579
) == {
76-
Path(assets_path, '1.txt'),
77-
Path(assets_path, 'ignore.me'),
80+
assets_path / '1.txt',
81+
assets_path / 'ignore.me',
7882
}
7983

8084

8185
def test_filtered_path_exclude_dir_with_file(assets_path):
82-
extra_path = Path(assets_path, 'ignore.dir', 'extra').as_posix()
83-
os.mkdir(extra_path)
84-
one_more = os.path.join(extra_path, 'one_more.txt')
85-
shutil.copy(os.path.join(assets_path, '1.txt'), one_more)
86+
extra_path = assets_path / 'ignore.dir' / 'extra'
87+
extra_path.mkdir(exist_ok=True)
88+
one_more = extra_path / 'one_more.txt'
89+
shutil.copy(assets_path / '1.txt', one_more)
8690

87-
assert os.path.exists(one_more)
91+
assert one_more.exists()
8892

8993
assert filtered_paths(
9094
assets_path,
9195
exclude=[
9296
'ignore.dir/*',
9397
],
9498
) == {
95-
Path(assets_path, '1.txt'),
96-
Path(assets_path, 'ignore.dir'),
97-
Path(assets_path, 'ignore.dir', 'extra', 'one_more.txt'),
98-
Path(assets_path, 'ignore.me'),
99+
assets_path / '1.txt',
100+
assets_path / 'ignore.dir' / 'extra' / 'one_more.txt',
101+
assets_path / 'ignore.me',
102+
}
103+
104+
105+
def test_filtered_with_default_path(tmp_path):
106+
(tmp_path / 'build_all.sh').touch()
107+
(tmp_path / 'build_me').mkdir()
108+
(tmp_path / 'build_me' / 'file').touch()
109+
110+
assert filtered_paths(tmp_path, exclude_default=True) == {
111+
tmp_path / 'build_all.sh',
99112
}
100113

101114

0 commit comments

Comments
 (0)