Skip to content

Commit

Permalink
Remove apt_pkg dependency
Browse files Browse the repository at this point in the history
`apt_pkg` is only available as a system package on Debian, which makes
`process_incoming` not very portable, including preventing use of
virtualenvs.  It's not really needed, we can use `semver` sorting
instead in the remaining `apt_pkg` call site.
  • Loading branch information
elprans committed Sep 12, 2023
1 parent 7b5c5a5 commit 02ba601
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
29 changes: 16 additions & 13 deletions server/process_incoming.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
from typing import Any, ContextManager, cast, List, Optional
from typing_extensions import TypedDict

import apt_pkg

import contextlib
import hashlib
import fnmatch
import functools
import io
import json
import os
Expand All @@ -32,8 +29,6 @@
from mypy_boto3_s3 import service_resource as s3


apt_pkg.init_system()

CACHE = "Cache-Control:public, no-transform, max-age=315360000"
NO_CACHE = "Cache-Control:no-store, no-cache, private, max-age=0"
ARCHIVE = pathlib.Path("archive")
Expand Down Expand Up @@ -85,7 +80,7 @@ class Version(TypedDict):

slot_regexp = re.compile(
r"^(\w+(?:-[a-zA-Z]*)*?)"
r"(?:-(\d+(?:-(?:alpha|beta|rc)\d+)?(?:-dev\d+)?))?$",
+ r"(?:-(\d+(?:-(?:alpha|beta|rc)\d+)?(?:-dev\d+)?))?$",
re.A,
)

Expand Down Expand Up @@ -1263,24 +1258,33 @@ def process_rpm(
elif is_metapackage:
pkgmetadata["name"] = basename

version_key = format_version_key(
pkgmetadata["version_details"], pkgmetadata["revision"]
)
ver_details = pkgmetadata["version_details"]

slot_name = pkgmetadata["name"]
if pkgmetadata.get("version_slot"):
slot_name += f".{pkgmetadata['version_slot']}"
slot_name += f".{pkgmetadata['architecture']}"

version_sort_key = semver.VersionInfo(
ver_details["major"],
ver_details["minor"] or 0,
ver_details["patch"] or 0,
".".join(
f"{p['phase']}.{p['number']}"
for p in ver_details["prerelease"]
),
)

slot_index.setdefault(slot_name, []).append(
(
version_key,
version_sort_key,
pkgmetadata["name"],
nevra,
pkgmetadata["architecture"],
)
)

index_key = (pkgmetadata["name"], version_key, arch)
index_key = (pkgmetadata["name"], version_sort_key, arch)

if index_key in existing:
packages[index_key] = existing[index_key]
Expand All @@ -1298,12 +1302,11 @@ def process_rpm(
need_db_update = False
if channel == "nightly":
print("process_rpm: collecting garbage")
comp = functools.cmp_to_key(apt_pkg.version_compare)
for slot_name, versions in slot_index.items():
sorted_versions = list(
sorted(
versions,
key=lambda v: comp(v[0]),
key=lambda v: v[0],
reverse=True,
)
)
Expand Down
4 changes: 4 additions & 0 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ build-backend = "setuptools.build_meta"

[tool.setuptools]
py-modules = ["process_incoming"]

[tool.black]
line-length = 79
target-version = ["py39"]

0 comments on commit 02ba601

Please sign in to comment.