diff --git a/liccheck/command_line.py b/liccheck/command_line.py index f6ec443..ba18007 100644 --- a/liccheck/command_line.py +++ b/liccheck/command_line.py @@ -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 diff --git a/setup.py b/setup.py index 49768c6..3bdb1b8 100644 --- a/setup.py +++ b/setup.py @@ -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, diff --git a/tests/test_read_strategy.py b/tests/test_read_strategy.py index 526b3d7..a7de307 100644 --- a/tests/test_read_strategy.py +++ b/tests/test_read_strategy.py @@ -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 "] + 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")