diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index f8092cb65..d30e29caf 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -5,4 +5,8 @@ * #940: Added shared validation for packaged agent skills and the `skills:check` Nox session. * #938: Added the `skills:install` Nox session for installing the packaged PTB agent skill. * #942: Added api-contract-audit skill for identifying mismatches between type annotations, docstrings, and runtime - behavior \ No newline at end of file + behavior + +## Refactoring + +* #924: Removed the deprecated `lint:dependencies` Nox session and its unused implementation and tests. diff --git a/exasol/toolbox/nox/_lint.py b/exasol/toolbox/nox/_lint.py index 82d3f4e77..a63ebb941 100644 --- a/exasol/toolbox/nox/_lint.py +++ b/exasol/toolbox/nox/_lint.py @@ -1,22 +1,13 @@ from __future__ import annotations -import sys from collections.abc import Iterable -from pathlib import Path import nox -import rich.console -import tomlkit from nox import Session from exasol.toolbox.nox._shared import get_filtered_python_files -from exasol.toolbox.util.dependencies.shared_models import PoetryFiles from noxconfig import PROJECT_CONFIG -# The relevant nox session will be removed in: -# https://github.com/exasol/python-toolbox/issues/924 -LINT_DEPENDENCIES_DEPRECATION_DATE = "2026-10-08" - def _pylint(session: Session, files: Iterable[str]) -> None: json_file = PROJECT_CONFIG.root_path / ".lint.json" @@ -66,58 +57,6 @@ def _security_lint(session: Session, files: Iterable[str]) -> None: ) -class Dependencies: - def __init__(self, illegal: dict[str, list[str]] | None): - self._illegal = illegal or {} - - @staticmethod - def parse(pyproject_toml: str) -> Dependencies: - def _source_filter(version) -> bool: - ILLEGAL_SPECIFIERS = ["url", "git", "path"] - return any(specifier in version for specifier in ILLEGAL_SPECIFIERS) - - def find_illegal(part) -> list[str]: - return [ - f"{name} = {version}" - for name, version in part.items() - if _source_filter(version) - ] - - illegal: dict[str, list[str]] = {} - toml = tomlkit.loads(pyproject_toml) - poetry = toml.get("tool", {}).get("poetry", {}) - - part = poetry.get("dependencies", {}) - if illegal_group := find_illegal(part): - illegal["tool.poetry.dependencies"] = illegal_group - - part = poetry.get("dev", {}).get("dependencies", {}) - if illegal_group := find_illegal(part): - illegal["tool.poetry.dev.dependencies"] = illegal_group - - part = poetry.get("group", {}) - for group, content in part.items(): - illegal_group = find_illegal(content.get("dependencies", {})) - if illegal_group: - illegal[f"tool.poetry.group.{group}.dependencies"] = illegal_group - return Dependencies(illegal) - - @property - def illegal(self) -> dict[str, list[str]]: - return self._illegal - - -def report_illegal(illegal: dict[str, list[str]], console: rich.console.Console): - count = sum(len(deps) for deps in illegal.values()) - suffix = "y" if count == 1 else "ies" - console.print(f"{count} illegal dependenc{suffix}\n", style="red") - for section, dependencies in illegal.items(): - console.print(f"\\[{section}]", style="red") - for dependency in dependencies: - console.print(dependency, style="red") - console.print("") - - @nox.session(name="lint:code", python=False) def lint(session: Session) -> None: """Runs the static code analyzer on the project""" @@ -137,18 +76,3 @@ def security_lint(session: Session) -> None: """Runs the security linter on the project""" py_files = get_filtered_python_files(PROJECT_CONFIG.source_code_path) _security_lint(session=session, files=py_files) - - -@nox.session(name="lint:dependencies", python=False) -def dependency_check(session: Session) -> None: - """Checks if only valid sources of dependencies are used""" - content = Path(PROJECT_CONFIG.root_path, PoetryFiles.pyproject_toml).read_text() - dependencies = Dependencies.parse(content) - console = rich.console.Console() - if illegal := dependencies.illegal: - report_illegal(illegal, console) - sys.exit(1) - session.warn( - f"Warning: `nox -s lint:dependencies` is deprecated and will be removed on " - f"{LINT_DEPENDENCIES_DEPRECATION_DATE}." - ) diff --git a/test/unit/dependencies_check_test.py b/test/unit/dependencies_check_test.py deleted file mode 100644 index 617a4f1a6..000000000 --- a/test/unit/dependencies_check_test.py +++ /dev/null @@ -1,174 +0,0 @@ -import pytest -import rich.console - -from exasol.toolbox.nox._lint import ( - Dependencies, - report_illegal, -) - - -@pytest.mark.parametrize( - "toml,expected", - [ - ( - """ - """, - {}, - ), - ( - """ -[tool.poetry.dependencies] -python = "^3.8" -example-url1 = {url = "https://example.com/my-package-0.1.0.tar.gz"} - -[tool.poetry.dev.dependencies] -nox = ">=2022.8.7" -example-url2 = {url = "https://example.com/my-package-0.2.0.tar.gz"} - -[tool.poetry.group.test.dependencies] -sphinx = ">=5.3,<8" -example-git = {git = "git@github.com:requests/requests.git"} - -[tool.poetry.group.dev.dependencies] -pytest = ">=7.2.2,<9" -example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"} - """, - { - "tool.poetry.dependencies": [ - "example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}" - ], - "tool.poetry.dev.dependencies": [ - "example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}" - ], - "tool.poetry.group.test.dependencies": [ - "example-git = {'git': 'git@github.com:requests/requests.git'}" - ], - "tool.poetry.group.dev.dependencies": [ - "example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}" - ], - }, - ), - ( - """ -[tool.poetry.dev.dependencies] -nox = ">=2022.8.7" -example-url2 = {url = "https://example.com/my-package-0.2.0.tar.gz"} - -[tool.poetry.group.test.dependencies] -sphinx = ">=5.3,<8" -example-git = {git = "git@github.com:requests/requests.git"} - -[tool.poetry.group.dev.dependencies] -pytest = ">=7.2.2,<9" -example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"} - """, - { - "tool.poetry.dev.dependencies": [ - "example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}" - ], - "tool.poetry.group.test.dependencies": [ - "example-git = {'git': 'git@github.com:requests/requests.git'}" - ], - "tool.poetry.group.dev.dependencies": [ - "example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}" - ], - }, - ), - ( - """ -[tool.poetry.dependencies] -python = "^3.8" -example-url1 = {url = "https://example.com/my-package-0.1.0.tar.gz"} - -[tool.poetry.group.test.dependencies] -sphinx = ">=5.3,<8" -example-git = {git = "git@github.com:requests/requests.git"} - -[tool.poetry.group.dev.dependencies] -pytest = ">=7.2.2,<9" -example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"} - """, - { - "tool.poetry.dependencies": [ - "example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}" - ], - "tool.poetry.group.test.dependencies": [ - "example-git = {'git': 'git@github.com:requests/requests.git'}" - ], - "tool.poetry.group.dev.dependencies": [ - "example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}" - ], - }, - ), - ( - """ -[tool.poetry.dependencies] -python = "^3.8" -example-url1 = {url = "https://example.com/my-package-0.1.0.tar.gz"} - -[tool.poetry.dev.dependencies] -nox = ">=2022.8.7" -example-url2 = {url = "https://example.com/my-package-0.2.0.tar.gz"} - """, - { - "tool.poetry.dependencies": [ - "example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}" - ], - "tool.poetry.dev.dependencies": [ - "example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}" - ], - }, - ), - ], -) -def test_dependency_check_parse(toml, expected): - dependencies = Dependencies.parse(toml) - assert dependencies.illegal == expected - - -@pytest.mark.parametrize( - "toml,expected", - [ - ( - """ -[tool.poetry.dependencies] -python = "^3.8" -example-url1 = {url = "https://example.com/my-package-0.1.0.tar.gz"} - -[tool.poetry.dev.dependencies] -nox = ">=2022.8.7" -example-url2 = {url = "https://example.com/my-package-0.2.0.tar.gz"} - -[tool.poetry.group.test.dependencies] -sphinx = ">=5.3,<8" -example-git = {git = "git@github.com:requests/requests.git"} - -[tool.poetry.group.dev.dependencies] -pytest = ">=7.2.2,<9" -example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"} -example-path2 = {path = "../my-package/dist/my-package-0.2.0.tar.gz"} - """, - """5 illegal dependencies - -[tool.poetry.dependencies] -example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'} - -[tool.poetry.dev.dependencies] -example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'} - -[tool.poetry.group.test.dependencies] -example-git = {'git': 'git@github.com:requests/requests.git'} - -[tool.poetry.group.dev.dependencies] -example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'} -example-path2 = {'path': '../my-package/dist/my-package-0.2.0.tar.gz'} - -""", - ), - ], -) -def test_dependencies_check_report(toml, expected, capsys): - console = rich.console.Console() - dependencies = Dependencies.parse(toml) - report_illegal(dependencies.illegal, console) - assert capsys.readouterr().out == expected