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

Function get_requires_dependencies

src/packagedcode/pypi.py:2177–2246  ·  view source on GitHub ↗

Return a list of DependentPackage found in a ``requires`` list of requirement strings or an empty list.

(
    requires,
    default_scope='install',
    is_direct=True,
    is_optional=False,
    is_runtime=True,
)

Source from the content-addressed store, hash-verified

2175
2176
2177def get_requires_dependencies(
2178 requires,
2179 default_scope='install',
2180 is_direct=True,
2181 is_optional=False,
2182 is_runtime=True,
2183):
2184 """
2185 Return a list of DependentPackage found in a ``requires`` list of
2186 requirement strings or an empty list.
2187 """
2188 if not is_simple_requires(requires):
2189 # FIXME: when does this happen? should we log this?
2190 return []
2191 dependent_packages = []
2192 for req in (requires or []):
2193 req = Requirement(req)
2194 name = canonicalize_name(req.name)
2195 is_pinned = False
2196 purl = PackageURL(type='pypi', name=name)
2197 # note: packaging.requirements.Requirement.specifier is a
2198 # packaging.specifiers.SpecifierSet object and a SpecifierSet._specs is
2199 # a set of either: packaging.specifiers.Specifier or
2200 # packaging.specifiers.LegacySpecifier and each of these have a
2201 # .operator and .version property
2202 # a packaging.specifiers.SpecifierSet
2203 specifiers_set = req.specifier # a list of packaging.specifiers.Specifier
2204 specifiers = specifiers_set._specs
2205 requirement = None
2206 if specifiers:
2207 # SpecifierSet stringifies to comma-separated sorted Specifiers
2208 requirement = str(specifiers_set)
2209 # are we pinned e.g. resolved? this is true if we have a single
2210 # equality specifier
2211 if len(specifiers) == 1:
2212 specifier = list(specifiers)[0]
2213 if specifier.operator in ('==', '==='):
2214 is_pinned = True
2215 purl = purl._replace(version=specifier.version)
2216
2217 # we use the extra as scope if available
2218 extra = get_extra(req.marker)
2219 scope = extra or default_scope
2220
2221 extra_data = {}
2222 if req.marker:
2223 platform = get_python_version_os(req.marker)
2224 if platform:
2225 extra_data = platform
2226
2227 extracted_requirement = None
2228 if requirement:
2229 extracted_requirement = requirement
2230
2231 if is_optional or bool(extra):
2232 is_optional = True
2233
2234 dependent_packages.append(

Callers 7

parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
get_dist_dependenciesFunction · 0.85

Calls 6

is_simple_requiresFunction · 0.85
get_extraFunction · 0.85
get_python_version_osFunction · 0.85
boolFunction · 0.85
to_stringMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected