Skip to content

Commit

Permalink
Run pyupgrade
Browse files Browse the repository at this point in the history
upgrade everything to 3.10+
  • Loading branch information
lazka committed Nov 1, 2023
1 parent 4f5dad3 commit e77fed1
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 208 deletions.
50 changes: 25 additions & 25 deletions app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
from fastapi_etag import Etag
from pydantic import BaseModel

from typing import Tuple, Dict, List, Set, Iterable, Union, Optional
from collections.abc import Iterable
from .appstate import state, SrcInfoPackage
from .utils import extract_upstream_version, version_is_newer_than
from .fetch import queue_update


class QueueBuild(BaseModel):
packages: List[str]
depends: Dict[str, List[str]]
packages: list[str]
depends: dict[str, list[str]]
new: bool


class QueueEntry(BaseModel):
name: str
version: str
version_repo: Optional[str]
version_repo: str | None
repo_url: str
repo_path: str
source: bool
builds: Dict[str, QueueBuild]
builds: dict[str, QueueBuild]


async def get_etag(request: Request) -> str:
Expand All @@ -32,7 +32,7 @@ async def get_etag(request: Request) -> str:
router = APIRouter()


def get_srcinfos_to_build() -> Tuple[List[SrcInfoPackage], Set[str]]:
def get_srcinfos_to_build() -> tuple[list[SrcInfoPackage], set[str]]:
srcinfos = []

# packages that should be updated
Expand All @@ -45,16 +45,16 @@ def get_srcinfos_to_build() -> Tuple[List[SrcInfoPackage], Set[str]]:
srcinfos.append(srcinfo)

# packages that are new
not_in_repo: Dict[str, List[SrcInfoPackage]] = {}
replaces_not_in_repo: Set[str] = set()
not_in_repo: dict[str, list[SrcInfoPackage]] = {}
replaces_not_in_repo: set[str] = set()
for srcinfo in state.sourceinfos.values():
not_in_repo.setdefault(srcinfo.pkgname, []).append(srcinfo)
replaces_not_in_repo.update(srcinfo.replaces)
for s in state.sources.values():
for p in s.packages.values():
not_in_repo.pop(p.name, None)
replaces_not_in_repo.discard(p.name)
marked_new: Set[str] = set()
marked_new: set[str] = set()
for sis in not_in_repo.values():
srcinfos.extend(sis)
# packages that are considered new, that don't exist in the repo, or
Expand All @@ -69,8 +69,8 @@ def get_srcinfos_to_build() -> Tuple[List[SrcInfoPackage], Set[str]]:
return srcinfos, marked_new


@router.get('/buildqueue2', response_model=List[QueueEntry])
async def buildqueue2(request: Request, response: Response) -> List[QueueEntry]:
@router.get('/buildqueue2', response_model=list[QueueEntry])
async def buildqueue2(request: Request, response: Response) -> list[QueueEntry]:
srcinfos, marked_new = get_srcinfos_to_build()

srcinfo_provides = {}
Expand All @@ -92,7 +92,7 @@ def resolve_package(pkgname: str) -> str:
# if there is no real one, try to find a provider
return srcinfo_provides.get(pkgname, pkgname)

def get_transitive_depends_and_resolve(packages: Iterable[str]) -> Set[str]:
def get_transitive_depends_and_resolve(packages: Iterable[str]) -> set[str]:
todo = set(packages)
done = set()
while todo:
Expand All @@ -105,8 +105,8 @@ def get_transitive_depends_and_resolve(packages: Iterable[str]) -> Set[str]:
todo.update(si.depends.keys())
return done

def get_transitive_makedepends(packages: Iterable[str]) -> Set[str]:
todo: Set[str] = set()
def get_transitive_makedepends(packages: Iterable[str]) -> set[str]:
todo: set[str] = set()
for name in packages:
# don't resolve here, we want the real deps of the packages to build
# even if it gets replaced
Expand All @@ -115,7 +115,7 @@ def get_transitive_makedepends(packages: Iterable[str]) -> Set[str]:
todo.update(si.makedepends.keys())
return get_transitive_depends_and_resolve(todo)

def srcinfo_get_repo_version(si: SrcInfoPackage) -> Optional[str]:
def srcinfo_get_repo_version(si: SrcInfoPackage) -> str | None:
if si.pkgbase in state.sources:
return state.sources[si.pkgbase].version
return None
Expand All @@ -131,21 +131,21 @@ def srcinfo_has_src(si: SrcInfoPackage) -> bool:
def srcinfo_is_new(si: SrcInfoPackage) -> bool:
return si.pkgname in marked_new

def build_key(srcinfo: SrcInfoPackage) -> Tuple[str, str]:
def build_key(srcinfo: SrcInfoPackage) -> tuple[str, str]:
return (srcinfo.repo_url, srcinfo.repo_path)

to_build: Dict[Tuple, List[SrcInfoPackage]] = {}
to_build: dict[tuple, list[SrcInfoPackage]] = {}
for srcinfo in srcinfos:
key = build_key(srcinfo)
to_build.setdefault(key, []).append(srcinfo)

entries = []
repo_mapping = {}
all_packages: Set[str] = set()
all_packages: set[str] = set()
for srcinfos in to_build.values():
packages = set()
needs_src = False
new_all: Dict[str, List[bool]] = {}
new_all: dict[str, list[bool]] = {}
version_repo = None
for si in srcinfos:
if not srcinfo_has_src(si):
Expand Down Expand Up @@ -177,8 +177,8 @@ def build_key(srcinfo: SrcInfoPackage) -> Tuple[str, str]:
e["makedepends"] &= all_packages
e["makedepends"] -= e["packages"]

def group_by_repo(sequence: Iterable[str]) -> Dict[str, List]:
grouped: Dict[str, List] = {}
def group_by_repo(sequence: Iterable[str]) -> dict[str, list]:
grouped: dict[str, list] = {}
for name in sequence:
grouped.setdefault(repo_mapping[name], []).append(name)
for key, values in grouped.items():
Expand All @@ -200,7 +200,7 @@ def group_by_repo(sequence: Iterable[str]) -> Dict[str, List]:

makedepends = e["makedepends"]

builds: Dict[str, QueueBuild] = {}
builds: dict[str, QueueBuild] = {}
deps_grouped = group_by_repo(makedepends)

for repo, build_packages in group_by_repo(e["packages"]).items():
Expand Down Expand Up @@ -251,7 +251,7 @@ async def search(request: Request, response: Response, query: str = "", qtype: s
qtype = "pkg"

parts = query.split()
res_pkg: List[Dict[str, Union[str, List[str], int]]] = []
res_pkg: list[dict[str, str | list[str] | int]] = []
exact = {}
if not query:
pass
Expand Down Expand Up @@ -296,8 +296,8 @@ class OutOfDateEntry(BaseModel):
version_upstream: str


@router.get('/outofdate', response_model=List[OutOfDateEntry], dependencies=[Depends(Etag(get_etag))])
async def outofdate(request: Request, response: Response) -> List[OutOfDateEntry]:
@router.get('/outofdate', response_model=list[OutOfDateEntry], dependencies=[Depends(Etag(get_etag))])
async def outofdate(request: Request, response: Response) -> list[OutOfDateEntry]:
to_update = []

for s in state.sources.values():
Expand Down
7 changes: 2 additions & 5 deletions app/appconfig.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Copyright 2016-2020 Christoph Reiter
# SPDX-License-Identifier: MIT

from typing import Optional


REPO_URL = "https://repo.msys2.org"
DOWNLOAD_URL = "https://mirror.msys2.org"
REPOSITORIES = [
Expand All @@ -21,7 +18,7 @@
ARCH_REPO_CONFIG = []
for repo in ["core", "core-testing", "extra", "extra-testing"]:
ARCH_REPO_CONFIG.append(
(ARCH_REPO_URL + "/{0}/os/x86_64/{0}.db".format(repo), repo)
(ARCH_REPO_URL + f"/{repo}/os/x86_64/{repo}.db", repo)
)
AUR_METADATA_URL = "https://aur.archlinux.org/packages-meta-ext-v1.json.gz"

Expand All @@ -48,4 +45,4 @@
UPDATE_MIN_RATE = 1

REQUEST_TIMEOUT = 60
CACHE_DIR: Optional[str] = None
CACHE_DIR: str | None = None
Loading

0 comments on commit e77fed1

Please sign in to comment.