Skip to content

Commit 146c4e9

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 <[email protected]>
1 parent 3ad3925 commit 146c4e9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/_packagedcode/pypi.py

Lines changed: 7 additions & 2 deletions
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,7 +945,12 @@ def get_requirements_txt_dependencies(location, include_nested=False):
945945

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

948-
requirement = req.dumps()
948+
# Extract clean requirement string without hash options to avoid
949+
# packvers.requirements.Requirement parsing errors
950+
if req.name:
951+
requirement = f"{req.name}{req.specifier or ''}"
952+
else:
953+
requirement = req.dumps()
949954

950955
if location.endswith(
951956
(

0 commit comments

Comments
 (0)