Skip to content

Commit d2c7979

Browse files
add format check
1 parent 38905d2 commit d2c7979

File tree

13 files changed

+76
-44
lines changed

13 files changed

+76
-44
lines changed

.github/workflows/checks.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ jobs:
117117
path: .security.json
118118
include-hidden-files: true
119119

120+
Format:
121+
name: Format Check (Python-${{ matrix.python-version }})
122+
needs: [ Version-Check ]
123+
runs-on: ubuntu-latest
124+
strategy:
125+
fail-fast: false
126+
matrix:
127+
python-version: [ "3.9" ]
128+
129+
steps:
130+
- name: SCM Checkout
131+
uses: actions/checkout@v4
132+
133+
- name: Setup Python & Poetry Environment
134+
uses: ./.github/actions/python-environment
135+
with:
136+
python-version: ${{ matrix.python-version }}
137+
138+
- name: Run format check
139+
run: poetry run nox -s project:format
140+
120141
Tests:
121142
name: Unit-Tests (Python-${{ matrix.python-version }}, Exasol-${{ matrix.exasol-version}})
122143
needs: [ Documentation, Lint, Type-Check, Security]

exasol/toolbox/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import subprocess
2-
from typing import Iterable
2+
from collections.abc import Iterable
33

44

55
def tags() -> Iterable[str]:

exasol/toolbox/metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def security(file: Union[str, Path]) -> Rating:
151151
return Rating.bandit_rating(_bandit_scoring(security_lint["results"]))
152152

153153

154-
def _bandit_scoring(ratings: List[Dict[str, Any]]) -> float:
154+
def _bandit_scoring(ratings: list[dict[str, Any]]) -> float:
155155
def char(value: str, default: str = "H") -> str:
156156
if value in ["HIGH", "MEDIUM", "LOW"]:
157157
return value[0]
@@ -258,7 +258,7 @@ def _json(report: Report) -> str:
258258
def identity(obj: Any) -> Any:
259259
return obj
260260

261-
transformation: Dict[type, Callable[[Any], Any]] = defaultdict(
261+
transformation: dict[type, Callable[[Any], Any]] = defaultdict(
262262
lambda: identity,
263263
{
264264
Rating: lambda value: f"{value:n}",

exasol/toolbox/nox/_format.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Iterable
3+
from collections.abc import Iterable
44

55
import nox
66
from nox import Session
@@ -27,7 +27,7 @@ def _pyupgrade(session: Session, files: Iterable[str]) -> None:
2727
"poetry",
2828
"run",
2929
"pyupgrade",
30-
"--py38-plus",
30+
"--py39-plus",
3131
"--exit-zero-even-if-changed",
3232
*files,
3333
)
@@ -40,3 +40,9 @@ def fix(session: Session) -> None:
4040
_version(session, Mode.Fix, PROJECT_CONFIG.version_file)
4141
_pyupgrade(session, py_files)
4242
_code_format(session, Mode.Fix, py_files)
43+
44+
45+
@nox.session(name="project:format", python=False)
46+
def fmt_check(session: Session) -> None:
47+
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
48+
_code_format(session=session, mode=Mode.Check, files=py_files)

exasol/toolbox/nox/_lint.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Dict,
88
Iterable,
99
List,
10+
Dict
1011
)
1112

1213
import nox
@@ -17,6 +18,11 @@
1718
from exasol.toolbox.nox._shared import python_files
1819
from noxconfig import PROJECT_CONFIG
1920

21+
from pathlib import Path
22+
import rich.console
23+
import tomlkit
24+
import sys
25+
2026

2127
def _pylint(session: Session, files: Iterable[str]) -> None:
2228
session.run(
@@ -79,23 +85,26 @@ def _import_lint(session: Session, path: Path) -> None:
7985

8086

8187
class Dependencies:
82-
def __init__(self, illegal: dict[str, list[str]] | None):
88+
def __init__(self, illegal: Dict[str, List[str]] | None):
8389
self._illegal = illegal or {}
8490

8591
@staticmethod
86-
def parse(pyproject_toml: str) -> Dependencies:
92+
def parse(pyproject_toml: str) -> "Dependencies":
8793
def _source_filter(version) -> bool:
88-
ILLEGAL_SPECIFIERS = ["url", "git", "path"]
89-
return any(specifier in version for specifier in ILLEGAL_SPECIFIERS)
94+
ILLEGAL_SPECIFIERS = ['url', 'git', 'path']
95+
return any(
96+
specifier in version
97+
for specifier in ILLEGAL_SPECIFIERS
98+
)
9099

91-
def find_illegal(part) -> list[str]:
100+
def find_illegal(part) -> List[str]:
92101
return [
93102
f"{name} = {version}"
94103
for name, version in part.items()
95104
if _source_filter(version)
96105
]
97106

98-
illegal: dict[str, list[str]] = {}
107+
illegal: Dict[str, List[str]] = {}
99108
toml = tomlkit.loads(pyproject_toml)
100109
poetry = toml.get("tool", {}).get("poetry", {})
101110

@@ -115,11 +124,11 @@ def find_illegal(part) -> list[str]:
115124
return Dependencies(illegal)
116125

117126
@property
118-
def illegal(self) -> dict[str, list[str]]:
127+
def illegal(self) -> Dict[str, List[str]]:
119128
return self._illegal
120129

121130

122-
def report_illegal(illegal: dict[str, list[str]], console: rich.console.Console):
131+
def report_illegal(illegal: Dict[str, List[str]], console: rich.console.Console):
123132
count = sum(len(deps) for deps in illegal.values())
124133
suffix = "y" if count == 1 else "ies"
125134
console.print(f"{count} illegal dependenc{suffix}\n", style="red")
@@ -148,7 +157,7 @@ def type_check(session: Session) -> None:
148157
def security_lint(session: Session) -> None:
149158
"""Runs the security linter on the project"""
150159
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
151-
_security_lint(session, py_files)
160+
_security_lint(session, list(filter(lambda file: "test" not in file, py_files)))
152161

153162

154163
@nox.session(name="lint:dependencies", python=False)

exasol/toolbox/nox/_shared.py

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

33
import argparse
4+
from collections import ChainMap
5+
from collections.abc import (
6+
Iterable,
7+
MutableMapping,
8+
)
49
from enum import (
510
Enum,
611
auto,
712
)
813
from pathlib import Path
9-
from typing import (
10-
Any,
11-
ChainMap,
12-
Iterable,
13-
MutableMapping,
14-
)
14+
from typing import Any
1515

1616
from nox import Session
1717

exasol/toolbox/nox/_test.py

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

3-
from pathlib import Path
4-
from typing import (
5-
Any,
3+
from collections.abc import (
64
Iterable,
75
MutableMapping,
86
)
7+
from pathlib import Path
8+
from typing import Any
99

1010
import nox
1111
from nox import Session

exasol/toolbox/pre_commit_hooks/package_version.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
Namespace,
66
)
77
from collections import namedtuple
8+
from collections.abc import Iterable
89
from inspect import cleandoc
910
from pathlib import Path
1011
from shutil import which
1112
from typing import (
1213
Any,
1314
Dict,
14-
Iterable,
1515
Union,
1616
)
1717

@@ -49,8 +49,8 @@ class CommitHookError(Exception):
4949
def version_from_python_module(path: Path) -> Version:
5050
"""Retrieve version information from the `version` module"""
5151
with open(path, encoding="utf-8") as file:
52-
_locals: Dict[str, Any] = {}
53-
_globals: Dict[str, Any] = {}
52+
_locals: dict[str, Any] = {}
53+
_globals: dict[str, Any] = {}
5454
exec(file.read(), _locals, _globals)
5555

5656
try:

exasol/toolbox/templates/noxconfig.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from __future__ import annotations
22

3+
from collections.abc import MutableMapping
34
from dataclasses import dataclass
45
from pathlib import Path
5-
from typing import (
6-
Any,
7-
MutableMapping,
8-
)
6+
from typing import Any
97

108
from nox import Session
119

exasol/toolbox/tools/replace_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def update_version(line, version):
2525
return f"{keep}{updated}"
2626

2727

28-
def update_versions(lines, matcher, version) -> List[str]:
28+
def update_versions(lines, matcher, version) -> list[str]:
2929
result = []
3030
for line in lines:
3131
if is_update_required(line, matcher):

0 commit comments

Comments
 (0)