Skip to content

Commit 9d948f2

Browse files
committed
Apply code formatter
1 parent 4a760ee commit 9d948f2

File tree

4 files changed

+92
-70
lines changed

4 files changed

+92
-70
lines changed

exasol/toolbox/nox/_lint.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
from __future__ import annotations
22

3+
import argparse
4+
import sys
5+
from pathlib import Path
36
from typing import (
7+
Dict,
48
Iterable,
59
List,
6-
Dict
710
)
8-
import argparse
9-
from pathlib import Path
1011

1112
import nox
13+
import rich.console
14+
import tomlkit
1215
from nox import Session
1316

1417
from exasol.toolbox.nox._shared import python_files
1518
from noxconfig import PROJECT_CONFIG
1619

17-
from pathlib import Path
18-
import rich.console
19-
import tomlkit
20-
import sys
21-
2220

2321
def _pylint(session: Session, files: Iterable[str]) -> None:
2422
session.run(
@@ -76,37 +74,28 @@ def _security_lint(session: Session, files: Iterable[str]) -> None:
7674
)
7775

7876

79-
8077
def _import_lint(session: Session, path: Path) -> None:
81-
session.run(
82-
"poetry",
83-
"run",
84-
"lint-imports",
85-
"--config",
86-
path
87-
)
78+
session.run("poetry", "run", "lint-imports", "--config", path)
79+
8880

8981
class Dependencies:
90-
def __init__(self, illegal: Dict[str, List[str]] | None):
82+
def __init__(self, illegal: dict[str, list[str]] | None):
9183
self._illegal = illegal or {}
9284

9385
@staticmethod
94-
def parse(pyproject_toml: str) -> "Dependencies":
86+
def parse(pyproject_toml: str) -> Dependencies:
9587
def _source_filter(version) -> bool:
96-
ILLEGAL_SPECIFIERS = ['url', 'git', 'path']
97-
return any(
98-
specifier in version
99-
for specifier in ILLEGAL_SPECIFIERS
100-
)
88+
ILLEGAL_SPECIFIERS = ["url", "git", "path"]
89+
return any(specifier in version for specifier in ILLEGAL_SPECIFIERS)
10190

102-
def find_illegal(part) -> List[str]:
91+
def find_illegal(part) -> list[str]:
10392
return [
10493
f"{name} = {version}"
10594
for name, version in part.items()
10695
if _source_filter(version)
10796
]
10897

109-
illegal: Dict[str, List[str]] = {}
98+
illegal: dict[str, list[str]] = {}
11099
toml = tomlkit.loads(pyproject_toml)
111100
poetry = toml.get("tool", {}).get("poetry", {})
112101

@@ -126,11 +115,11 @@ def find_illegal(part) -> List[str]:
126115
return Dependencies(illegal)
127116

128117
@property
129-
def illegal(self) -> Dict[str, List[str]]:
118+
def illegal(self) -> dict[str, list[str]]:
130119
return self._illegal
131120

132121

133-
def report_illegal(illegal: Dict[str, List[str]], console: rich.console.Console):
122+
def report_illegal(illegal: dict[str, list[str]], console: rich.console.Console):
134123
count = sum(len(deps) for deps in illegal.values())
135124
suffix = "y" if count == 1 else "ies"
136125
console.print(f"{count} illegal dependenc{suffix}\n", style="red")
@@ -172,30 +161,33 @@ def dependency_check(session: Session) -> None:
172161
report_illegal(illegal, console)
173162
sys.exit(1)
174163

164+
175165
@nox.session(name="lint:import", python=False)
176166
def import_lint(session: Session) -> None:
177167
"""(experimental) Runs import linter on the project"""
178168
parser = argparse.ArgumentParser(
179169
usage="nox -s import-lint -- [options]",
180-
description="Runs the import linter on the project"
170+
description="Runs the import linter on the project",
181171
)
182172
parser.add_argument(
183173
"-c",
184174
"--config",
185175
type=str,
186176
help="path to the configuration file for the importlinter",
187-
metavar="TEXT"
177+
metavar="TEXT",
188178
)
189179

190180
args: argparse.Namespace = parser.parse_args(args=session.posargs)
191181
file: str = args.config
192182
path: Path | None = None
193183
if file is None:
194-
path = getattr(PROJECT_CONFIG, "import_linter_config", Path(".import_linter_config"))
184+
path = getattr(
185+
PROJECT_CONFIG, "import_linter_config", Path(".import_linter_config")
186+
)
195187
else:
196188
path = Path(file)
197189
if not path.exists():
198190
session.error(
199191
"Please make sure you have a configuration file for the importlinter"
200192
)
201-
_import_lint(session=session, path=path)
193+
_import_lint(session=session, path=path)

exasol/toolbox/tools/security.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
from enum import Enum
1212
from functools import partial
1313
from inspect import cleandoc
14+
from pathlib import Path
1415
from typing import (
1516
Generator,
1617
Iterable,
1718
Tuple,
1819
)
20+
1921
import typer
20-
from pathlib import Path
2122

2223
stdout = print
2324
stderr = partial(print, file=sys.stderr)
@@ -128,14 +129,16 @@ def from_json(report_str: str, prefix: Path) -> Iterable[SecurityIssue]:
128129
cwe=str(issue["issue_cwe"].get("id", "")),
129130
test_id=issue["test_id"],
130131
description=issue["issue_text"],
131-
references=tuple(references)
132+
references=tuple(references),
132133
)
133134

134135

135136
def issues_to_markdown(issues: Iterable[SecurityIssue]) -> str:
136-
template = cleandoc("""
137+
template = cleandoc(
138+
"""
137139
{header}{rows}
138-
""")
140+
"""
141+
)
139142

140143
def _header():
141144
header = "# Security\n\n"
@@ -153,10 +156,7 @@ def _row(issue):
153156
row = row[:-5] + "|"
154157
return row
155158

156-
return template.format(
157-
header=_header(),
158-
rows="\n".join(_row(i) for i in issues)
159-
)
159+
return template.format(header=_header(), rows="\n".join(_row(i) for i in issues))
160160

161161

162162
def security_issue_title(issue: Issue) -> str:
@@ -217,6 +217,7 @@ def create_security_issue(issue: Issue, project="") -> Tuple[str, str]:
217217
CVE_CLI = typer.Typer()
218218
CLI.add_typer(CVE_CLI, name="cve", help="Work with CVE's")
219219

220+
220221
class Format(str, Enum):
221222
Maven = "maven"
222223

@@ -320,8 +321,10 @@ class PPrintFormats(str, Enum):
320321

321322
@CLI.command(name="pretty-print")
322323
def json_issue_to_markdown(
323-
json_file: typer.FileText = typer.Argument(mode="r", help="json file with issues to convert"),
324-
path: Path = typer.Argument(default=Path("."), help="path to project root")
324+
json_file: typer.FileText = typer.Argument(
325+
mode="r", help="json file with issues to convert"
326+
),
327+
path: Path = typer.Argument(default=Path("."), help="path to project root"),
325328
) -> None:
326329
content = json_file.read()
327330
issues = from_json(content, path.absolute())

test/unit/dependencies_check_test.py

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import pytest
22
import rich.console
33

4-
from exasol.toolbox.nox._lint import Dependencies, report_illegal
4+
from exasol.toolbox.nox._lint import (
5+
Dependencies,
6+
report_illegal,
7+
)
58

69

710
@pytest.mark.parametrize(
@@ -10,7 +13,7 @@
1013
(
1114
"""
1215
""",
13-
{}
16+
{},
1417
),
1518
(
1619
"""
@@ -31,11 +34,19 @@
3134
example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"}
3235
""",
3336
{
34-
"tool.poetry.dependencies": ["example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}"],
35-
"tool.poetry.dev.dependencies": ["example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}"],
36-
"tool.poetry.group.test.dependencies": ["example-git = {'git': '[email protected]:requests/requests.git'}"],
37-
"tool.poetry.group.dev.dependencies": ["example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}"],
38-
}
37+
"tool.poetry.dependencies": [
38+
"example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}"
39+
],
40+
"tool.poetry.dev.dependencies": [
41+
"example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}"
42+
],
43+
"tool.poetry.group.test.dependencies": [
44+
"example-git = {'git': '[email protected]:requests/requests.git'}"
45+
],
46+
"tool.poetry.group.dev.dependencies": [
47+
"example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}"
48+
],
49+
},
3950
),
4051
(
4152
"""
@@ -52,10 +63,16 @@
5263
example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"}
5364
""",
5465
{
55-
"tool.poetry.dev.dependencies": ["example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}"],
56-
"tool.poetry.group.test.dependencies": ["example-git = {'git': '[email protected]:requests/requests.git'}"],
57-
"tool.poetry.group.dev.dependencies": ["example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}"],
58-
}
66+
"tool.poetry.dev.dependencies": [
67+
"example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}"
68+
],
69+
"tool.poetry.group.test.dependencies": [
70+
"example-git = {'git': '[email protected]:requests/requests.git'}"
71+
],
72+
"tool.poetry.group.dev.dependencies": [
73+
"example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}"
74+
],
75+
},
5976
),
6077
(
6178
"""
@@ -72,10 +89,16 @@
7289
example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"}
7390
""",
7491
{
75-
"tool.poetry.dependencies": ["example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}"],
76-
"tool.poetry.group.test.dependencies": ["example-git = {'git': '[email protected]:requests/requests.git'}"],
77-
"tool.poetry.group.dev.dependencies": ["example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}"],
78-
}
92+
"tool.poetry.dependencies": [
93+
"example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}"
94+
],
95+
"tool.poetry.group.test.dependencies": [
96+
"example-git = {'git': '[email protected]:requests/requests.git'}"
97+
],
98+
"tool.poetry.group.dev.dependencies": [
99+
"example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}"
100+
],
101+
},
79102
),
80103
(
81104
"""
@@ -88,11 +111,15 @@
88111
example-url2 = {url = "https://example.com/my-package-0.2.0.tar.gz"}
89112
""",
90113
{
91-
"tool.poetry.dependencies": ["example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}"],
92-
"tool.poetry.dev.dependencies": ["example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}"],
93-
}
94-
)
95-
]
114+
"tool.poetry.dependencies": [
115+
"example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}"
116+
],
117+
"tool.poetry.dev.dependencies": [
118+
"example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}"
119+
],
120+
},
121+
),
122+
],
96123
)
97124
def test_dependency_check_parse(toml, expected):
98125
dependencies = dependencies = Dependencies.parse(toml)
@@ -136,9 +163,9 @@ def test_dependency_check_parse(toml, expected):
136163
example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}
137164
example-path2 = {'path': '../my-package/dist/my-package-0.2.0.tar.gz'}
138165
139-
"""
166+
""",
140167
),
141-
]
168+
],
142169
)
143170
def test_dependencies_check_report(toml, expected, capsys):
144171
console = rich.console.Console()

test/unit/security_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def test_format_jsonl_removes_newline():
410410
"json_file,expected",
411411
[
412412
(
413-
'''{
413+
"""{
414414
"results": [
415415
{
416416
"code": "1 import subprocess\\n2 from typing import Iterable\\n3 \\n",
@@ -434,7 +434,7 @@ def test_format_jsonl_removes_newline():
434434
}
435435
]
436436
}
437-
''',
437+
""",
438438
{
439439
"file_name": "exasol/toolbox/git.py",
440440
"line": 53,
@@ -444,11 +444,11 @@ def test_format_jsonl_removes_newline():
444444
"description": "Consider possible security implications associated with the subprocess module.",
445445
"references": (
446446
"https://bandit.readthedocs.io/en/1.7.10/blacklists/blacklist_imports.html#b404-import-subprocess",
447-
"https://cwe.mitre.org/data/definitions/78.html"
448-
)
449-
}
447+
"https://cwe.mitre.org/data/definitions/78.html",
448+
),
449+
},
450450
)
451-
]
451+
],
452452
)
453453
def test_from_json(json_file, expected):
454454
actual = security.from_json(json_file, pathlib.Path("/home/test/python-toolbox"))
@@ -459,6 +459,6 @@ def test_from_json(json_file, expected):
459459
cwe=expected["cwe"],
460460
test_id=expected["test_id"],
461461
description=expected["description"],
462-
references=expected["references"]
462+
references=expected["references"],
463463
)
464464
assert list(actual) == [expected_issue]

0 commit comments

Comments
 (0)