Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions packagedb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

from univers import versions
from univers.version_range import RANGE_CLASS_BY_SCHEMES
from univers.version_range import InvalidVersionRange
from univers.versions import InvalidVersion
from univers.version_range import VersionRange


Expand Down Expand Up @@ -405,8 +405,9 @@ def index_packages(self, request, *args, **kwargs):
packages = request.data.get('packages') or []
queued_packages = []
unqueued_packages = []
supported_ecosystem = ["maven","npm"]
Comment thread
keshav-space marked this conversation as resolved.
Outdated

unique_purls, unsupported_packages, unsupported_vers = get_resolved_purls(packages)
unique_purls, unsupported_packages, unsupported_vers = get_resolved_purls(packages, supported_ecosystem)
Comment thread
keshav-space marked this conversation as resolved.
Outdated

for purl in unique_purls:
is_routable_purl = priority_router.is_routable(purl)
Expand Down Expand Up @@ -691,7 +692,7 @@ class PackageSetViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = PackageSetAPISerializer


def get_resolved_purls(packages):
def get_resolved_purls(packages, supported_ecosystem):
Comment thread
keshav-space marked this conversation as resolved.
Outdated
"""
Take a list of dict containing purl or version-less purl along with vers
and return a list of resolved purls, a list of unsupported purls, and a
Expand All @@ -718,7 +719,7 @@ def get_resolved_purls(packages):
unique_resolved_purls.add(purl)
continue

if not vers:
if not vers or parsed_purl.type not in supported_ecosystem:
Comment thread
keshav-space marked this conversation as resolved.
Outdated
unsupported_purls.add(purl)
continue

Expand Down Expand Up @@ -749,18 +750,22 @@ def resolve_versions(parsed_purl, vers):

all_versions = get_all_versions(parsed_purl) or []

return [
str(
PackageURL(
type=parsed_purl.type,
namespace=parsed_purl.namespace,
name=parsed_purl.name,
version=version.string,
)
)
for version in all_versions
if version in version_range
]
result = []
for version in all_versions:
try:
if version in version_range:
package_url = PackageURL(
type=parsed_purl.type,
namespace=parsed_purl.namespace,
name=parsed_purl.name,
version=version.string,
)
result.append(str(package_url))
except Exception:
# Skip the ``Invalid constraints sequence`` Exception
Comment thread
keshav-space marked this conversation as resolved.
Outdated
pass

return result

def get_all_versions(purl: PackageURL):
"""
Expand All @@ -778,10 +783,17 @@ def get_all_versions(purl: PackageURL):
if not package_name or not versionAPI:
return

all_versions = versionAPI().fetch(package_name)
all_versions = versionAPI().fetch(package_name) or []
versionClass = VERSION_CLASS_BY_PACKAGE_TYPE.get(purl.type)

return [versionClass(package_version.value) for package_version in all_versions]
result = []
for package_version in all_versions:
try:
Comment thread
JonoYang marked this conversation as resolved.
result.append(versionClass(package_version.value))
except InvalidVersion:
pass

return result


VERSION_CLASS_BY_PACKAGE_TYPE = {pkg_type: range_class.version_class for pkg_type, range_class in RANGE_CLASS_BY_SCHEMES.items()}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ install_requires =
scancode-toolkit[full] == 32.0.6
urlpy == 0.5
matchcode-toolkit >= 1.1.1
univers == 30.10.0
univers == 30.10.1
setup_requires = setuptools_scm[toml] >= 4

python_requires = >=3.8
Expand Down