Skip to content

Commit 2449410

Browse files
Add nox task to check format (#280)
1 parent 38905d2 commit 2449410

File tree

15 files changed

+285
-209
lines changed

15 files changed

+285
-209
lines changed

.github/workflows/checks.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,25 @@ jobs:
117117
path: .security.json
118118
include-hidden-files: true
119119

120+
Format:
121+
name: Format Check (Python-${{ matrix.python-version }})
122+
runs-on: ubuntu-latest
123+
124+
steps:
125+
- name: SCM Checkout
126+
uses: actions/checkout@v4
127+
128+
- name: Setup Python & Poetry Environment
129+
uses: ./.github/actions/python-environment
130+
with:
131+
python-version: "3.9"
132+
133+
- name: Run format check
134+
run: poetry run nox -s project:format
135+
120136
Tests:
121137
name: Unit-Tests (Python-${{ matrix.python-version }}, Exasol-${{ matrix.exasol-version}})
122-
needs: [ Documentation, Lint, Type-Check, Security]
138+
needs: [ Documentation, Lint, Type-Check, Security, Format]
123139
runs-on: ubuntu-latest
124140
env:
125141
GITHUB_TOKEN: ${{ secrets.ALTERNATIVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}

doc/changes/unreleased.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Excluded pyupgrade from project check due to its destructive nature
66
* Updated cookiecutter template
77
- removed obsolete template file `version.html`
8+
* Added nox task for format checking
9+
* Updated GitHub workflow and workflow template of `checks.yml` to include format check
810

911
## 🐞 Fixed
1012

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ 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+
"""Checks the project for correct formatting"""
48+
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
49+
_code_format(session=session, mode=Mode.Check, files=py_files)

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/github/workflows/checks.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,24 @@ jobs:
123123
path: .security.json
124124
include-hidden-files: true
125125

126+
Format:
127+
name: Format Check (Python-${{ matrix.python-version }})
128+
runs-on: ubuntu-latest
129+
130+
steps:
131+
- name: SCM Checkout
132+
uses: actions/checkout@v4
133+
134+
- name: Setup Python & Poetry Environment
135+
uses: exasol/python-toolbox/.github/actions/python-environment@0.18.0
136+
with:
137+
python-version: "3.9"
138+
- name: Run format check
139+
run: poetry run nox -s project:format
140+
126141
Tests:
127142
name: Unit-Tests (Python-${{ matrix.python-version }}, Exasol-${{ matrix.exasol-version}})
128-
needs: [ Documentation, Lint, Type-Check, Security]
143+
needs: [ Documentation, Lint, Type-Check, Security, Format ]
129144
runs-on: ubuntu-latest
130145
env:
131146
GITHUB_TOKEN: ${{ secrets.ALTERNATIVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}

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

0 commit comments

Comments
 (0)