Skip to content

Commit 28be6a1

Browse files
add format check
1 parent dec6bd3 commit 28be6a1

File tree

15 files changed

+140
-89
lines changed

15 files changed

+140
-89
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: 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: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
from __future__ import annotations
22

3+
import sys
4+
from collections.abc import Iterable
5+
from pathlib import Path
36
from typing import (
4-
Iterable,
7+
Dict,
58
List,
6-
Dict
79
)
810

911
import nox
12+
import rich.console
13+
import tomlkit
1014
from nox import Session
1115

1216
from exasol.toolbox.nox._shared import python_files
1317
from noxconfig import PROJECT_CONFIG
1418

15-
from pathlib import Path
16-
import rich.console
17-
import tomlkit
18-
import sys
19-
2019

2120
def _pylint(session: Session, files: Iterable[str]) -> None:
2221
session.run(
@@ -75,26 +74,23 @@ def _security_lint(session: Session, files: Iterable[str]) -> None:
7574

7675

7776
class Dependencies:
78-
def __init__(self, illegal: Dict[str, List[str]] | None):
77+
def __init__(self, illegal: dict[str, list[str]] | None):
7978
self._illegal = illegal or {}
8079

8180
@staticmethod
82-
def parse(pyproject_toml: str) -> "Dependencies":
81+
def parse(pyproject_toml: str) -> Dependencies:
8382
def _source_filter(version) -> bool:
84-
ILLEGAL_SPECIFIERS = ['url', 'git', 'path']
85-
return any(
86-
specifier in version
87-
for specifier in ILLEGAL_SPECIFIERS
88-
)
83+
ILLEGAL_SPECIFIERS = ["url", "git", "path"]
84+
return any(specifier in version for specifier in ILLEGAL_SPECIFIERS)
8985

90-
def find_illegal(part) -> List[str]:
86+
def find_illegal(part) -> list[str]:
9187
return [
9288
f"{name} = {version}"
9389
for name, version in part.items()
9490
if _source_filter(version)
9591
]
9692

97-
illegal: Dict[str, List[str]] = {}
93+
illegal: dict[str, list[str]] = {}
9894
toml = tomlkit.loads(pyproject_toml)
9995
poetry = toml.get("tool", {}).get("poetry", {})
10096

@@ -114,11 +110,11 @@ def find_illegal(part) -> List[str]:
114110
return Dependencies(illegal)
115111

116112
@property
117-
def illegal(self) -> Dict[str, List[str]]:
113+
def illegal(self) -> dict[str, list[str]]:
118114
return self._illegal
119115

120116

121-
def report_illegal(illegal: Dict[str, List[str]], console: rich.console.Console):
117+
def report_illegal(illegal: dict[str, list[str]], console: rich.console.Console):
122118
count = sum(len(deps) for deps in illegal.values())
123119
suffix = "y" if count == 1 else "ies"
124120
console.print(f"{count} illegal dependenc{suffix}\n", style="red")
@@ -158,4 +154,4 @@ def dependency_check(session: Session) -> None:
158154
console = rich.console.Console()
159155
if illegal := dependencies.illegal:
160156
report_illegal(illegal, console)
161-
sys.exit(1)
157+
sys.exit(1)

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)