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

Added support to poetry toml #103

Merged
merged 2 commits into from
Apr 28, 2023
Merged
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
28 changes: 18 additions & 10 deletions liccheck/command_line.py
Original file line number Diff line number Diff line change
@@ -455,21 +455,29 @@ def merge_args(args):
}


def generate_requirements_file_from_pyproject(include_dependencies, extra_dependencies):
def generate_requirements_file_from_pyproject(include_dependencies, optional_dependencies):
import tempfile

directory = tempfile.mkdtemp(prefix="liccheck_")
requirements_txt_file = directory + "/requirements.txt"
with open(requirements_txt_file, "w") as f:
project = toml.load("pyproject.toml").get("project", {})
dependencies = project.get("dependencies", []) if include_dependencies else []
optional_dependencies = (
project.get("optional-dependencies", {}) if extra_dependencies else {}
)
for extra_dependency in extra_dependencies:
if extra_dependency in optional_dependencies:
dependencies += optional_dependencies[extra_dependency]
f.write(os.linesep.join(dependencies))
ptoml = toml.load("pyproject.toml")
project = ptoml.get("project", {})
poetry = ptoml.get("tool", {}).get('poetry', {})
dependencies = set()
if include_dependencies:
dependencies |= set(project.get("dependencies", []))
dependencies |= set(d for d, v in poetry.get("dependencies", {}).items()
if d != 'python' and (not isinstance(v, dict) or not v.get('optional')))
if optional_dependencies:
extra_dependency = project.get("optional-dependencies", {})
extra_dependency.update(poetry.get("extras", {}))
if '*' in optional_dependencies:
optional_dependencies = extra_dependency.keys()
for opt in optional_dependencies:
extralist = extra_dependency.get(opt, [])
dependencies |= set(extralist)
f.write(os.linesep.join(sorted(dependencies)))
return requirements_txt_file


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.8.3',
version='0.9.0',

description='Check python packages from requirement.txt and report issues',
long_description=long_description,
69 changes: 69 additions & 0 deletions tests/test_read_strategy.py
Original file line number Diff line number Diff line change
@@ -43,6 +43,13 @@ def test_with_liccheck_section_in_pyproject_toml(self):
"uuid": "1.30"
}

@pytest.mark.usefixtures("pyproject_toml_poetry_in_cwd")
def test_with_poetry_toml(self):
strategy = Strategy.from_pyproject_toml()
assert "python software foundation license" in strategy.AUTHORIZED_LICENSES
assert "gpl v3" in strategy.UNAUTHORIZED_LICENSES


@pytest.fixture
def empty_pyproject_toml_in_cwd(self, tmpdir):
cwd = os.getcwd()
@@ -70,6 +77,68 @@ def pyproject_toml_with_liccheck_section_in_cwd(self, empty_pyproject_toml_in_cw
"""
)

@pytest.fixture
def pyproject_toml_poetry_in_cwd(self, empty_pyproject_toml_in_cwd):
with open("pyproject.toml", "w") as file:
file.write(
"""
[tool.poetry]
name = "liccheck"
version = "0.8.3"
description = "Check python packages from requirement.txt and report issues"
authors = ["Dhatim <[email protected]>"]
license = "Apache Software License"
readme = "README.rst"

[tool.poetry.dependencies]
python = "^3.9"
semantic-version = "^2.10.0"
toml = "^0.10.2"

[tool.poetry.group.dev.dependencies]
pytest = ">=3.6.3"
pytest-cov = "^4.0.0"
python3-openid = "^3.2.0"
pytest-mock = ">=1.10"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
liccheck = 'liccheck.command_line:main'

[tool.liccheck]
authorized_licenses = [
"new BSD",
"BSD license",
"new BDS license",
"simplified BSD",
"Apache",
"Apache 2.0",
"Apache software license",
"gnu LGPL",
"LGPL with exceptions or zpl",
"ISC license",
"ISC license (ISCL)",
"MIT",
"MIT license",
"python software foundation license",
"zpl 2.1"
]
unauthorized_licenses = [
"GPL v3",
"GPL2",
"GNU General Public License v2 or later (GPLv2+)"
]
authorized_packages = [
"uuid: 1.25,>=1.30"
]
dependencies = true
optional_dependencies = ['*']
"""
)


class TestReadStrategy:
@pytest.mark.usefixtures("from_pyproject_toml_raising")