From e2d60eef290219e50a6637ddd3601f4538207d93 Mon Sep 17 00:00:00 2001 From: Jan-Benedikt Jagusch Date: Sat, 18 Feb 2023 21:10:07 +0100 Subject: [PATCH 1/3] Enable pyright reportPrivateImportUsage. --- pyproject.toml | 2 +- quetz/main.py | 15 +++++++-------- quetz/pkgstores.py | 4 +++- quetz/tasks/mirror.py | 5 ++++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7833921f..67af0535 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ reportMissingTypeStubs = false reportOptionalMemberAccess = false reportOptionalOperand = false reportOptionalSubscript = false -reportPrivateImportUsage = false +reportPrivateImportUsage = true reportUnboundVariable = false reportUndefinedVariable = false venv = ".venv" diff --git a/quetz/main.py b/quetz/main.py index 673d4545..c4401e15 100644 --- a/quetz/main.py +++ b/quetz/main.py @@ -17,6 +17,7 @@ from typing import List, Optional, Tuple, Type import pydantic +import pydantic.error_wrappers import requests from fastapi import ( APIRouter, @@ -41,13 +42,11 @@ from starlette.middleware.base import BaseHTTPMiddleware from starlette.middleware.httpsredirect import HTTPSRedirectMiddleware from starlette.middleware.sessions import SessionMiddleware -from tenacity import ( - after_log, - retry, - retry_if_result, - stop_after_attempt, - wait_exponential, -) +from tenacity import retry +from tenacity.after import after_log +from tenacity.retry import retry_if_result +from tenacity.stop import stop_after_attempt +from tenacity.wait import wait_exponential from quetz import ( authorization, @@ -1596,7 +1595,7 @@ def _delete_file(condainfo, filename): summary=str(condainfo.about.get("summary", "n/a")), description=str(condainfo.about.get("description", "n/a")), ) - except pydantic.main.ValidationError as err: + except pydantic.error_wrappers.ValidationError as err: _delete_file(condainfo, file.filename) raise errors.ValidationError( "Validation Error for package: " diff --git a/quetz/pkgstores.py b/quetz/pkgstores.py index 26502281..0caf0fad 100644 --- a/quetz/pkgstores.py +++ b/quetz/pkgstores.py @@ -19,7 +19,9 @@ from typing import IO, List, Tuple, Union import fsspec -from tenacity import retry, retry_if_exception_type, stop_after_attempt +from tenacity import retry +from tenacity.retry import retry_if_exception_type +from tenacity.stop import stop_after_attempt try: import xattr diff --git a/quetz/tasks/mirror.py b/quetz/tasks/mirror.py index f5042201..e0b7fa18 100644 --- a/quetz/tasks/mirror.py +++ b/quetz/tasks/mirror.py @@ -10,7 +10,10 @@ import requests from fastapi import HTTPException, status -from tenacity import TryAgain, after_log, retry, stop_after_attempt, wait_exponential +from tenacity import TryAgain, retry +from tenacity.after import after_log +from tenacity.stop import stop_after_attempt +from tenacity.wait import wait_exponential from quetz import authorization, rest_models from quetz.condainfo import CondaInfo, get_subdir_compat From 5b06f814d98e64fa60606629794c428956487516 Mon Sep 17 00:00:00 2001 From: Jan-Benedikt Jagusch Date: Sat, 18 Feb 2023 21:16:39 +0100 Subject: [PATCH 2/3] Enable pyright reportOptionalSubscript. --- pyproject.toml | 2 +- quetz/authentication/base.py | 4 +++- quetz/migrations/env.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 67af0535..b0af50b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ reportMissingModuleSource = false reportMissingTypeStubs = false reportOptionalMemberAccess = false reportOptionalOperand = false -reportOptionalSubscript = false +reportOptionalSubscript = true reportPrivateImportUsage = true reportUnboundVariable = false reportUndefinedVariable = false diff --git a/quetz/authentication/base.py b/quetz/authentication/base.py index b5695115..08db4b09 100644 --- a/quetz/authentication/base.py +++ b/quetz/authentication/base.py @@ -301,7 +301,9 @@ def configure(self, config): async def authenticate( self, request: Request, data=None, dao=None, config=None, **kwargs ) -> Optional[str]: - if data["username"] == data["password"]: + if data is None: + return None + elif data["username"] == data["password"]: return data['username'] else: return None diff --git a/quetz/migrations/env.py b/quetz/migrations/env.py index 1f10459d..96ade218 100644 --- a/quetz/migrations/env.py +++ b/quetz/migrations/env.py @@ -73,7 +73,7 @@ def run_migrations_online(): and associate a connection with the context. """ - configuration = config.get_section(config.config_ini_section) + configuration = config.get_section(config.config_ini_section, {}) configuration["sqlalchemy.url"] = get_url() connection = config.attributes.get('connection', None) From 0bb54b0564a7086cb39781b97ea0b7786e4639f4 Mon Sep 17 00:00:00 2001 From: Jan-Benedikt Jagusch Date: Sat, 18 Feb 2023 21:21:54 +0100 Subject: [PATCH 3/3] Enable pyright reportOptionalOperand. --- pyproject.toml | 2 +- quetz/tasks/workers.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b0af50b8..cb046617 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,7 @@ reportMissingImports = false reportMissingModuleSource = false reportMissingTypeStubs = false reportOptionalMemberAccess = false -reportOptionalOperand = false +reportOptionalOperand = true reportOptionalSubscript = true reportPrivateImportUsage = true reportUnboundVariable = false diff --git a/quetz/tasks/workers.py b/quetz/tasks/workers.py index ba4702ad..a750faec 100644 --- a/quetz/tasks/workers.py +++ b/quetz/tasks/workers.py @@ -100,6 +100,8 @@ def fork_job(self): def wait_for_job(self): exc = self._parent_conn.recv() self._process.join() + if self._process.exitcode is None: + raise RuntimeError if self._process.exitcode > 0: raise exc return