Skip to content

Commit befa394

Browse files
author
Olivier Chédru
authored
Merge pull request #103 from prometeia-erm/feature/poetry-tool-dep
Added support to poetry toml
2 parents 7bbdffd + 125730d commit befa394

File tree

3 files changed

+88
-11
lines changed

3 files changed

+88
-11
lines changed

liccheck/command_line.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -455,21 +455,29 @@ def merge_args(args):
455455
}
456456

457457

458-
def generate_requirements_file_from_pyproject(include_dependencies, extra_dependencies):
458+
def generate_requirements_file_from_pyproject(include_dependencies, optional_dependencies):
459459
import tempfile
460460

461461
directory = tempfile.mkdtemp(prefix="liccheck_")
462462
requirements_txt_file = directory + "/requirements.txt"
463463
with open(requirements_txt_file, "w") as f:
464-
project = toml.load("pyproject.toml").get("project", {})
465-
dependencies = project.get("dependencies", []) if include_dependencies else []
466-
optional_dependencies = (
467-
project.get("optional-dependencies", {}) if extra_dependencies else {}
468-
)
469-
for extra_dependency in extra_dependencies:
470-
if extra_dependency in optional_dependencies:
471-
dependencies += optional_dependencies[extra_dependency]
472-
f.write(os.linesep.join(dependencies))
464+
ptoml = toml.load("pyproject.toml")
465+
project = ptoml.get("project", {})
466+
poetry = ptoml.get("tool", {}).get('poetry', {})
467+
dependencies = set()
468+
if include_dependencies:
469+
dependencies |= set(project.get("dependencies", []))
470+
dependencies |= set(d for d, v in poetry.get("dependencies", {}).items()
471+
if d != 'python' and (not isinstance(v, dict) or not v.get('optional')))
472+
if optional_dependencies:
473+
extra_dependency = project.get("optional-dependencies", {})
474+
extra_dependency.update(poetry.get("extras", {}))
475+
if '*' in optional_dependencies:
476+
optional_dependencies = extra_dependency.keys()
477+
for opt in optional_dependencies:
478+
extralist = extra_dependency.get(opt, [])
479+
dependencies |= set(extralist)
480+
f.write(os.linesep.join(sorted(dependencies)))
473481
return requirements_txt_file
474482

475483

setup.py

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

2929
description='Check python packages from requirement.txt and report issues',
3030
long_description=long_description,

tests/test_read_strategy.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ def test_with_liccheck_section_in_pyproject_toml(self):
4343
"uuid": "1.30"
4444
}
4545

46+
@pytest.mark.usefixtures("pyproject_toml_poetry_in_cwd")
47+
def test_with_poetry_toml(self):
48+
strategy = Strategy.from_pyproject_toml()
49+
assert "python software foundation license" in strategy.AUTHORIZED_LICENSES
50+
assert "gpl v3" in strategy.UNAUTHORIZED_LICENSES
51+
52+
4653
@pytest.fixture
4754
def empty_pyproject_toml_in_cwd(self, tmpdir):
4855
cwd = os.getcwd()
@@ -70,6 +77,68 @@ def pyproject_toml_with_liccheck_section_in_cwd(self, empty_pyproject_toml_in_cw
7077
"""
7178
)
7279

80+
@pytest.fixture
81+
def pyproject_toml_poetry_in_cwd(self, empty_pyproject_toml_in_cwd):
82+
with open("pyproject.toml", "w") as file:
83+
file.write(
84+
"""
85+
[tool.poetry]
86+
name = "liccheck"
87+
version = "0.8.3"
88+
description = "Check python packages from requirement.txt and report issues"
89+
authors = ["Dhatim <contact@dhatim.com>"]
90+
license = "Apache Software License"
91+
readme = "README.rst"
92+
93+
[tool.poetry.dependencies]
94+
python = "^3.9"
95+
semantic-version = "^2.10.0"
96+
toml = "^0.10.2"
97+
98+
[tool.poetry.group.dev.dependencies]
99+
pytest = ">=3.6.3"
100+
pytest-cov = "^4.0.0"
101+
python3-openid = "^3.2.0"
102+
pytest-mock = ">=1.10"
103+
104+
[build-system]
105+
requires = ["poetry-core"]
106+
build-backend = "poetry.core.masonry.api"
107+
108+
[tool.poetry.scripts]
109+
liccheck = 'liccheck.command_line:main'
110+
111+
[tool.liccheck]
112+
authorized_licenses = [
113+
"new BSD",
114+
"BSD license",
115+
"new BDS license",
116+
"simplified BSD",
117+
"Apache",
118+
"Apache 2.0",
119+
"Apache software license",
120+
"gnu LGPL",
121+
"LGPL with exceptions or zpl",
122+
"ISC license",
123+
"ISC license (ISCL)",
124+
"MIT",
125+
"MIT license",
126+
"python software foundation license",
127+
"zpl 2.1"
128+
]
129+
unauthorized_licenses = [
130+
"GPL v3",
131+
"GPL2",
132+
"GNU General Public License v2 or later (GPLv2+)"
133+
]
134+
authorized_packages = [
135+
"uuid: 1.25,>=1.30"
136+
]
137+
dependencies = true
138+
optional_dependencies = ['*']
139+
"""
140+
)
141+
73142

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

0 commit comments

Comments
 (0)