diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 92e30ddd3..58c19d947 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -36,4 +36,4 @@ jobs: # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest tests + poetry run pytest tests diff --git a/browse/commands/invalidate.py b/browse/commands/invalidate.py index f74599f45..696a9db60 100644 --- a/browse/commands/invalidate.py +++ b/browse/commands/invalidate.py @@ -16,7 +16,7 @@ @bp.cli.command(short_help="invalidates CDN for PDFs from a mailing") @click.argument("mailings", - #help="Invalidate all PDFs from these mailings. May have more than one. Format YYMMDD.", + # help="Invalidate all PDFs from these mailings. May have more than one. Format YYMMDD.", nargs=-1) @click.option("--project", default="arxiv-production") @click.option("--cdn", default="browse-arxiv-org-load-balancer2", @@ -28,7 +28,7 @@ @click.option("-v", is_flag=True, help="Verbose.", default=False) -def invalidate_mailings(project: str, cdn: str, mailings: List[str], dry_run: bool, v: bool): +def invalidate_mailings(project: str, cdn: str, mailings: List[str], dry_run: bool, v: bool) -> None: """Invalidate CDN for PDFs in a mailing.""" if not mailings: raise ValueError("mailing must not be empty.") @@ -45,11 +45,11 @@ def invalidate_mailings(project: str, cdn: str, mailings: List[str], dry_run: bo papers = (session.query(NextMail.paper_id, NextMail.version) .filter(NextMail.mail_id == int(mailing))) - nn=0; + nn = 0; for paper_id, version in papers.all(): paths.append(f"/pdf/{paper_id}.pdf") paths.append(f"/pdf/{paper_id}v{version}.pdf") - nn = nn+1 + nn = nn + 1 if v: print(f"For {mailing} found {nn} papers.") @@ -61,7 +61,7 @@ def invalidate_mailings(project: str, cdn: str, mailings: List[str], dry_run: bo _invalidate(project, cdn, paths, dry_run=dry_run, v=v) -def _invalidate(proj: str, cdn: str, paths: Iterable[str], dry_run: bool = False, v: bool = False): +def _invalidate(proj: str, cdn: str, paths: List[str], dry_run: bool = False, v: bool = False) -> None: """Invalidates `paths` on `cdn` in `proj`.""" paths.sort() if v: @@ -80,18 +80,20 @@ def _invalidate(proj: str, cdn: str, paths: Iterable[str], dry_run: bool = False url_map=cdn, cache_invalidation_rule_resource= compute_v1.CacheInvalidationRule( - #host="*", + # host="*", path=path), ) _invalidate_req(client, request) if v: print(f"Invalidated {path}.") -def _exception_pred(ex:Exception) -> bool: - return (ex and - (isinstance(ex, BaseException) - or "rate limit exceeded" in str(ex).lower())) + +def _exception_pred(ex: Exception) -> bool: + return bool(ex and + (isinstance(ex, BaseException) + or "rate limit exceeded" in str(ex).lower())) + @retry.Retry(predicate=_exception_pred) -def _invalidate_req(client, request) -> None: +def _invalidate_req(client: compute_v1.UrlMapsClient, request: compute_v1.InvalidateCacheUrlMapRequest) -> None: client.invalidate_cache_unary(request=request)