From eeb7fb91b89bce42b566b169cdb737b142e54a21 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Tue, 5 Dec 2023 13:08:22 +0100 Subject: [PATCH 1/3] Fix pylint warnings --- product_listings_manager/auth.py | 4 +-- product_listings_manager/models.py | 49 ++++++++-------------------- product_listings_manager/products.py | 32 +++++++++--------- tests/test_products.py | 2 +- 4 files changed, 32 insertions(+), 55 deletions(-) diff --git a/product_listings_manager/auth.py b/product_listings_manager/auth.py index f934a3e..34503a2 100644 --- a/product_listings_manager/auth.py +++ b/product_listings_manager/auth.py @@ -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" @@ -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 diff --git a/product_listings_manager/models.py b/product_listings_manager/models.py index 835c04c..e550000 100644 --- a/product_listings_manager/models.py +++ b/product_listings_manager/models.py @@ -66,12 +66,7 @@ class Packages(BaseModel): version = Column(String(255), nullable=False) def __repr__(self): - return "" % ( - self.id, - self.name, - self.version, - self.arch, - ) + return f"" class TreeProductMap(BaseModel): @@ -100,12 +95,9 @@ class Products(BaseModel): trees = relationship("Trees", secondary="tree_product_map", backref="products") def __repr__(self): - return "" % ( - self.id, - self.label, - self.version, - self.variant, - self.allow_source_only, + return ( + f"" ) @@ -146,12 +138,7 @@ class Trees(BaseModel): modules = relationship("Modules", secondary="tree_modules") def __repr__(self): - return "" % ( - self.id, - self.name, - self.date, - self.arch, - ) + return f"" class Overrides(BaseModel): @@ -172,12 +159,9 @@ class Overrides(BaseModel): include = Column(Boolean, nullable=False) def __repr__(self): - return "".format( - self.name, - self.pkg_arch, - self.product_arch, - self.product, - self.include, + return ( + f"" ) @@ -190,7 +174,7 @@ class MatchVersions(BaseModel): product = Column(String(100), primary_key=True) def __repr__(self): - return f"" + return f"" class Modules(BaseModel): @@ -204,12 +188,7 @@ class Modules(BaseModel): version = Column(String(255), nullable=False) def __repr__(self): - return "" % ( - self.id, - self.name, - self.stream, - self.version, - ) + return f"" class ModuleOverrides(BaseModel): @@ -223,9 +202,7 @@ class ModuleOverrides(BaseModel): product_arch = Column(String(32), primary_key=True) def __repr__(self): - return "" % ( - self.name, - self.stream, - self.product, - self.product_arch, + return ( + f"" ) diff --git a/product_listings_manager/products.py b/product_listings_manager/products.py index 693375f..0f3fd82 100644 --- a/product_listings_manager/products.py +++ b/product_listings_manager/products.py @@ -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 ( @@ -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 @@ -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: @@ -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 @@ -355,20 +355,20 @@ 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 = {} @@ -376,7 +376,7 @@ def get_module_product_listings(db, productLabel, moduleNVR): 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) @@ -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)) diff --git a/tests/test_products.py b/tests/test_products.py index 63eb0a6..564aef5 100644 --- a/tests/test_products.py +++ b/tests/test_products.py @@ -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") From 33b515811e2318d28ed36b080d4434c6cc046550 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Tue, 5 Dec 2023 13:17:27 +0100 Subject: [PATCH 2/3] Allow running tox with different Python versions --- tox.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index cc104d2..6d3fe60 100644 --- a/tox.ini +++ b/tox.ini @@ -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 = From 988acffadad954b84dcb7234ca3b1e25088651f2 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Tue, 5 Dec 2023 13:19:06 +0100 Subject: [PATCH 3/3] Update to Python 3.12 --- .github/workflows/gating.yaml | 4 ++-- Dockerfile | 2 +- poetry.lock | 4 ++-- pyproject.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/gating.yaml b/.github/workflows/gating.yaml index 7392c18..c1eaa05 100644 --- a/.github/workflows/gating.yaml +++ b/.github/workflows/gating.yaml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.11"] + python-version: ["3.12"] steps: - uses: actions/checkout@v4 @@ -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 diff --git a/Dockerfile b/Dockerfile index 01b58b6..4799158 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ diff --git a/poetry.lock b/poetry.lock index 5a34fc5..7567a9b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1482,5 +1482,5 @@ test = ["flake8", "httpx", "pytest", "pytest-cov"] [metadata] lock-version = "2.0" -python-versions = ">=3.9,<3.12" -content-hash = "c59fdfa932d2e0c0bf10fe70f476d5264c801b61aee00bb957bd91cd7777c966" +python-versions = ">=3.9,<3.13" +content-hash = "2aaea3ef6de7bc807621b1b27cdec772ef69ca8b4d652e85f120232f303b9476" diff --git a/pyproject.toml b/pyproject.toml index e3c47ff..5f2fae3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"