MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / parse

Method parse

src/packagedcode/pypi.py:1017–1126  ·  view source on GitHub ↗
(cls, location, package_only=False)

Source from the content-addressed store, hash-verified

1015
1016 @classmethod
1017 def parse(cls, location, package_only=False):
1018 with open(location, "rb") as fp:
1019 toml_data = tomllib.load(fp)
1020
1021 packages = toml_data.get('package')
1022 if not packages:
1023 return
1024
1025 dependencies = []
1026 for package in packages:
1027 source = package.get('source') or {}
1028 # skip the editable root project entry: the local pyproject.toml is
1029 # parsed independently and the resolved transitive dependencies are
1030 # surfaced as their own ``[[package]]`` entries.
1031 if 'editable' in source or 'virtual' in source:
1032 continue
1033
1034 name = package.get('name')
1035 version = package.get('version')
1036 if not name:
1037 continue
1038
1039 dependencies_for_resolved = []
1040 for dep in (package.get('dependencies') or []):
1041 dep_name = dep.get('name')
1042 if not dep_name:
1043 continue
1044 dep_purl = PackageURL(type=cls.default_package_type, name=dep_name)
1045 dependencies_for_resolved.append(
1046 models.DependentPackage(
1047 purl=dep_purl.to_string(),
1048 extracted_requirement=dep.get('marker'),
1049 scope='dependencies',
1050 is_runtime=True,
1051 is_optional=False,
1052 is_direct=True,
1053 is_pinned=False,
1054 ).to_dict()
1055 )
1056
1057 sha256 = None
1058 download_url = None
1059 file_name = None
1060 sdist = package.get('sdist')
1061 if isinstance(sdist, dict):
1062 download_url = sdist.get('url')
1063 hash_value = sdist.get('hash') or ''
1064 if hash_value.startswith('sha256:'):
1065 sha256 = hash_value[len('sha256:'):]
1066 if download_url:
1067 file_name = posixpath.basename(download_url) or None
1068
1069 urls = get_pypi_urls(name, version)
1070 if download_url:
1071 # prefer the exact sdist URL recorded in the lock file
1072 urls['repository_download_url'] = download_url
1073
1074 qualifiers = {}

Callers 15

sortable_name_versionMethod · 0.45
package_from_distsMethod · 0.45
LocationResponseMethod · 0.45
ListBucketResponseMethod · 0.45
endElementMethod · 0.45
endElementMethod · 0.45
__attrs_post_init__Method · 0.45
compute_license_scoreFunction · 0.45
to_dictMethod · 0.45

Calls 7

get_pypi_urlsFunction · 0.85
to_stringMethod · 0.80
from_dataMethod · 0.80
getMethod · 0.65
loadMethod · 0.45
appendMethod · 0.45
to_dictMethod · 0.45

Tested by 1

__attrs_post_init__Method · 0.36