Skip to content

Commit

Permalink
Merge fdf0ba7 into 448bf1a
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Dec 6, 2023
2 parents 448bf1a + fdf0ba7 commit 4945ed5
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gating.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
GH_REGISTRY: ghcr.io/${{ github.actor }}
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ repos:
- --ignore=E501
- id: ruff-format

# Linter and formatter
- repo: https://github.com/Instagram/Fixit
rev: v2.1.0
hooks:
- id: fixit-fix

# Security linter
- repo: https://github.com/pycqa/bandit
rev: 1.7.5
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.fedoraproject.org/fedora:38 as builder
FROM registry.fedoraproject.org/fedora:39 as builder

# hadolint ignore=DL3033,DL4006,SC2039,SC3040
RUN set -exo pipefail \
Expand Down
2 changes: 1 addition & 1 deletion client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def pretty_print_json(data):
else:
import requests

product_info_path = "/product-info/%s" % args.product
product_info_path = f"/product-info/{args.product}"
product_listings_path = "/product-listings/{}/{}".format(
args.product,
args.nvr,
Expand Down
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions product_listings_manager/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# Inspired by https://github.com/mkomitee/flask-kerberos/blob/master/flask_kerberos.py
# Later cleaned and ported to python-gssapi
def process_gssapi_request(token):
stage = "initialize server context"
try:
stage = "initialize server context"
sc = gssapi.SecurityContext(usage="accept")

stage = "step context"
Expand Down Expand Up @@ -83,5 +83,5 @@ def get_user(request):
headers = {"WWW-Authenticate": f"Negotiate {token}"}

# remove realm
user = user.split("@")[0]
user = user.split("@", maxsplit=1)[0]
return user, headers
49 changes: 13 additions & 36 deletions product_listings_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ class Packages(BaseModel):
version = Column(String(255), nullable=False)

def __repr__(self):
return "<Package %d %s %s %s>" % (
self.id,
self.name,
self.version,
self.arch,
)
return f"<Package {self.id} {self.name} {self.version} {self.arch}>"


class TreeProductMap(BaseModel):
Expand Down Expand Up @@ -100,12 +95,9 @@ class Products(BaseModel):
trees = relationship("Trees", secondary="tree_product_map", backref="products")

def __repr__(self):
return "<Product %d %s %s %s %s>" % (
self.id,
self.label,
self.version,
self.variant,
self.allow_source_only,
return (
f"<Product {self.id} {self.label} {self.version}"
f" {self.variant} {self.allow_source_only}>"
)


Expand Down Expand Up @@ -146,12 +138,7 @@ class Trees(BaseModel):
modules = relationship("Modules", secondary="tree_modules")

def __repr__(self):
return "<Tree %d %s %s %s>" % (
self.id,
self.name,
self.date,
self.arch,
)
return f"<Tree {self.id} {self.name} {self.date} {self.arch}>"


class Overrides(BaseModel):
Expand All @@ -172,12 +159,9 @@ class Overrides(BaseModel):
include = Column(Boolean, nullable=False)

def __repr__(self):
return "<Overrides {} {} {} {} {}>".format(
self.name,
self.pkg_arch,
self.product_arch,
self.product,
self.include,
return (
f"<Overrides {self.name} {self.pkg_arch} {self.product_arch}"
f" {self.product} {self.include}>"
)


Expand All @@ -190,7 +174,7 @@ class MatchVersions(BaseModel):
product = Column(String(100), primary_key=True)

def __repr__(self):
return f"<MatchVersion {self.id} {self.name} {self.product}>"
return f"<MatchVersion {self.name} {self.product}>"


class Modules(BaseModel):
Expand All @@ -204,12 +188,7 @@ class Modules(BaseModel):
version = Column(String(255), nullable=False)

def __repr__(self):
return "<Module %d %s %s %s>" % (
self.id,
self.name,
self.stream,
self.version,
)
return f"<Module {self.id} {self.name} {self.stream} {self.version}>"


class ModuleOverrides(BaseModel):
Expand All @@ -223,9 +202,7 @@ class ModuleOverrides(BaseModel):
product_arch = Column(String(32), primary_key=True)

def __repr__(self):
return "<ModuleOverrides %s %s %d %s>" % (
self.name,
self.stream,
self.product,
self.product_arch,
return (
f"<ModuleOverrides {self.name} {self.stream} {self.product}"
f" {self.product_arch}>"
)
2 changes: 1 addition & 1 deletion product_listings_manager/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def has_permission(
permissions: list[Permission],
ldap_config: LdapConfig,
) -> bool:
qs = list(q.query for q in queries)
qs = [q.query for q in queries]
qs = [
q
for q in qs
Expand Down
32 changes: 16 additions & 16 deletions product_listings_manager/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_product_info(db, label):

if not versions:
raise ProductListingsNotFoundError(
"Could not find a product with label: %s" % label
f"Could not find a product with label: {label}"
)

return (
Expand Down Expand Up @@ -246,18 +246,18 @@ def get_product_labels(db):
return [{"label": row.label} for row in rows]


def get_product_listings(db, productLabel, buildInfo):
def get_product_listings(db, product_label, build_info):
"""
Get a map of which variants of the given product included packages built
by the given build, and which arches each variant included.
"""
session = get_koji_session()
build = get_build(buildInfo, session)
build = get_build(build_info, session)

rpms = session.listRPMs(buildID=build["id"])
if not rpms:
raise ProductListingsNotFoundError(
"Could not find any RPMs for build: %s" % buildInfo
f"Could not find any RPMs for build: {build_info}"
)

# sort rpms, so first part of list consists of sorted 'normal' rpms and
Expand All @@ -267,21 +267,21 @@ def get_product_listings(db, productLabel, buildInfo):
rpms = sorted(base_rpms, key=lambda x: x["nvr"]) + sorted(
debuginfos, key=lambda x: x["nvr"]
)
srpm = "%(package_name)s-%(version)s-%(release)s.src.rpm" % build
srpm = "{package_name}-{version}-{release}.src.rpm".format(**build)

prodinfo = get_product_info(db, productLabel)
prodinfo = get_product_info(db, product_label)
version, variants = prodinfo

listings = {}
match_version = get_match_versions(db, productLabel)
match_version = get_match_versions(db, product_label)
for variant in variants:
if variant is None:
# dict keys must be a string
variant = ""
treelist = precalc_treelist(db, productLabel, version, variant)
treelist = precalc_treelist(db, product_label, version, variant)
if not treelist:
continue
overrides = get_overrides(db, productLabel, version, variant)
overrides = get_overrides(db, product_label, version, variant)
cache_map = {}
for rpm in rpms:
if rpm["name"] in match_version:
Expand Down Expand Up @@ -346,7 +346,7 @@ def get_product_listings(db, productLabel, buildInfo):
for variant in list(listings.keys()):
nvrs = list(listings[variant].keys())
# BREW-260: Read allow_src_only flag for the product/version
allow_src_only = get_srconly_flag(db, productLabel, version)
allow_src_only = get_srconly_flag(db, product_label, version)
if len(nvrs) == 1:
maps = list(listings[variant][nvrs[0]].keys())
# BREW-260: check for allow_src_only flag added
Expand All @@ -355,28 +355,28 @@ def get_product_listings(db, productLabel, buildInfo):
return listings


def get_module_product_listings(db, productLabel, moduleNVR):
def get_module_product_listings(db, product_label, module_nvr):
"""
Get a map of which variants of the given product included the given module,
and which arches each variant included.
"""
build = get_build(moduleNVR)
build = get_build(module_nvr)
try:
module = build["extra"]["typeinfo"]["module"]
module_name = module["name"]
module_stream = module["stream"]
except (KeyError, TypeError):
raise ProductListingsNotFoundError("It's not a module build: %s" % moduleNVR)
raise ProductListingsNotFoundError(f"This is not a module build: {module_nvr}")

prodinfo = get_product_info(db, productLabel)
prodinfo = get_product_info(db, product_label)
version, variants = prodinfo

listings = {}
for variant in variants:
if variant is None:
# dict keys must be a string
variant = ""
trees = precalc_treelist(db, productLabel, version, variant)
trees = precalc_treelist(db, product_label, version, variant)

module_trees = (
db.query(models.Trees)
Expand All @@ -390,7 +390,7 @@ def get_module_product_listings(db, productLabel, moduleNVR):
)

overrides = get_module_overrides(
db, productLabel, version, module_name, module_stream, variant
db, product_label, version, module_name, module_stream, variant
)

archs = sorted(set([arch for (arch,) in module_trees] + overrides))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include = [
]

[tool.poetry.dependencies]
python = ">=3.9,<3.12"
python = ">=3.9,<3.13"
fastapi = "^0.104.1"
gunicorn = "^21.2.0"
python-dateutil = "^2.8.2"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_not_module_build(self, mock_get_build, db):
nvr = "perl-5.16.3-1.el7"
with pytest.raises(ProductListingsNotFoundError) as excinfo:
get_module_product_listings(db, "fake-label", nvr)
assert f"It's not a module build: {nvr}" == str(excinfo.value)
assert f"This is not a module build: {nvr}" == str(excinfo.value)

@patch("product_listings_manager.products.get_module_overrides")
@patch("product_listings_manager.products.get_product_info")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rest_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_get_product_info(self, client):
assert r.json() == [product_version, [p1.variant, p2.variant]]

def test_label_not_found(self, client):
msg = "Could not find a product with label: %s" % self.product_label
msg = f"Could not find a product with label: {self.product_label}"
r = client.get(self.path)
assert r.status_code == 404
assert msg in r.json().get("message", "")
Expand Down Expand Up @@ -340,7 +340,7 @@ def test_unknown_error(self, mock_getlabels, exception_log, client):
"%s: callee=%r, args=%r, kwargs=%r",
"API call get_product_labels() failed",
ANY,
tuple(),
(),
{},
)

Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[tox]
envlist = py311,mypy
envlist = py3,mypy
isolated_build = True

[testenv]
basepython = python3.11
# Set RPM_PY_VERBOSE to "true" to debug koji package installation failures
passenv = RPM_PY_VERBOSE
extras =
Expand Down

0 comments on commit 4945ed5

Please sign in to comment.