Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nox task to check format #280

Merged
merged 9 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,25 @@ jobs:
path: .security.json
include-hidden-files: true

Format:
name: Format Check (Python-${{ matrix.python-version }})
runs-on: ubuntu-latest

steps:
- name: SCM Checkout
uses: actions/checkout@v4

- name: Setup Python & Poetry Environment
uses: ./.github/actions/python-environment
with:
python-version: "3.9"

- name: Run format check
run: poetry run nox -s project:format

Tests:
name: Unit-Tests (Python-${{ matrix.python-version }}, Exasol-${{ matrix.exasol-version}})
needs: [ Documentation, Lint, Type-Check, Security]
needs: [ Documentation, Lint, Type-Check, Security, Format]
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.ALTERNATIVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Excluded pyupgrade from project check due to its destructive nature
* Updated cookiecutter template
- removed obsolete template file `version.html`
* Added nox task for format checking
* Updated GitHub workflow and workflow template of `checks.yml` to include format check

## 🐞 Fixed

Expand Down
2 changes: 1 addition & 1 deletion exasol/toolbox/git.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import subprocess
from typing import Iterable
from collections.abc import Iterable


def tags() -> Iterable[str]:
Expand Down
4 changes: 2 additions & 2 deletions exasol/toolbox/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def security(file: Union[str, Path]) -> Rating:
return Rating.bandit_rating(_bandit_scoring(security_lint["results"]))


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

transformation: Dict[type, Callable[[Any], Any]] = defaultdict(
transformation: dict[type, Callable[[Any], Any]] = defaultdict(
lambda: identity,
{
Rating: lambda value: f"{value:n}",
Expand Down
7 changes: 7 additions & 0 deletions exasol/toolbox/nox/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ def fix(session: Session) -> None:
_version(session, Mode.Fix, PROJECT_CONFIG.version_file)
_pyupgrade(session, py_files)
_code_format(session, Mode.Fix, py_files)


@nox.session(name="project:format", python=False)
def fmt_check(session: Session) -> None:
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
"""Checks the project for correct formatting"""
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
_code_format(session=session, mode=Mode.Check, files=py_files)
12 changes: 6 additions & 6 deletions exasol/toolbox/nox/_shared.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from __future__ import annotations

import argparse
from collections import ChainMap
from collections.abc import (
Iterable,
MutableMapping,
)
from enum import (
Enum,
auto,
)
from pathlib import Path
from typing import (
Any,
ChainMap,
Iterable,
MutableMapping,
)
from typing import Any

from nox import Session

Expand Down
6 changes: 3 additions & 3 deletions exasol/toolbox/nox/_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

from pathlib import Path
from typing import (
Any,
from collections.abc import (
Iterable,
MutableMapping,
)
from pathlib import Path
from typing import Any

import nox
from nox import Session
Expand Down
6 changes: 3 additions & 3 deletions exasol/toolbox/pre_commit_hooks/package_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Namespace,
)
from collections import namedtuple
from collections.abc import Iterable
from inspect import cleandoc
from pathlib import Path
from shutil import which
from typing import (
Any,
Dict,
Iterable,
Union,
)

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

try:
Expand Down
17 changes: 16 additions & 1 deletion exasol/toolbox/templates/github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,24 @@ jobs:
path: .security.json
include-hidden-files: true

Format:
name: Format Check (Python-${{ matrix.python-version }})
runs-on: ubuntu-latest

steps:
- name: SCM Checkout
uses: actions/checkout@v4

- name: Setup Python & Poetry Environment
uses: exasol/python-toolbox/.github/actions/[email protected]
with:
python-version: "3.9"
- name: Run format check
run: poetry run nox -s project:format

Tests:
name: Unit-Tests (Python-${{ matrix.python-version }}, Exasol-${{ matrix.exasol-version}})
needs: [ Documentation, Lint, Type-Check, Security]
needs: [ Documentation, Lint, Type-Check, Security, Format ]
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.ALTERNATIVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
Expand Down
6 changes: 2 additions & 4 deletions exasol/toolbox/templates/noxconfig.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import annotations

from collections.abc import MutableMapping
from dataclasses import dataclass
from pathlib import Path
from typing import (
Any,
MutableMapping,
)
from typing import Any

from nox import Session

Expand Down
2 changes: 1 addition & 1 deletion exasol/toolbox/tools/replace_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def update_version(line, version):
return f"{keep}{updated}"


def update_versions(lines, matcher, version) -> List[str]:
def update_versions(lines, matcher, version) -> list[str]:
result = []
for line in lines:
if is_update_required(line, matcher):
Expand Down
14 changes: 7 additions & 7 deletions exasol/toolbox/tools/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import re
import subprocess
import sys
from collections.abc import (
Generator,
Iterable,
)
from dataclasses import (
asdict,
dataclass,
Expand All @@ -12,11 +16,7 @@
from functools import partial
from inspect import cleandoc
from pathlib import Path
from typing import (
Generator,
Iterable,
Tuple,
)
from typing import Tuple

import typer

Expand Down Expand Up @@ -48,7 +48,7 @@ def _issues_as_json_str(issues):
yield json.dumps(issue)


def gh_security_issues() -> Generator[Tuple[str, str], None, None]:
def gh_security_issues() -> Generator[tuple[str, str], None, None]:
"""
Yields issue-id, cve-id pairs for all (closed, open) issues associated with CVEs

Expand Down Expand Up @@ -187,7 +187,7 @@ def as_markdown_listing(elements: Iterable[str]):
)


def create_security_issue(issue: Issue, project="") -> Tuple[str, str]:
def create_security_issue(issue: Issue, project="") -> tuple[str, str]:
# fmt: off
command = [
"gh", "issue", "create",
Expand Down
2 changes: 1 addition & 1 deletion exasol/toolbox/tools/template.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import difflib
import io
from collections.abc import Mapping
from contextlib import ExitStack
from pathlib import Path
from typing import (
Any,
Mapping,
Union,
)

Expand Down
2 changes: 1 addition & 1 deletion noxconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from __future__ import annotations

from collections.abc import Iterable
from dataclasses import dataclass
from pathlib import Path
from typing import Iterable

from exasol.toolbox.nox.plugin import hookimpl
from exasol.toolbox.tools.replace_version import update_workflow
Expand Down
Loading