Skip to content

Commit 4e16ec1

Browse files
authored
Fix issue in _deny_filter (#165)
1 parent bf8117f commit 4e16ec1

File tree

7 files changed

+118
-64
lines changed

7 files changed

+118
-64
lines changed

doc/changes/unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
The CI-CD workflow now assumes the changelog to be in markdown and the location `/doc/changes/change_x.y.z.md`
99

1010
## 🐞 Fixed
11+
* Fixed `_deny_filter` function in `exasol.toolbox._shared` module
1112
* Fixed GitHub workflow references in `ci.yml`, ci-cd.yml` and `pr-merge.yml` workflows
1213
* Fixed indent error/issue in `checks.yml` workflow
1314

exasol/toolbox/nox/_shared.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,9 @@ def _python_files(
4040
def _deny_filter(files: Iterable[Path], deny_list: Iterable[str]) -> Iterable[Path]:
4141
"""
4242
Adds a filter to remove unwanted paths containing python files from the iterator.
43-
44-
args:
45-
46-
47-
return:
4843
"""
4944
for entry in deny_list:
50-
files = filter(lambda path: entry not in path.parts, files)
45+
files = list(filter(lambda path: entry not in path.parts, files))
5146
return files
5247

5348

exasol/toolbox/tools/issue.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from pathlib import Path
2+
23
import typer
3-
from exasol.toolbox.tools import template
44

5+
from exasol.toolbox.tools import template
56

67
CLI = typer.Typer()
78
PKG = "exasol.toolbox.templates.github.ISSUE_TEMPLATE"
@@ -24,7 +25,9 @@ def show_issue(
2425
issue: str = typer.Argument(..., help="issue which shall be shown."),
2526
) -> None:
2627
"""Shows a specific issue."""
27-
template.show_templates(template=issue, pkg=PKG, template_type=TEMPLATE_TYPE, lexer=LEXER)
28+
template.show_templates(
29+
template=issue, pkg=PKG, template_type=TEMPLATE_TYPE, lexer=LEXER
30+
)
2831

2932

3033
@CLI.command(name="diff")
@@ -36,36 +39,44 @@ def diff_issue(
3639
),
3740
) -> None:
3841
"""Diff a specific issue against the installed one."""
39-
template.diff_template(template=issue, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE)
42+
template.diff_template(
43+
template=issue, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE
44+
)
4045

4146

4247
@CLI.command(name="install")
4348
def install_issue(
4449
issue: str = typer.Argument("all", help="name of the issue to install."),
4550
dest: Path = typer.Argument(
46-
Path("./.github/ISSUE_TEMPLATE"), help="target directory to install the issue to."
51+
Path("./.github/ISSUE_TEMPLATE"),
52+
help="target directory to install the issue to.",
4753
),
4854
) -> None:
4955
"""
5056
Installs the requested issue into the target directory.
5157
5258
Attention: If there is an existing issue with the same name it will be overwritten!
5359
"""
54-
template.install_template(template=issue, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE)
60+
template.install_template(
61+
template=issue, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE
62+
)
5563

5664

5765
@CLI.command(name="update")
5866
def update_issue(
5967
issue: str = typer.Argument("all", help="name of the issue to install."),
6068
dest: Path = typer.Argument(
61-
Path("./.github/ISSUE_TEMPLATE"), help="target directory to install the issue to."
69+
Path("./.github/ISSUE_TEMPLATE"),
70+
help="target directory to install the issue to.",
6271
),
6372
confirm: bool = typer.Option(
6473
False, help="Automatically confirm overwritting exsisting issue(s)"
6574
),
6675
) -> None:
6776
"""Similar to install but checks for existing issues and shows diff"""
68-
template.update_template(template=issue, dest=dest, confirm=confirm, pkg=PKG, template_type=TEMPLATE_TYPE)
77+
template.update_template(
78+
template=issue, dest=dest, confirm=confirm, pkg=PKG, template_type=TEMPLATE_TYPE
79+
)
6980

7081

7182
if __name__ == "__main__":

exasol/toolbox/tools/template.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ def _normalize(name: str) -> str:
2828
return {_normalize(w.name): w for w in resources.files(pkg).iterdir()}
2929

3030

31-
def list_templates(
32-
columns: bool,
33-
pkg: str
34-
) -> None:
31+
def list_templates(columns: bool, pkg: str) -> None:
3532
"""List all available templates."""
3633

3734
class List:
@@ -41,7 +38,9 @@ def __init__(self, items: Any):
4138
def __rich__(self) -> str:
4239
return "\n".join(self.items)
4340

44-
output = List(_templates(pkg)) if not columns else Columns(_templates(pkg), expand=True)
41+
output = (
42+
List(_templates(pkg)) if not columns else Columns(_templates(pkg), expand=True)
43+
)
4544
stdout.print(output)
4645

4746

@@ -61,12 +60,7 @@ def show_templates(
6160
stdout.print(Syntax.from_path(path=template, encoding="utf-8", lexer=lexer)) # type: ignore
6261

6362

64-
def diff_template(
65-
template: str,
66-
dest: Path,
67-
pkg: str,
68-
template_type: str
69-
) -> None:
63+
def diff_template(template: str, dest: Path, pkg: str, template_type: str) -> None:
7064
"""Diff a specific template against the installed one."""
7165
templates = _templates(pkg)
7266
if template not in templates:
@@ -79,7 +73,9 @@ def diff_template(
7973
old: Any = dest / f"{template}{path.suffix}"
8074
new: Any = Path(_templates(pkg)[template])
8175
with ExitStack() as stack:
82-
old = stack.enter_context(open(old, encoding="utf-8") if old.exists() else io.StringIO(""))
76+
old = stack.enter_context(
77+
open(old, encoding="utf-8") if old.exists() else io.StringIO("")
78+
)
8379
new = stack.enter_context(open(new, encoding="utf-8"))
8480
old = old.read().split("\n")
8581
new = new.read().split("\n")
@@ -90,7 +86,9 @@ def diff_template(
9086

9187
def _install_template(
9288
template_type: str,
93-
src: Union[str, Path], dest: Union[str, Path], exists_ok: bool = False,
89+
src: Union[str, Path],
90+
dest: Union[str, Path],
91+
exists_ok: bool = False,
9492
) -> None:
9593
src, dest = Path(src), Path(dest)
9694

@@ -115,12 +113,7 @@ def _select_templates(template: str, pkg: str, template_type: str) -> Mapping[st
115113
return templates
116114

117115

118-
def install_template(
119-
template: str,
120-
dest: Path,
121-
pkg: str,
122-
template_type: str
123-
) -> None:
116+
def install_template(template: str, dest: Path, pkg: str, template_type: str) -> None:
124117
"""
125118
Installs the requested template into the target directory.
126119
@@ -142,11 +135,7 @@ def install_template(
142135

143136

144137
def update_template(
145-
template: str,
146-
dest: Path,
147-
confirm: bool,
148-
pkg: str,
149-
template_type: str
138+
template: str, dest: Path, confirm: bool, pkg: str, template_type: str
150139
) -> None:
151140
"""Similar to install but checks for existing templates and shows diff"""
152141
if not dest.exists():

exasol/toolbox/tools/workflow.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pathlib import Path
2+
23
import typer
4+
35
from exasol.toolbox.tools import template
46

57
CLI = typer.Typer()
@@ -23,7 +25,9 @@ def show_workflow(
2325
workflow: str = typer.Argument(..., help="Workflow which shall be shown."),
2426
) -> None:
2527
"""Shows a specific workflow."""
26-
template.show_templates(template=workflow, pkg=PKG, template_type=TEMPLATE_TYPE, lexer=LEXER)
28+
template.show_templates(
29+
template=workflow, pkg=PKG, template_type=TEMPLATE_TYPE, lexer=LEXER
30+
)
2731

2832

2933
@CLI.command(name="diff")
@@ -35,7 +39,9 @@ def diff_workflow(
3539
),
3640
) -> None:
3741
"""Diff a specific workflow against the installed one."""
38-
template.diff_template(template=workflow, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE)
42+
template.diff_template(
43+
template=workflow, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE
44+
)
3945

4046

4147
@CLI.command(name="install")
@@ -50,7 +56,9 @@ def install_workflow(
5056
5157
Attention: If there is an existing workflow with the same name it will be overwritten!
5258
"""
53-
template.install_template(template=workflow, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE)
59+
template.install_template(
60+
template=workflow, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE
61+
)
5462

5563

5664
@CLI.command(name="update")
@@ -64,7 +72,13 @@ def update_workflow(
6472
),
6573
) -> None:
6674
"""Similar to install but checks for existing workflows and shows diff"""
67-
template.update_template(template=workflow, dest=dest, confirm=confirm, pkg=PKG, template_type=TEMPLATE_TYPE)
75+
template.update_template(
76+
template=workflow,
77+
dest=dest,
78+
confirm=confirm,
79+
pkg=PKG,
80+
template_type=TEMPLATE_TYPE,
81+
)
6882

6983

7084
if __name__ == "__main__":

test/unit/deny_filter_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
from exasol.toolbox.nox._shared import _deny_filter
7+
8+
9+
@pytest.fixture
10+
def directory_tree(tmp_path):
11+
directories = {
12+
"d1": ["d1-f1.txt", "d1-f2.py"],
13+
"d2": ["d2-f1.txt", "d2-f2.py"],
14+
".d3": [".d3-f1.txt", ".d3-f2.py"],
15+
}
16+
file_list = []
17+
for directory, files in directories.items():
18+
directory_path = tmp_path / directory
19+
directory_path.mkdir()
20+
for file_name in files:
21+
file_path = directory_path / file_name
22+
file_path.touch()
23+
file_list.append(file_path)
24+
25+
yield tmp_path, file_list
26+
27+
28+
@pytest.mark.parametrize(
29+
"deny_list,expected",
30+
[
31+
(["d1"], {"d2-f1.txt", "d2-f2.py", ".d3-f1.txt", ".d3-f2.py"}),
32+
(["d2"], {"d1-f1.txt", "d1-f2.py", ".d3-f1.txt", ".d3-f2.py"}),
33+
([".d3"], {"d1-f1.txt", "d1-f2.py", "d2-f1.txt", "d2-f2.py"}),
34+
(["d1", "d2"], {".d3-f1.txt", ".d3-f2.py"}),
35+
(["d2", ".d3"], {"d1-f1.txt", "d1-f2.py"}),
36+
(["d1", ".d3"], {"d2-f1.txt", "d2-f2.py"}),
37+
(["d1", "d2", ".d3"], set()),
38+
],
39+
)
40+
def test_deny_filter(directory_tree, deny_list, expected):
41+
_, files = directory_tree
42+
actual = {f.name for f in _deny_filter(files, deny_list)}
43+
assert actual == expected

test/unit/template_test.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from pathlib import Path
21
import os
2+
from pathlib import Path
3+
34
import pytest
45

56
from exasol.toolbox.tools import template
@@ -41,28 +42,28 @@ def test_retrieve_issue_templates():
4142
"subpackage,expected",
4243
[
4344
(
44-
"exasol.toolbox.templates.github.workflows",
45-
{
46-
"build-and-publish": "build-and-publish.yml",
47-
"check-release-tag": "check-release-tag.yml",
48-
"checks": "checks.yml",
49-
"ci-cd": "ci-cd.yml",
50-
"ci": "ci.yml",
51-
"gh-pages": "gh-pages.yml",
52-
"pr-merge": "pr-merge.yml",
53-
"report": "report.yml",
54-
},
45+
"exasol.toolbox.templates.github.workflows",
46+
{
47+
"build-and-publish": "build-and-publish.yml",
48+
"check-release-tag": "check-release-tag.yml",
49+
"checks": "checks.yml",
50+
"ci-cd": "ci-cd.yml",
51+
"ci": "ci.yml",
52+
"gh-pages": "gh-pages.yml",
53+
"pr-merge": "pr-merge.yml",
54+
"report": "report.yml",
55+
},
5556
),
5657
(
57-
"exasol.toolbox.templates.github.ISSUE_TEMPLATE",
58-
{
59-
"blank": "blank.md",
60-
"bug": "bug.md",
61-
"documentation": "documentation.md",
62-
"feature": "feature.md",
63-
"refactoring": "refactoring.md",
64-
"security": "security.md",
65-
},
58+
"exasol.toolbox.templates.github.ISSUE_TEMPLATE",
59+
{
60+
"blank": "blank.md",
61+
"bug": "bug.md",
62+
"documentation": "documentation.md",
63+
"feature": "feature.md",
64+
"refactoring": "refactoring.md",
65+
"security": "security.md",
66+
},
6667
),
6768
],
6869
)
@@ -78,7 +79,7 @@ def test_retrieve_templates(subpackage, expected):
7879
(
7980
"all",
8081
"exasol.toolbox.templates.github.ISSUE_TEMPLATE",
81-
"issue",
82+
"issue",
8283
[
8384
"blank.md",
8485
"bug.md",
@@ -103,7 +104,7 @@ def test_retrieve_templates(subpackage, expected):
103104
"report.yml",
104105
],
105106
),
106-
]
107+
],
107108
)
108109
def test_install_templates(templates, pkg, template_type, expected, tmp_path):
109110
template.install_template(templates, tmp_path, pkg, template_type)

0 commit comments

Comments
 (0)