Skip to content

Commit dec9351

Browse files
Cleanup requirement string to avoid packvers parsing issues
Extract clean name and version from requirements instead of using dumps() output that includes hash options and other pip-specific syntax that `packvers.requirements.Requirement` cannot parse. Resolves: #243. Signed-off-by: Marcel Bochtler <marcel.bochtler@bosch.com>
1 parent ff07d0e commit dec9351

File tree

5 files changed

+563
-1
lines changed

5 files changed

+563
-1
lines changed

src/_packagedcode/pypi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def parse(cls, location):
534534
for metapath in path.iterdir():
535535
if not metapath.name.endswith('METADATA'):
536536
continue
537-
537+
538538
yield parse_metadata(
539539
location=metapath,
540540
datasource_id=cls.datasource_id,
@@ -945,6 +945,7 @@ def get_requirements_txt_dependencies(location, include_nested=False):
945945

946946
purl = purl and purl.to_string() or None
947947

948+
req.hash_options = []
948949
requirement = req.dumps()
949950

950951
if location.endswith(

tests/data/hash-requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
addict==2.4.0 \
2+
--hash=sha256:249bb56bbfd3cdc2a004ea0ff4c2b6ddc84d53bc2194761636eb314d5cfa5dfc \
3+
--hash=sha256:b3b2210e0e067a281f5646c8c5db92e99b7231ea8b0eb5f74dbdf9e259d4e494
4+
5+
requests==2.25.1 \
6+
--hash=sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e \
7+
--hash=sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804

0 commit comments

Comments
 (0)