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 support for import linter to lint tasks #227

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
poetry.lock linguist-generated=true
2 changes: 2 additions & 0 deletions .import_linter_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[importlinter]
root_package = exasol.toolbox
1 change: 1 addition & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## ✨ Added

* Added cookiecutter-template for creating new project
* #149: Added import linter and nox task for it
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved

## 🔩 Internal

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

from typing import Iterable
import argparse
from pathlib import Path

import nox
from nox import Session
Expand Down Expand Up @@ -64,6 +66,16 @@ def _security_lint(session: Session, files: Iterable[str]) -> None:
)


def _import_lint(session: Session, path: Path) -> None:
session.run(
"poetry",
"run",
"lint-imports",
"--config",
path
)


@nox.session(python=False)
def lint(session: Session) -> None:
"""Runs the linter on the project"""
Expand All @@ -83,3 +95,33 @@ def security_lint(session: Session) -> None:
"""Runs the security linter on the project"""
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
_security_lint(session, list(filter(lambda file: "test" not in file, py_files)))


@nox.session(name="import-lint", python=False)
def import_lint(session: Session) -> None:
"""Runs the import linter on the project"""
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
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)

1 change: 1 addition & 0 deletions noxconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Config:

root: Path = Path(__file__).parent
doc: Path = Path(__file__).parent / "doc"
importlinter: Path = Path(__file__).parent / ".import_linter_config"
version_file: Path = Path(__file__).parent / "exasol" / "toolbox" / "version.py"
path_filters: Iterable[str] = ("dist", ".eggs", "venv", "metrics-schema", "project-template", "idioms")
plugins = [UpdateTemplates]
Expand Down
132 changes: 131 additions & 1 deletion poetry.lock
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ black = ">=24.1.0"
coverage = ">=6.4.4,<8.0.0"
furo = ">=2022.9.15"
importlib-resources = ">=5.12.0"
import-linter = "^2.0"
isort = "^5.12.0"
mypy = ">=0.971"
myst-parser = ">=2.0.0,<4"
Expand Down