diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c779d7b88..889d1b881 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -161,7 +161,7 @@ jobs: - name: "Linting Checks 🧹" run: | - hatch env run -e dev lint + hatch env run -e lint lint - name: "Build package 📦" run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 164a8bf16..289ee39e4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,34 +7,28 @@ # # - Register git hooks: pre-commit install --install-hooks # - Run on all files: pre-commit run --all-files +ci: + autoupdate_schedule: monthly + autofix_commit_msg: | + [pre-commit.ci] Apply automatic pre-commit fixes repos: - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 24.3.0 hooks: - id: black exclude: "examples|tests/assets" - - repo: https://github.com/charliermarsh/ruff-pre-commit + - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: "v0.0.289" + rev: "v0.3.4" hooks: - id: ruff exclude: "examples|tests/assets" args: ["--fix"] - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - name: isort - additional_dependencies: [toml] - files: \.py$ - args: ["--profile", "black"] - exclude: "conda-store-server/conda_store_server/action/__init__.py" - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace files: ".*\\.py" @@ -44,7 +38,15 @@ repos: - id: trailing-whitespace - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.3 + rev: v4.0.0-alpha.8 hooks: - id: prettier exclude: ^(examples/|templates/|) + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + name: isort + args: ["--profile", "black"] + exclude: "conda-store-server/conda_store_server/action/__init__.py" diff --git a/conda-store-server/conda_store_server/__init__.py b/conda-store-server/conda_store_server/__init__.py index 5737a0e60..497aeea0c 100644 --- a/conda-store-server/conda_store_server/__init__.py +++ b/conda-store-server/conda_store_server/__init__.py @@ -1,7 +1,9 @@ import datetime import typing + from pathlib import Path + __version__ = "2024.3.1" diff --git a/conda-store-server/conda_store_server/action/add_conda_prefix_packages.py b/conda-store-server/conda_store_server/action/add_conda_prefix_packages.py index 0c805649c..5e270df8f 100644 --- a/conda-store-server/conda_store_server/action/add_conda_prefix_packages.py +++ b/conda-store-server/conda_store_server/action/add_conda_prefix_packages.py @@ -4,6 +4,7 @@ import pathlib from conda.core.prefix_data import PrefixData + from conda_store_server import action, api diff --git a/conda-store-server/conda_store_server/action/add_lockfile_packages.py b/conda-store-server/conda_store_server/action/add_lockfile_packages.py index bea87d456..fa703fb38 100644 --- a/conda-store-server/conda_store_server/action/add_lockfile_packages.py +++ b/conda-store-server/conda_store_server/action/add_lockfile_packages.py @@ -1,6 +1,7 @@ import typing from conda.models.dist import Dist + from conda_store_server import action, api, conda_utils diff --git a/conda-store-server/conda_store_server/action/download_packages.py b/conda-store-server/conda_store_server/action/download_packages.py index 93273f3ba..940ffc223 100644 --- a/conda-store-server/conda_store_server/action/download_packages.py +++ b/conda-store-server/conda_store_server/action/download_packages.py @@ -10,6 +10,7 @@ import conda_package_handling.api import conda_package_streaming.url import filelock + from conda.base.constants import PACKAGE_CACHE_MAGIC_FILE from conda.common.path import expand, strip_pkg_extension from conda.core.package_cache_data import ( @@ -20,6 +21,7 @@ write_as_json_to_file, ) from conda.gateways.disk.update import touch + from conda_store_server import action, conda_utils diff --git a/conda-store-server/conda_store_server/action/generate_conda_pack.py b/conda-store-server/conda_store_server/action/generate_conda_pack.py index ba1e4e6d4..9ec8ff3eb 100644 --- a/conda-store-server/conda_store_server/action/generate_conda_pack.py +++ b/conda-store-server/conda_store_server/action/generate_conda_pack.py @@ -1,6 +1,7 @@ import pathlib import conda_pack + from conda_store_server import action diff --git a/conda-store-server/conda_store_server/action/generate_constructor_installer.py b/conda-store-server/conda_store_server/action/generate_constructor_installer.py index 0fbb6afd2..96ae5a6d2 100644 --- a/conda-store-server/conda_store_server/action/generate_constructor_installer.py +++ b/conda-store-server/conda_store_server/action/generate_constructor_installer.py @@ -5,6 +5,7 @@ import warnings import yaml + from conda_store_server import action, schema from conda_store_server.action.utils import logged_command diff --git a/conda-store-server/conda_store_server/action/generate_lockfile.py b/conda-store-server/conda_store_server/action/generate_lockfile.py index 550012426..53c746140 100644 --- a/conda-store-server/conda_store_server/action/generate_lockfile.py +++ b/conda-store-server/conda_store_server/action/generate_lockfile.py @@ -4,7 +4,9 @@ import typing import yaml + from conda_lock.conda_lock import run_lock + from conda_store_server import action, conda_utils, schema from conda_store_server.action.utils import logged_command diff --git a/conda-store-server/conda_store_server/alembic/env.py b/conda-store-server/conda_store_server/alembic/env.py index 6c254d6be..1237115f7 100644 --- a/conda-store-server/conda_store_server/alembic/env.py +++ b/conda-store-server/conda_store_server/alembic/env.py @@ -3,6 +3,7 @@ from alembic import context from sqlalchemy import engine_from_config, pool + # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config @@ -22,10 +23,12 @@ # assumes that alembic is inside directory conda_store_server/alembic/env.py import sys # noqa E402 + sys.path.append(str(pathlib.Path(__file__).parent.parent.parent)) from conda_store_server.orm import Base # noqa E402 + target_metadata = Base.metadata diff --git a/conda-store-server/conda_store_server/alembic/versions/03c839888c82_add_canceled_status.py b/conda-store-server/conda_store_server/alembic/versions/03c839888c82_add_canceled_status.py index 8c30d3b50..6ea34b3bd 100644 --- a/conda-store-server/conda_store_server/alembic/versions/03c839888c82_add_canceled_status.py +++ b/conda-store-server/conda_store_server/alembic/versions/03c839888c82_add_canceled_status.py @@ -5,9 +5,12 @@ Create Date: 2024-01-29 03:56:36.889909 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "03c839888c82" down_revision = "57cd11b949d5" diff --git a/conda-store-server/conda_store_server/alembic/versions/0f7e23ff24ee_add_worker.py b/conda-store-server/conda_store_server/alembic/versions/0f7e23ff24ee_add_worker.py index ca086ebd0..e9d09c62c 100644 --- a/conda-store-server/conda_store_server/alembic/versions/0f7e23ff24ee_add_worker.py +++ b/conda-store-server/conda_store_server/alembic/versions/0f7e23ff24ee_add_worker.py @@ -5,9 +5,12 @@ Create Date: 2023-12-13 21:01:45.546591 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "0f7e23ff24ee" down_revision = "771180018e1b" diff --git a/conda-store-server/conda_store_server/alembic/versions/16f65805dc8f_split_conda_package_into_conda_package_.py b/conda-store-server/conda_store_server/alembic/versions/16f65805dc8f_split_conda_package_into_conda_package_.py index dc6c07944..3e11ec606 100644 --- a/conda-store-server/conda_store_server/alembic/versions/16f65805dc8f_split_conda_package_into_conda_package_.py +++ b/conda-store-server/conda_store_server/alembic/versions/16f65805dc8f_split_conda_package_into_conda_package_.py @@ -5,9 +5,12 @@ Create Date: 2022-08-24 12:01:48.461989 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "16f65805dc8f" down_revision = "5ad723de2abd" diff --git a/conda-store-server/conda_store_server/alembic/versions/30b37e725c32_add_build_key_version.py b/conda-store-server/conda_store_server/alembic/versions/30b37e725c32_add_build_key_version.py index 0313a95f0..61fed110b 100644 --- a/conda-store-server/conda_store_server/alembic/versions/30b37e725c32_add_build_key_version.py +++ b/conda-store-server/conda_store_server/alembic/versions/30b37e725c32_add_build_key_version.py @@ -5,9 +5,12 @@ Create Date: 2023-11-17 14:34:40.688865 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "30b37e725c32" down_revision = "d78e9889566a" diff --git a/conda-store-server/conda_store_server/alembic/versions/48be4072fe58_initial_schema.py b/conda-store-server/conda_store_server/alembic/versions/48be4072fe58_initial_schema.py index 7e3e15d87..9bc337016 100644 --- a/conda-store-server/conda_store_server/alembic/versions/48be4072fe58_initial_schema.py +++ b/conda-store-server/conda_store_server/alembic/versions/48be4072fe58_initial_schema.py @@ -5,9 +5,12 @@ Create Date: 2022-06-01 18:37:12.396138 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "48be4072fe58" down_revision = None diff --git a/conda-store-server/conda_store_server/alembic/versions/57cd11b949d5_add_installer.py b/conda-store-server/conda_store_server/alembic/versions/57cd11b949d5_add_installer.py index db815fe1d..ee4d048aa 100644 --- a/conda-store-server/conda_store_server/alembic/versions/57cd11b949d5_add_installer.py +++ b/conda-store-server/conda_store_server/alembic/versions/57cd11b949d5_add_installer.py @@ -5,9 +5,12 @@ Create Date: 2024-01-28 14:31:35.723505 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "57cd11b949d5" down_revision = "0f7e23ff24ee" diff --git a/conda-store-server/conda_store_server/alembic/versions/5ad723de2abd_adding_container_registry_value_to_enum.py b/conda-store-server/conda_store_server/alembic/versions/5ad723de2abd_adding_container_registry_value_to_enum.py index 3398b7a36..b1670f272 100644 --- a/conda-store-server/conda_store_server/alembic/versions/5ad723de2abd_adding_container_registry_value_to_enum.py +++ b/conda-store-server/conda_store_server/alembic/versions/5ad723de2abd_adding_container_registry_value_to_enum.py @@ -5,9 +5,12 @@ Create Date: 2022-08-05 22:14:34.110642 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "5ad723de2abd" down_revision = "8d63a091aff8" diff --git a/conda-store-server/conda_store_server/alembic/versions/771180018e1b_add_v2_role_mappings.py b/conda-store-server/conda_store_server/alembic/versions/771180018e1b_add_v2_role_mappings.py index a195b7a9f..07d6c352c 100644 --- a/conda-store-server/conda_store_server/alembic/versions/771180018e1b_add_v2_role_mappings.py +++ b/conda-store-server/conda_store_server/alembic/versions/771180018e1b_add_v2_role_mappings.py @@ -5,9 +5,12 @@ Create Date: 2023-11-29 09:02:35.835664 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "771180018e1b" down_revision = "30b37e725c32" diff --git a/conda-store-server/conda_store_server/alembic/versions/8d63a091aff8_add_environment_description.py b/conda-store-server/conda_store_server/alembic/versions/8d63a091aff8_add_environment_description.py index 518362dbf..6645aee1b 100644 --- a/conda-store-server/conda_store_server/alembic/versions/8d63a091aff8_add_environment_description.py +++ b/conda-store-server/conda_store_server/alembic/versions/8d63a091aff8_add_environment_description.py @@ -5,9 +5,12 @@ Create Date: 2022-07-15 14:22:00.351131 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "8d63a091aff8" down_revision = "48be4072fe58" diff --git a/conda-store-server/conda_store_server/alembic/versions/abd7248d5327_adding_a_settings_table.py b/conda-store-server/conda_store_server/alembic/versions/abd7248d5327_adding_a_settings_table.py index 2fd34559d..b801bc907 100644 --- a/conda-store-server/conda_store_server/alembic/versions/abd7248d5327_adding_a_settings_table.py +++ b/conda-store-server/conda_store_server/alembic/versions/abd7248d5327_adding_a_settings_table.py @@ -5,9 +5,12 @@ Create Date: 2023-05-11 16:38:12.210549 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "abd7248d5327" down_revision = "16f65805dc8f" diff --git a/conda-store-server/conda_store_server/alembic/versions/b387747ca9b7_role_mapping.py b/conda-store-server/conda_store_server/alembic/versions/b387747ca9b7_role_mapping.py index 5f899a5bb..7e41b3e15 100644 --- a/conda-store-server/conda_store_server/alembic/versions/b387747ca9b7_role_mapping.py +++ b/conda-store-server/conda_store_server/alembic/versions/b387747ca9b7_role_mapping.py @@ -5,9 +5,12 @@ Create Date: 2023-07-04 14:35:48.177574 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "b387747ca9b7" down_revision = "abd7248d5327" diff --git a/conda-store-server/conda_store_server/alembic/versions/d78e9889566a_add_status_info.py b/conda-store-server/conda_store_server/alembic/versions/d78e9889566a_add_status_info.py index d91938a11..bd81857d1 100644 --- a/conda-store-server/conda_store_server/alembic/versions/d78e9889566a_add_status_info.py +++ b/conda-store-server/conda_store_server/alembic/versions/d78e9889566a_add_status_info.py @@ -5,9 +5,12 @@ Create Date: 2023-11-07 12:25:04.416192 """ + import sqlalchemy as sa + from alembic import op + # revision identifiers, used by Alembic. revision = "d78e9889566a" down_revision = "b387747ca9b7" diff --git a/conda-store-server/conda_store_server/api.py b/conda-store-server/conda_store_server/api.py index 01a6ec9d5..cb4440edc 100644 --- a/conda-store-server/conda_store_server/api.py +++ b/conda-store-server/conda_store_server/api.py @@ -1,10 +1,12 @@ import re + from typing import Any, Dict, List -from conda_store_server import conda_utils, orm, schema, utils from sqlalchemy import distinct, func, null, or_ from sqlalchemy.orm import aliased +from conda_store_server import conda_utils, orm, schema, utils + def list_namespaces(db, show_soft_deleted: bool = False): filters = [] diff --git a/conda-store-server/conda_store_server/app.py b/conda-store-server/conda_store_server/app.py index 8d68dd138..11c085136 100644 --- a/conda-store-server/conda_store_server/app.py +++ b/conda-store-server/conda_store_server/app.py @@ -1,23 +1,13 @@ import datetime import os import sys + from contextlib import contextmanager from typing import Any, Dict import pydantic + from celery import Celery, group -from conda_store_server import ( - CONDA_STORE_DIR, - BuildKey, - api, - conda_utils, - environment, - orm, - registry, - schema, - storage, - utils, -) from sqlalchemy.orm import Session from sqlalchemy.pool import QueuePool from traitlets import ( @@ -34,6 +24,19 @@ ) from traitlets.config import LoggingConfigurable +from conda_store_server import ( + CONDA_STORE_DIR, + BuildKey, + api, + conda_utils, + environment, + orm, + registry, + schema, + storage, + utils, +) + def conda_store_validate_specification( db: Session, diff --git a/conda-store-server/conda_store_server/build.py b/conda-store-server/conda_store_server/build.py index f2b349b08..913189b22 100644 --- a/conda-store-server/conda_store_server/build.py +++ b/conda-store-server/conda_store_server/build.py @@ -9,9 +9,11 @@ import typing import yaml + +from sqlalchemy.orm import Session + from conda_store_server import action, api, conda_utils, orm, schema, utils from conda_store_server.utils import BuildPathError -from sqlalchemy.orm import Session def append_to_logs(db: Session, conda_store, build, logs: typing.Union[str, bytes]): diff --git a/conda-store-server/conda_store_server/dbutil.py b/conda-store-server/conda_store_server/dbutil.py index b76b28ba6..a81e5dd12 100644 --- a/conda-store-server/conda_store_server/dbutil.py +++ b/conda-store-server/conda_store_server/dbutil.py @@ -1,4 +1,5 @@ import os + from contextlib import contextmanager from tempfile import TemporaryDirectory @@ -6,6 +7,7 @@ from alembic.config import Config from sqlalchemy import create_engine, inspect + _here = os.path.abspath(os.path.dirname(__file__)) ALEMBIC_INI_TEMPLATE_PATH = os.path.join(_here, "alembic.ini") diff --git a/conda-store-server/conda_store_server/environment.py b/conda-store-server/conda_store_server/environment.py index b105bdc69..89ef6b8af 100644 --- a/conda-store-server/conda_store_server/environment.py +++ b/conda-store-server/conda_store_server/environment.py @@ -2,6 +2,7 @@ import pydantic import yaml + from conda_store_server import conda_utils, schema diff --git a/conda-store-server/conda_store_server/orm.py b/conda-store-server/conda_store_server/orm.py index 3a626e82c..ba815bbc3 100644 --- a/conda-store-server/conda_store_server/orm.py +++ b/conda-store-server/conda_store_server/orm.py @@ -6,9 +6,6 @@ import shutil import sys -from conda_store_server import conda_utils, schema, utils -from conda_store_server.environment import validate_environment -from conda_store_server.utils import BuildPathError from sqlalchemy import ( JSON, BigInteger, @@ -36,6 +33,11 @@ validates, ) +from conda_store_server import conda_utils, schema, utils +from conda_store_server.environment import validate_environment +from conda_store_server.utils import BuildPathError + + logger = logging.getLogger("orm") Base = declarative_base() diff --git a/conda-store-server/conda_store_server/registry.py b/conda-store-server/conda_store_server/registry.py index a1f76b88e..e793cb7f0 100644 --- a/conda-store-server/conda_store_server/registry.py +++ b/conda-store-server/conda_store_server/registry.py @@ -2,12 +2,13 @@ import hashlib import urllib.parse -from conda_store_server import orm, schema, utils from python_docker.registry import Image, Registry from sqlalchemy.orm import Session from traitlets import Callable, Dict, default from traitlets.config import LoggingConfigurable +from conda_store_server import orm, schema, utils + class ContainerRegistry(LoggingConfigurable): container_registries = Dict( diff --git a/conda-store-server/conda_store_server/schema.py b/conda-store-server/conda_store_server/schema.py index 52142b4a9..03303602d 100644 --- a/conda-store-server/conda_store_server/schema.py +++ b/conda-store-server/conda_store_server/schema.py @@ -4,11 +4,13 @@ import os import re import sys + from typing import Any, Callable, Dict, List, Optional, Union -from conda_store_server import conda_utils, utils from pydantic import BaseModel, Field, ValidationError, constr, validator +from conda_store_server import conda_utils, utils + def _datetime_factory(offset: datetime.timedelta): """utcnow datetime + timezone as string""" diff --git a/conda-store-server/conda_store_server/server/__main__.py b/conda-store-server/conda_store_server/server/__main__.py index 3ffe529ee..27733bd18 100644 --- a/conda-store-server/conda_store_server/server/__main__.py +++ b/conda-store-server/conda_store_server/server/__main__.py @@ -1,5 +1,6 @@ from conda_store_server.server.app import CondaStoreServer + main = CondaStoreServer.launch_instance if __name__ == "__main__": diff --git a/conda-store-server/conda_store_server/server/app.py b/conda-store-server/conda_store_server/server/app.py index a23ef150f..639630158 100644 --- a/conda-store-server/conda_store_server/server/app.py +++ b/conda-store-server/conda_store_server/server/app.py @@ -3,15 +3,12 @@ import posixpath import sys import time + from enum import Enum from threading import Thread -import conda_store_server -import conda_store_server.dbutil as dbutil import uvicorn -from conda_store_server import __version__, orm, storage -from conda_store_server.app import CondaStore -from conda_store_server.server import auth, views + from fastapi import FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import FileResponse, JSONResponse, RedirectResponse @@ -32,6 +29,13 @@ ) from traitlets.config import Application, catch_config_error +import conda_store_server +import conda_store_server.dbutil as dbutil + +from conda_store_server import __version__, orm, storage +from conda_store_server.app import CondaStore +from conda_store_server.server import auth, views + class _Color(str, Enum): GREEN = "\x1b[32m" diff --git a/conda-store-server/conda_store_server/server/auth.py b/conda-store-server/conda_store_server/server/auth.py index 4e1c37420..672107ad3 100644 --- a/conda-store-server/conda_store_server/server/auth.py +++ b/conda-store-server/conda_store_server/server/auth.py @@ -2,14 +2,14 @@ import datetime import re import secrets + from collections import defaultdict from typing import Optional import jwt import requests import yarl -from conda_store_server import api, orm, schema, utils -from conda_store_server.server import dependencies + from fastapi import APIRouter, Depends, HTTPException, Request, Response from fastapi.encoders import jsonable_encoder from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse @@ -30,6 +30,10 @@ ) from traitlets.config import LoggingConfigurable +from conda_store_server import api, orm, schema, utils +from conda_store_server.server import dependencies + + ARN_ALLOWED_REGEX = re.compile(schema.ARN_ALLOWED) diff --git a/conda-store-server/conda_store_server/server/views/api.py b/conda-store-server/conda_store_server/server/views/api.py index 72c6826cf..03db854ea 100644 --- a/conda-store-server/conda_store_server/server/views/api.py +++ b/conda-store-server/conda_store_server/server/views/api.py @@ -1,13 +1,17 @@ import datetime + from typing import Any, Dict, List, Optional import pydantic import yaml + +from fastapi import APIRouter, Body, Depends, HTTPException, Query, Request +from fastapi.responses import PlainTextResponse, RedirectResponse + from conda_store_server import __version__, api, orm, schema, utils from conda_store_server.schema import Permissions from conda_store_server.server import dependencies -from fastapi import APIRouter, Body, Depends, HTTPException, Query, Request -from fastapi.responses import PlainTextResponse, RedirectResponse + router_api = APIRouter( tags=["api"], @@ -145,9 +149,11 @@ async def api_get_permissions( "status": "ok", "data": { "authenticated": authenticated, - "primary_namespace": entity.primary_namespace - if authenticated - else conda_store.default_namespace, + "primary_namespace": ( + entity.primary_namespace + if authenticated + else conda_store.default_namespace + ), "entity_permissions": entity_binding_permissions, "entity_roles": entity_binding_roles, "expiration": entity.exp if authenticated else None, diff --git a/conda-store-server/conda_store_server/server/views/conda_store_ui.py b/conda-store-server/conda_store_server/server/views/conda_store_ui.py index 4dae09b8f..ae944902a 100644 --- a/conda-store-server/conda_store_server/server/views/conda_store_ui.py +++ b/conda-store-server/conda_store_server/server/views/conda_store_ui.py @@ -1,6 +1,8 @@ -from conda_store_server.server import dependencies from fastapi import APIRouter, Depends, Request +from conda_store_server.server import dependencies + + router_conda_store_ui = APIRouter(tags=["conda-store-ui"]) diff --git a/conda-store-server/conda_store_server/server/views/metrics.py b/conda-store-server/conda_store_server/server/views/metrics.py index 962c52246..d9286a1fe 100644 --- a/conda-store-server/conda_store_server/server/views/metrics.py +++ b/conda-store-server/conda_store_server/server/views/metrics.py @@ -1,8 +1,10 @@ -from conda_store_server import api -from conda_store_server.server import dependencies from fastapi import APIRouter, Depends from fastapi.responses import PlainTextResponse +from conda_store_server import api +from conda_store_server.server import dependencies + + router_metrics = APIRouter(tags=["metrics"]) diff --git a/conda-store-server/conda_store_server/server/views/registry.py b/conda-store-server/conda_store_server/server/views/registry.py index 7acd480c5..b6dd323d5 100644 --- a/conda-store-server/conda_store_server/server/views/registry.py +++ b/conda-store-server/conda_store_server/server/views/registry.py @@ -1,11 +1,13 @@ import json import time +from fastapi import APIRouter, Depends, HTTPException, Request +from fastapi.responses import RedirectResponse, Response + from conda_store_server import api, orm, schema from conda_store_server.schema import Permissions from conda_store_server.server import dependencies -from fastapi import APIRouter, Depends, HTTPException, Request -from fastapi.responses import RedirectResponse, Response + router_registry = APIRouter(tags=["registry"]) @@ -159,9 +161,11 @@ def list_tags( try: auth.authorize_request( request, - image - if parts[0] != "conda-store-dynamic" - else "conda-store-dynamic/python", + ( + image + if parts[0] != "conda-store-dynamic" + else "conda-store-dynamic/python" + ), {Permissions.ENVIRONMENT_READ}, require=True, ) diff --git a/conda-store-server/conda_store_server/server/views/ui.py b/conda-store-server/conda_store_server/server/views/ui.py index 522891f3c..b7b260f56 100644 --- a/conda-store-server/conda_store_server/server/views/ui.py +++ b/conda-store-server/conda_store_server/server/views/ui.py @@ -1,14 +1,17 @@ from typing import Optional import yaml + +from fastapi import APIRouter, Depends, Request +from fastapi.responses import RedirectResponse + from conda_store_server import api from conda_store_server.action.generate_constructor_installer import ( get_installer_platform, ) from conda_store_server.schema import Permissions from conda_store_server.server import dependencies -from fastapi import APIRouter, Depends, Request -from fastapi.responses import RedirectResponse + router_ui = APIRouter(tags=["ui"]) diff --git a/conda-store-server/conda_store_server/storage.py b/conda-store-server/conda_store_server/storage.py index 1ee77a5ea..2e37ec6d7 100644 --- a/conda-store-server/conda_store_server/storage.py +++ b/conda-store-server/conda_store_server/storage.py @@ -4,11 +4,13 @@ import shutil import minio -from conda_store_server import CONDA_STORE_DIR, api, orm, schema + from minio.credentials.providers import Provider from traitlets import Bool, Dict, List, Type, Unicode from traitlets.config import LoggingConfigurable +from conda_store_server import CONDA_STORE_DIR, api, orm, schema + class Storage(LoggingConfigurable): def fset( diff --git a/conda-store-server/conda_store_server/testing.py b/conda-store-server/conda_store_server/testing.py index da5c65bcb..96cfce2b7 100644 --- a/conda-store-server/conda_store_server/testing.py +++ b/conda-store-server/conda_store_server/testing.py @@ -2,9 +2,10 @@ import typing import uuid -from conda_store_server import api, conda_utils, orm, schema from sqlalchemy.orm import Session +from conda_store_server import api, conda_utils, orm, schema + def seed_conda_store( db: Session, diff --git a/conda-store-server/conda_store_server/worker/__main__.py b/conda-store-server/conda_store_server/worker/__main__.py index 88c22474c..ec0d7a439 100644 --- a/conda-store-server/conda_store_server/worker/__main__.py +++ b/conda-store-server/conda_store_server/worker/__main__.py @@ -1,5 +1,6 @@ from conda_store_server.worker.app import CondaStoreWorker + main = CondaStoreWorker.launch_instance if __name__ == "__main__": diff --git a/conda-store-server/conda_store_server/worker/app.py b/conda-store-server/conda_store_server/worker/app.py index b3278a395..e8400c7f3 100644 --- a/conda-store-server/conda_store_server/worker/app.py +++ b/conda-store-server/conda_store_server/worker/app.py @@ -2,10 +2,11 @@ import os import sys -from conda_store_server.app import CondaStore from traitlets import Integer, List, Unicode, validate from traitlets.config import Application, catch_config_error +from conda_store_server.app import CondaStore + class CondaStoreWorker(Application): aliases = { diff --git a/conda-store-server/conda_store_server/worker/tasks.py b/conda-store-server/conda_store_server/worker/tasks.py index e87cc6a99..9c601b1c3 100644 --- a/conda-store-server/conda_store_server/worker/tasks.py +++ b/conda-store-server/conda_store_server/worker/tasks.py @@ -5,9 +5,13 @@ import typing import yaml + from celery import Task, platforms, shared_task from celery.execute import send_task from celery.signals import worker_ready +from filelock import FileLock +from sqlalchemy.orm import Session + from conda_store_server import api, environment, schema, utils from conda_store_server.build import ( build_cleanup, @@ -19,8 +23,6 @@ solve_conda_environment, ) from conda_store_server.worker.app import CondaStoreWorker -from filelock import FileLock -from sqlalchemy.orm import Session @worker_ready.connect diff --git a/conda-store-server/hatch_build.py b/conda-store-server/hatch_build.py index b4e55c75d..742db2503 100644 --- a/conda-store-server/hatch_build.py +++ b/conda-store-server/hatch_build.py @@ -4,10 +4,12 @@ import tarfile import tempfile import urllib.request + from typing import Any, Dict, List from hatchling.builders.hooks.plugin.interface import BuildHookInterface + CONDA_STORE_UI_VERSION = "2024.3.1" CONDA_STORE_UI_URL = f"https://registry.npmjs.org/@conda-store/conda-store-ui/-/conda-store-ui-{CONDA_STORE_UI_VERSION}.tgz" CONDA_STORE_UI_FILES = [ diff --git a/conda-store-server/pyproject.toml b/conda-store-server/pyproject.toml index 9ca81b171..5726afb07 100644 --- a/conda-store-server/pyproject.toml +++ b/conda-store-server/pyproject.toml @@ -112,10 +112,13 @@ conda-store-worker = "conda_store_server.worker.__main__:main" line-length = 88 target-version = ['py37', 'py38', 'py39'] +[tool.isort] +lines_between_types = 1 +lines_after_imports = 2 + [tool.ruff] ignore = [ "E501", # line-length - ] [tool.check-wheel-contents] diff --git a/conda-store-server/tests/conftest.py b/conda-store-server/tests/conftest.py index 32ed0bda5..9644afd80 100644 --- a/conda-store-server/tests/conftest.py +++ b/conda-store-server/tests/conftest.py @@ -4,8 +4,10 @@ import pytest import yaml + from fastapi.testclient import TestClient + from conda_store_server import ( # isort:skip action, api, @@ -84,11 +86,11 @@ def conda_store_server(conda_store_config): _conda_store.celery_app # must import tasks after a celery app has been initialized - import conda_store_server.worker.tasks # noqa - # ensure that models are created from celery.backends.database.session import ResultModelBase + import conda_store_server.worker.tasks # noqa + ResultModelBase.metadata.create_all(db.get_bind()) yield _conda_store_server @@ -167,11 +169,11 @@ def conda_store(conda_store_config): _conda_store.celery_app # must import tasks after a celery app has been initialized - import conda_store_server.worker.tasks # noqa - # ensure that models are created from celery.backends.database.session import ResultModelBase + import conda_store_server.worker.tasks # noqa + ResultModelBase.metadata.create_all(db.get_bind()) yield _conda_store diff --git a/conda-store-server/tests/test_actions.py b/conda-store-server/tests/test_actions.py index 02f710481..de9419548 100644 --- a/conda-store-server/tests/test_actions.py +++ b/conda-store-server/tests/test_actions.py @@ -7,6 +7,10 @@ import pytest import yarl + +from fastapi.responses import RedirectResponse +from traitlets import TraitError + from conda_store_server import ( BuildKey, action, @@ -18,8 +22,6 @@ utils, ) from conda_store_server.server.auth import DummyAuthentication -from fastapi.responses import RedirectResponse -from traitlets import TraitError def test_action_decorator(): diff --git a/conda-store-server/tests/test_app_api.py b/conda-store-server/tests/test_app_api.py index e08d81c67..b3aa6a134 100644 --- a/conda-store-server/tests/test_app_api.py +++ b/conda-store-server/tests/test_app_api.py @@ -1,6 +1,7 @@ import sys from celery.result import AsyncResult + from conda_store_server import api, schema diff --git a/conda-store-server/tests/test_auth.py b/conda-store-server/tests/test_auth.py index 99145d5ff..37af313a1 100644 --- a/conda-store-server/tests/test_auth.py +++ b/conda-store-server/tests/test_auth.py @@ -2,6 +2,7 @@ import uuid import pytest + from conda_store_server.schema import AuthenticationToken, Permissions from conda_store_server.server.auth import ( AuthenticationBackend, diff --git a/conda-store-server/tests/test_db_api.py b/conda-store-server/tests/test_db_api.py index 25b86cdf8..ee64f3916 100644 --- a/conda-store-server/tests/test_db_api.py +++ b/conda-store-server/tests/test_db_api.py @@ -1,4 +1,5 @@ import pytest + from conda_store_server import api from conda_store_server.orm import NamespaceRoleMapping from conda_store_server.utils import BuildPathError diff --git a/conda-store-server/tests/test_server.py b/conda-store-server/tests/test_server.py index 4624f3650..9ffa27610 100644 --- a/conda-store-server/tests/test_server.py +++ b/conda-store-server/tests/test_server.py @@ -5,6 +5,7 @@ import pytest import traitlets import yaml + from conda_store_server import __version__, schema diff --git a/conda-store-server/tests/test_traitlets.py b/conda-store-server/tests/test_traitlets.py index eb9af5daf..956b9f87d 100644 --- a/conda-store-server/tests/test_traitlets.py +++ b/conda-store-server/tests/test_traitlets.py @@ -2,10 +2,12 @@ import tempfile import pytest -from conda_store_server import schema + from fastapi.templating import Jinja2Templates from fastapi.testclient import TestClient +from conda_store_server import schema + def test_conda_store_server_enable_ui(conda_store_server): conda_store_server.enable_ui = False diff --git a/conda-store-server/tests/test_usage.py b/conda-store-server/tests/test_usage.py index 98833938c..c4e733274 100644 --- a/conda-store-server/tests/test_usage.py +++ b/conda-store-server/tests/test_usage.py @@ -1,5 +1,6 @@ from conda_store_server.utils import disk_usage, du + # TODO: Add tests for the other functions in utils.py diff --git a/conda-store-server/tests/user_journeys/test_user_journeys.py b/conda-store-server/tests/user_journeys/test_user_journeys.py index 49584a5f0..a55e93b46 100644 --- a/conda-store-server/tests/user_journeys/test_user_journeys.py +++ b/conda-store-server/tests/user_journeys/test_user_journeys.py @@ -1,4 +1,5 @@ """User journey tests for the API.""" + import os import pytest diff --git a/conda-store-server/tests/user_journeys/utils/api_utils.py b/conda-store-server/tests/user_journeys/utils/api_utils.py index 0a50fd321..657f5e261 100644 --- a/conda-store-server/tests/user_journeys/utils/api_utils.py +++ b/conda-store-server/tests/user_journeys/utils/api_utils.py @@ -1,12 +1,15 @@ """Helper functions for user journeys.""" + import time import uuid + from enum import Enum from typing import Union import requests import utils.time_utils as time_utils + TIMEOUT = 10 diff --git a/conda-store/conda_store/api.py b/conda-store/conda_store/api.py index c67823fca..b3b6656ef 100644 --- a/conda-store/conda_store/api.py +++ b/conda-store/conda_store/api.py @@ -1,9 +1,11 @@ import datetime import math import os + from typing import Dict, List import yarl + from conda_store import auth, exception, utils diff --git a/conda-store/conda_store/auth.py b/conda-store/conda_store/auth.py index 5dcc08038..d9af2787b 100644 --- a/conda-store/conda_store/auth.py +++ b/conda-store/conda_store/auth.py @@ -1,5 +1,6 @@ import aiohttp import yarl + from conda_store import utils diff --git a/conda-store/conda_store/cli.py b/conda-store/conda_store/cli.py index 73f077635..9151aa4fd 100644 --- a/conda-store/conda_store/cli.py +++ b/conda-store/conda_store/cli.py @@ -4,9 +4,11 @@ import re import tempfile import time + from typing import List import click + from conda_store import __version__, api, exception, runner, utils from ruamel.yaml import YAML diff --git a/conda-store/conda_store/runner.py b/conda-store/conda_store/runner.py index 915f2a7a4..b38c815b0 100644 --- a/conda-store/conda_store/runner.py +++ b/conda-store/conda_store/runner.py @@ -3,6 +3,7 @@ import shlex import subprocess import tarfile + from typing import List from conda_store import api diff --git a/conda-store/conda_store/utils.py b/conda-store/conda_store/utils.py index c25e9e85f..dffd09658 100644 --- a/conda-store/conda_store/utils.py +++ b/conda-store/conda_store/utils.py @@ -2,12 +2,14 @@ import functools import json import sys + from typing import Dict, List from conda_store import exception from rich.console import Console from rich.table import Table + console = Console() error_console = Console(stderr=True, style="bold red") diff --git a/conda-store/pyproject.toml b/conda-store/pyproject.toml index 0967991f7..a090fe501 100644 --- a/conda-store/pyproject.toml +++ b/conda-store/pyproject.toml @@ -58,8 +58,13 @@ dependencies = [ "pytest-mock", ] -[tool.hatch.envs.dev.scripts] +[tool.hatch.envs.lint] +dependencies = ["pre-commit"] + +[tool.hatch.envs.lint.scripts] lint = ["pre-commit run --all"] + +[tool.hatch.envs.dev.scripts] test = "pytest tests" [project.scripts] @@ -72,5 +77,8 @@ target-version = ['py38', 'py39', 'py310'] [tool.ruff] ignore = [ "E501", # line-length - ] + +[tool.isort] +lines_between_types = 1 +lines_after_imports = 2 diff --git a/docusaurus-docs/community/contribute/testing.md b/docusaurus-docs/community/contribute/testing.md index 12de02587..10596b735 100644 --- a/docusaurus-docs/community/contribute/testing.md +++ b/docusaurus-docs/community/contribute/testing.md @@ -14,7 +14,7 @@ Linting and formatting checks can be performed via hatch. ```shell $ cd conda-store -$ hatch env run -e dev lint +$ hatch env run -e lint lint ``` Running integration tests. These tests are stateful! So you will need @@ -43,7 +43,7 @@ Linting and formatting checks can be performed via hatch. ```shell $ cd conda-store-server -$ hatch env run -e dev lint +$ hatch env run -e lint lint ``` Checking that the package builds diff --git a/examples/docker-without-nfs/assets/conda_store_config.py b/examples/docker-without-nfs/assets/conda_store_config.py index a6a97b9a5..01dc5fe30 100644 --- a/examples/docker-without-nfs/assets/conda_store_config.py +++ b/examples/docker-without-nfs/assets/conda_store_config.py @@ -3,6 +3,7 @@ from conda_store_server.server.auth import JupyterHubOAuthAuthentication from conda_store_server.storage import S3Storage + # ================================== # conda-store settings # ================================== diff --git a/examples/docker-without-nfs/assets/jupyterhub_config.py b/examples/docker-without-nfs/assets/jupyterhub_config.py index f097b0cae..35fd27b16 100644 --- a/examples/docker-without-nfs/assets/jupyterhub_config.py +++ b/examples/docker-without-nfs/assets/jupyterhub_config.py @@ -7,6 +7,7 @@ from jupyterhub.spawner import SimpleLocalProcessSpawner from jupyterhub.utils import maybe_future + c.JupyterHub.ip = "0.0.0.0" c.JupyterHub.authenticator_class = DummyAuthenticator diff --git a/examples/docker/assets/conda_store_config.py b/examples/docker/assets/conda_store_config.py index b37390a76..60798f071 100644 --- a/examples/docker/assets/conda_store_config.py +++ b/examples/docker/assets/conda_store_config.py @@ -3,6 +3,7 @@ from conda_store_server.server.auth import JupyterHubOAuthAuthentication from conda_store_server.storage import S3Storage + # ================================== # conda-store settings # ================================== diff --git a/examples/docker/assets/jupyterhub_config.py b/examples/docker/assets/jupyterhub_config.py index d675ab411..c8d6fb139 100644 --- a/examples/docker/assets/jupyterhub_config.py +++ b/examples/docker/assets/jupyterhub_config.py @@ -4,6 +4,7 @@ from jupyterhub.auth import DummyAuthenticator from jupyterhub.spawner import SimpleLocalProcessSpawner + c.JupyterHub.ip = "0.0.0.0" c.JupyterHub.authenticator_class = DummyAuthenticator diff --git a/examples/kubernetes/files/conda_store_config.py b/examples/kubernetes/files/conda_store_config.py index 5f3aa15d0..ea7be3756 100644 --- a/examples/kubernetes/files/conda_store_config.py +++ b/examples/kubernetes/files/conda_store_config.py @@ -3,6 +3,7 @@ from conda_store_server.server.auth import DummyAuthentication from conda_store_server.storage import S3Storage + # ================================== # conda-store settings # ================================== diff --git a/tests/assets/conda_store_config.py b/tests/assets/conda_store_config.py index 7b7d47d4b..d657849ce 100644 --- a/tests/assets/conda_store_config.py +++ b/tests/assets/conda_store_config.py @@ -3,6 +3,7 @@ from conda_store_server.server.auth import DummyAuthentication from conda_store_server.storage import S3Storage + # ================================== # conda-store settings # ================================== diff --git a/tests/conftest.py b/tests/conftest.py index aa3135329..0753ed599 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,13 @@ import os import sys + from urllib.parse import urljoin import pytest + from requests import Session + sys.path.append(os.path.join(os.getcwd(), "conda-store-server")) diff --git a/tests/test_api.py b/tests/test_api.py index 9583249b1..c2d758056 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -8,6 +8,7 @@ ordering for tests. """ + import asyncio import collections import datetime @@ -15,12 +16,15 @@ import statistics import time import uuid + from functools import partial import aiohttp -import conda_store_server import pytest import requests + +import conda_store_server + from conda_store_server import schema from .conftest import CONDA_STORE_BASE_URL diff --git a/tests/test_playwright.py b/tests/test_playwright.py index f9fd0f7be..3e0221270 100644 --- a/tests/test_playwright.py +++ b/tests/test_playwright.py @@ -1,6 +1,7 @@ import time import pytest + from playwright.sync_api import Page