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 5 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
23 changes: 22 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,30 @@ jobs:
path: .security.json
include-hidden-files: true

Format:
name: Format Check (Python-${{ matrix.python-version }})
needs: [ Version-Check ]
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.9" ]
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved

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

- name: Setup Python & Poetry Environment
uses: ./.github/actions/python-environment
with:
python-version: ${{ matrix.python-version }}
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved

- 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: 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
10 changes: 8 additions & 2 deletions exasol/toolbox/nox/_format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Iterable
from collections.abc import Iterable

import nox
from nox import Session
Expand All @@ -27,7 +27,7 @@ def _pyupgrade(session: Session, files: Iterable[str]) -> None:
"poetry",
"run",
"pyupgrade",
"--py38-plus",
"--py39-plus",
"--exit-zero-even-if-changed",
*files,
)
Expand All @@ -40,3 +40,9 @@ 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
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
_code_format(session=session, mode=Mode.Check, files=py_files)
33 changes: 1 addition & 32 deletions exasol/toolbox/nox/_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import argparse
import sys
from collections.abc import Iterable
from pathlib import Path
from typing import (
Dict,
Iterable,
List,
)

Expand Down Expand Up @@ -160,34 +160,3 @@ def dependency_check(session: Session) -> None:
if illegal := dependencies.illegal:
report_illegal(illegal, console)
sys.exit(1)


@nox.session(name="lint:import", python=False)
def import_lint(session: Session) -> None:
"""(experimental) Runs import linter on the project"""
parser = argparse.ArgumentParser(
usage="nox -s import-lint -- [options]",
description="Runs the import linter on the project",
)
parser.add_argument(
"-c",
"--config",
type=str,
help="path to the configuration file for the importlinter",
metavar="TEXT",
)

args: argparse.Namespace = parser.parse_args(args=session.posargs)
file: str = args.config
path: Path | None = None
if file is None:
path = getattr(
PROJECT_CONFIG, "import_linter_config", Path(".import_linter_config")
)
else:
path = Path(file)
if not path.exists():
session.error(
"Please make sure you have a configuration file for the importlinter"
)
_import_lint(session=session, path=path)
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
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