|
10 | 10 |
|
11 | 11 | import ast
|
12 | 12 | from configparser import ConfigParser
|
| 13 | +import copy |
13 | 14 | import json
|
14 | 15 | import logging
|
15 | 16 | from pathlib import Path
|
@@ -921,7 +922,7 @@ def get_requirements_txt_dependencies(location, include_nested=False):
|
921 | 922 | if req.name:
|
922 | 923 | # will be None if not pinned
|
923 | 924 | 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) |
925 | 926 |
|
926 | 927 | else:
|
927 | 928 | # this is odd, but this can be null
|
@@ -954,12 +955,41 @@ def get_requirements_txt_dependencies(location, include_nested=False):
|
954 | 955 | is_optional=is_optional,
|
955 | 956 | is_resolved=req.is_pinned or False,
|
956 | 957 | 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 | + ), |
957 | 970 | )
|
958 | 971 | )
|
959 | 972 |
|
960 | 973 | return dependent_packages, extra_data
|
961 | 974 |
|
962 | 975 |
|
| 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 | + |
963 | 993 | def get_attribute(metainfo, name, multiple=False):
|
964 | 994 | """
|
965 | 995 | Return the value for the attribute ``name`` in the ``metainfo`` mapping,
|
|
0 commit comments