Skip to content

Commit 8ef34e2

Browse files
committed
Merge branch 'main' of https://github.com/nexB/python-inspector into main
2 parents 0762c7a + 226260d commit 8ef34e2

20 files changed

+2342
-235
lines changed

src/_packagedcode/models.py

+5
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ class DependentPackage(ModelMixin):
373373
'either from the datafile or collected from another source. Some '
374374
'lockfiles for Composer or Cargo contain extra dependency data.'
375375
)
376+
377+
extra_data = Mapping(
378+
label='extra data',
379+
help='A mapping of arbitrary extra data.',
380+
)
376381

377382

378383
@attr.attributes(slots=True)

src/_packagedcode/pypi.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import ast
1212
from configparser import ConfigParser
13+
import copy
1314
import json
1415
import logging
1516
from pathlib import Path
@@ -921,7 +922,7 @@ def get_requirements_txt_dependencies(location, include_nested=False):
921922
if req.name:
922923
# will be None if not pinned
923924
version = req.get_pinned_version
924-
purl = PackageURL(type='pypi', name=req.name, version=version)
925+
purl = PackageURL(type='pypi', name=canonicalize_name(req.name), version=version)
925926

926927
else:
927928
# this is odd, but this can be null
@@ -954,12 +955,41 @@ def get_requirements_txt_dependencies(location, include_nested=False):
954955
is_optional=is_optional,
955956
is_resolved=req.is_pinned or False,
956957
extracted_requirement=requirement,
958+
extra_data=dict(
959+
is_editable=req.is_editable,
960+
link=req.link and req.link.url or None,
961+
hash_options=req.hash_options or [],
962+
is_constraint=req.is_constraint,
963+
is_archive=req.is_archive,
964+
is_wheel=req.is_wheel,
965+
is_url=req.is_url,
966+
is_vcs_url=req.is_vcs_url,
967+
is_name_at_url=req.is_name_at_url,
968+
is_local_path=req.is_local_path,
969+
),
957970
)
958971
)
959972

960973
return dependent_packages, extra_data
961974

962975

976+
def can_process_dependent_package(dep: models.DependentPackage):
977+
"""
978+
Return True if we can process the dependent package
979+
typically anything that's not a plain standard specifier
980+
can not be processed such as an editable requirement
981+
"""
982+
# copying dep.extra_data to avoid mutating the original
983+
requirement_flags = copy.copy(dep.extra_data or {})
984+
requirement_flags.pop("hash_options", None)
985+
if not requirement_flags:
986+
return True
987+
# we can not process the requirement if it has any flag set
988+
# because this means it is not a standard specifier
989+
# but rather some pip specific option of sorts
990+
return not any(requirement_flags.values())
991+
992+
963993
def get_attribute(metainfo, name, multiple=False):
964994
"""
965995
Return the value for the attribute ``name`` in the ``metainfo`` mapping,

0 commit comments

Comments
 (0)