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 verify dependency declarations #236

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
13e9f39
add dependancy_check.py + test
Jannis-Mittenzwei Aug 15, 2024
d96fb65
fix dependancy_check.py
Jannis-Mittenzwei Aug 20, 2024
da4854e
add output for problematic dependencies
Jannis-Mittenzwei Aug 20, 2024
767e38c
output changed
Jannis-Mittenzwei Aug 21, 2024
1ffe47d
add nox task + test
Jannis-Mittenzwei Sep 3, 2024
4e13573
fix f-string new line problem
Jannis-Mittenzwei Sep 3, 2024
9c33b61
Merge branch 'main' into feature/#233-add-nox-task-to-verify-dependen…
Jannis-Mittenzwei Sep 3, 2024
6d14d58
new version
Jannis-Mittenzwei Sep 3, 2024
21a7aff
new version
Jannis-Mittenzwei Sep 3, 2024
b7c04a8
Merge remote-tracking branch 'origin/feature/#233-add-nox-task-to-ver…
Jannis-Mittenzwei Sep 3, 2024
7b88101
new version
Jannis-Mittenzwei Sep 3, 2024
5f41253
resolves the conversations
Jannis-Mittenzwei Sep 11, 2024
06d6594
fix type error
Jannis-Mittenzwei Sep 17, 2024
1757ed0
add capsys to dependencies check test
Jannis-Mittenzwei Sep 17, 2024
f48801b
Merge branch 'main' into feature/#233-add-nox-task-to-verify-dependen…
Jannis-Mittenzwei Sep 24, 2024
2a11ca0
resolves the conversations
Jannis-Mittenzwei Sep 24, 2024
836ab35
Merge branch 'main' into feature/#233-add-nox-task-to-verify-dependen…
Jannis-Mittenzwei Sep 24, 2024
5414dd7
Merge branch 'main' into feature/#233-add-nox-task-to-verify-dependen…
Jannis-Mittenzwei Sep 25, 2024
cbd41da
update changelog
Jannis-Mittenzwei Sep 25, 2024
44d6cd5
resolves the conversations
Jannis-Mittenzwei Sep 25, 2024
ca17f92
Merge branch 'main' into feature/#233-add-nox-task-to-verify-dependen…
Jannis-Mittenzwei Oct 18, 2024
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
69 changes: 69 additions & 0 deletions exasol/toolbox/nox/_dependencies_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import tomlkit
import sys
from pathlib import Path
import nox
from nox import Session


FILTERS = ['url', 'git', 'path']
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved


@nox.session(name="dependencies-check", python=False)
def dependency_check(session: Session):
file = Path("pyproject.toml")
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
sys.exit(_dependencies_check(file.read_text()))
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved


def _source_filter(version, filters):
output = None
if isinstance(version, dict):
for key in version.keys():
if key in filters:
output = key
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
return output


def _dependencies_check(string: str):
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
toml = tomlkit.loads(string)
dependencies: list = []
dev_dependencies: list = []
group_dependencies: dict = {}
if "tool" in toml:
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
if "poetry" in toml["tool"].unwrap():
if "dependencies" in toml["tool"].unwrap()["poetry"]:
for name, version in toml["tool"].unwrap()["poetry"]["dependencies"].items():
key = _source_filter(version, FILTERS)
if key:
dependencies.append(f"{name} = {version}")

if "dev" in toml["tool"].unwrap()["poetry"]:
if "dependencies" in toml["tool"].unwrap()["poetry"]["dev"]:
for name, version in toml["tool"].unwrap()["poetry"]["dev"]["dependencies"].items():
key = _source_filter(version, FILTERS)
if key:
dev_dependencies.append(f"{name} = {version}")
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved

if "group" in toml["tool"].unwrap()["poetry"]:
for group in toml["tool"].unwrap()["poetry"]["group"]:
if "dependencies" in toml["tool"].unwrap()["poetry"]["group"][group]:
for name, version in toml["tool"].unwrap()["poetry"]["group"][group]["dependencies"].items():
key = _source_filter(version, FILTERS)
if key:
if f'[tool.poetry.group.{group}.dependencies]' not in group_dependencies:
group_dependencies[f'[tool.poetry.group.{group}.dependencies]'] = []
group_dependencies[f'[tool.poetry.group.{group}.dependencies]'].append(f"{name} = {version}")

if dependencies or dev_dependencies or group_dependencies:
l = len(dependencies)
m = len(dev_dependencies)
n = 0
for _, dependency in group_dependencies.items():
n += len(dependency)
suffix = "y" if l+m+n == 1 else "ies"
output = f"{l+m+n} illegal dependenc{suffix}:{chr(10)}"
output += ("\n[tool.poetry.dependencies]\n"+"\n".join(dependencies)+"\n") if l > 0 else ""
output += ("\n[tool.poetry.dev.dependencies]\n"+"\n".join(dev_dependencies)+"\n") if m > 0 else ""
output += ("\n".join(f"{chr(10)}{key}{chr(10)}{chr(10).join(value)}"for key, value in group_dependencies.items())) if n > 0 else ""
output += "\n"
return output
return 0
3 changes: 3 additions & 0 deletions exasol/toolbox/nox/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
integration_tests,
unit_tests,
)
from exasol.toolbox.nox._dependencies_check import (
dependency_check
)
from noxconfig import PROJECT_CONFIG


Expand Down
79 changes: 79 additions & 0 deletions test/unit/dependencies_check_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from tomlkit import loads
import pytest
from exasol.toolbox.nox._dependencies_check import (
_source_filter,
_dependencies_check
)
import pathlib


@pytest.mark.parametrize(
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
"filters,source,expected",
[
(
['url', 'git', 'path'],
"""example-url = {url = "https://example.com/my-package-0.1.0.tar.gz"}""",
'url'),
(
['url', 'git', 'path'],
"""example-git = {git = "[email protected]:requests/requests.git"}""",
'git'),
(
['url', 'git', 'path'],
"""example-path = {path = "../my-package/dist/my-package-0.1.0.tar.gz"}""",
'path'),
(
['url', 'git', 'path'],
"""example-url = {platform = "darwin", url = "https://example.com/my-package-0.1.0.tar.gz"}""",
'url'),
(
['url', 'git', 'path'],
"""example = "^2.31.0.6" """,
None),
(
['url', 'git', 'path'],
"""python = ">=3.8.0,<4.0" """,
None
)
]
)
def test_dependencies_check(filters, source, expected):
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
for _, version in loads(source).items():
assert _source_filter(version, filter) == expected


@pytest.mark.parametrize(
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
"toml, expected",
[
(
"""[tool.poetry.dependencies]
python = "^3.8"
example-url = {url = "https://example.com/my-package-0.1.0.tar.gz"}

[tool.poetry.dev.dependencies]
nox = ">=2022.8.7"

[tool.poetry.group.test.dependencies]
sphinx = ">=5.3,<8"
example-git = {git = "[email protected]:requests/requests.git"}

[tool.poetry.group.dev.dependencies]
pytest = ">=7.2.2,<9"
example-path = {path = "../my-package/dist/my-package-0.1.0.tar.gz"}
""",
"""3 illegal dependencies:

[tool.poetry.dependencies]
example-url = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}

[tool.poetry.group.test.dependencies]
example-git = {'git': '[email protected]:requests/requests.git'}

[tool.poetry.group.dev.dependencies]
example-path = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}
"""
),
]
)
def test_dependencies_check(toml, expected):
assert _dependencies_check(toml) == expected
Loading