Skip to content

Commit 0accc38

Browse files
authored
Merge pull request #14 from martincjespersen/main
Poetry lock support
2 parents c48d6e4 + a0fbbb8 commit 0accc38

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Supported dependency files:
1717
* `Pipfile`
1818
* `Pipfile.lock`
1919
* `conda.yaml`
20+
* `poetry.lock`
2021

2122
### Installation
2223

dep_license/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"pyproject.toml",
3333
"setup.py",
3434
"conda.yml",
35+
"poetry.lock",
3536
]
3637
PYPYI_URL = "https://pypi.python.org/pypi"
3738
COLUMNS = ["Name", "Meta", "Classifier"]
@@ -130,7 +131,7 @@ def worker(d):
130131
license_class.add("::".join([x.strip() for x in c.split("::")[1:]]))
131132

132133
license_class_str = (
133-
license_class.pop() if len(license_class) == 1 else str(license_class)
134+
license_class.pop() if len(license_class) == 1 else ", ".join(license_class)
134135
)
135136
record.append(license_class_str)
136137

dep_license/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def parse_file(input_file, base_name, dev=False):
3131
elif base_name == "conda.yml":
3232
return parse_conda_yaml_file(input_file)
3333

34+
elif base_name == "poetry.lock":
35+
return parse_poetry_lock_file(input_file)
3436
else:
3537
return parse_req_file(input_file)
3638
except Exception as e:
@@ -93,6 +95,13 @@ def parse_pyproject_file_poetry(input_file):
9395
]
9496

9597

98+
def parse_poetry_lock_file(input_file):
99+
output = []
100+
cf = toml.load(input_file)
101+
output = [pkg["name"] for pkg in cf.get("package", []) if "name" in pkg]
102+
return output
103+
104+
96105
def parse_setup_file(input_file):
97106
output = []
98107
cur_dir = os.getcwd()

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def run(self):
8181
"Programming Language :: Python :: 3.6",
8282
"Programming Language :: Python :: 3.7",
8383
"Programming Language :: Python :: 3.8",
84+
"Programming Language :: Python :: 3.9",
8485
"Topic :: Utilities",
8586
"Topic :: System :: System Shells",
8687
],

tests/test_utils.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,40 @@ def test_parsing_conda_yaml_file(tmpdir):
176176
assert utils.parse_conda_yaml_file(x.strpath) == ["numpy", "pandas"]
177177

178178

179+
def test_parsing_poetry_lock_file(tmpdir):
180+
x = tmpdir.join("poetry.lock")
181+
x.write(
182+
"""
183+
[[package]]
184+
name = "anyio"
185+
version = "3.5.0"
186+
description = "High level compatibility layer for multiple asynchronous event loop implementations"
187+
category = "dev"
188+
optional = false
189+
python-versions = ">=3.6.2"
190+
191+
[[package]]
192+
name = "appnope"
193+
version = "0.1.2"
194+
description = "Disable App Nap on macOS >= 10.9"
195+
category = "dev"
196+
optional = false
197+
python-versions = "*"
198+
"""
199+
)
200+
assert utils.parse_poetry_lock_file(x.strpath) == ["anyio", "appnope"]
201+
202+
179203
@pytest.mark.parametrize(
180-
"f", ("requirements.txt", "pyproject.toml", "Pipfile", "Pipfile.lock", "conda.yml")
204+
"f",
205+
(
206+
"requirements.txt",
207+
"pyproject.toml",
208+
"Pipfile",
209+
"Pipfile.lock",
210+
"conda.yml",
211+
"poetry.lock",
212+
),
181213
)
182214
def test_passing_dependency_file(f, tmpdir):
183215
x = tmpdir.join(f)

0 commit comments

Comments
 (0)