Skip to content

Commit

Permalink
[MAINT] Update lint tooling (conda-incubator#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
peytondmurray authored Oct 30, 2024
1 parent 30c35ee commit eaa0968
Show file tree
Hide file tree
Showing 39 changed files with 132 additions and 120 deletions.
18 changes: 3 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ ci:
[pre-commit.ci] Apply automatic pre-commit fixes
repos:
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
exclude: "examples|tests/assets"

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: "v0.6.3"
hooks:
- id: ruff
exclude: "examples|tests/assets"
args: ["--fix"]
args: ["--fix", "--show-fixes"]
- id: ruff-format
exclude: "examples|tests/assets"

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand All @@ -41,11 +37,3 @@ repos:
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"
17 changes: 12 additions & 5 deletions conda-store-server/conda_store_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Copyright (c) conda-store development team. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
from __future__ import annotations

import datetime
import hashlib
import typing

import platformdirs

if typing.TYPE_CHECKING:
from ._internal.orm import Build
from .app import CondaStore


__version__ = "2024.11.1-dev"

Expand Down Expand Up @@ -39,15 +44,15 @@ class BuildKey:

_version3_experimental_hash_size = 32

def _version1_fmt(build: "Build") -> str: # noqa: F821
def _version1_fmt(build: Build) -> str: # noqa: F821
datetime_format = "%Y%m%d-%H%M%S-%f"
hash = build.specification.sha256
timestamp = build.scheduled_on.strftime(datetime_format)
id = build.id
name = build.specification.name
return f"{hash}-{timestamp}-{id}-{name}"

def _version2_fmt(build: "Build") -> str: # noqa: F821
def _version2_fmt(build: Build) -> str: # noqa: F821
tzinfo = datetime.timezone.utc
hash = build.specification.sha256[: BuildKey._version2_hash_size]
timestamp = int(build.scheduled_on.replace(tzinfo=tzinfo).timestamp())
Expand All @@ -56,7 +61,7 @@ def _version2_fmt(build: "Build") -> str: # noqa: F821
return f"{hash}-{timestamp}-{id}-{name}"

# Warning: this is an experimental version and can be changed at any time
def _version3_experimental_fmt(build: "Build") -> str: # noqa: F821
def _version3_experimental_fmt(build: Build) -> str: # noqa: F821
# Caches the hash value for faster lookup later
if build.hash is not None:
return build.hash
Expand Down Expand Up @@ -113,14 +118,16 @@ def versions(cls) -> typing.Tuple[int]:
return tuple(cls._fmt.keys())

@classmethod
def get_build_key(cls, build: "Build") -> str: # noqa: F821
def get_build_key(cls, build: Build) -> str: # noqa: F821
"""Returns build key for this build"""
cls._check_version(build.build_key_version)
return cls._fmt.get(build.build_key_version)(build)

@classmethod
def parse_build_key(
cls, conda_store: "CondaStore", build_key: str # noqa: F821
cls,
conda_store: CondaStore,
build_key: str, # noqa: F821
) -> int:
"""Returns build id from build key"""
# This import is here to avoid cyclic imports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import sys
import tempfile
import warnings

from typing import Union

import yaml
Expand Down Expand Up @@ -54,7 +53,7 @@ def write_file(filename, s):
warnings.warn(
"Installer generation requires constructor: https://github.com/conda/constructor"
)
return
return None

# pip dependencies are not directly supported by constructor, they will be
# installed via the post_install script:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import typing

import yaml

from conda_lock.conda_lock import run_lock

from conda_store_server._internal import action, conda_utils, schema, utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion conda-store-server/conda_store_server/_internal/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import typing

import yaml

from filelock import FileLock
from sqlalchemy.orm import Session

Expand Down
2 changes: 0 additions & 2 deletions conda-store-server/conda_store_server/_internal/dbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import json
import os

from contextlib import contextmanager
from functools import partial
from tempfile import TemporaryDirectory
Expand All @@ -15,7 +14,6 @@

from conda_store_server._internal import utils


_here = os.path.abspath(os.path.dirname(__file__))

ALEMBIC_INI_TEMPLATE_PATH = os.path.join(_here, "alembic.ini")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import pydantic
import yaml

from sqlalchemy import and_, or_
from sqlalchemy.orm import Query

Expand Down
2 changes: 0 additions & 2 deletions conda-store-server/conda_store_server/_internal/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pathlib
import shutil
import sys

from functools import partial

from sqlalchemy import (
Expand Down Expand Up @@ -42,7 +41,6 @@
from conda_store_server._internal import conda_utils, schema, utils
from conda_store_server._internal.environment import validate_environment


logger = logging.getLogger("orm")

Base = declarative_base()
Expand Down
8 changes: 4 additions & 4 deletions conda-store-server/conda_store_server/_internal/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import re
import sys

from typing import Any, Callable, Dict, List, Optional, TypeAlias, Union

from conda_lock.lockfile.v1.models import Lockfile
Expand All @@ -19,7 +18,7 @@


def _datetime_factory(offset: datetime.timedelta):
"""utcnow datetime + timezone as string"""
"""Utcnow datetime + timezone as string"""
return datetime.datetime.utcnow() + offset


Expand All @@ -41,7 +40,8 @@ def _datetime_factory(offset: datetime.timedelta):


class Permissions(enum.Enum):
"Permissions map to conda-store actions"
"""Permissions map to conda-store actions"""

ENVIRONMENT_CREATE = "environment:create"
ENVIRONMENT_READ = "environment::read"
ENVIRONMENT_UPDATE = "environment::update"
Expand Down Expand Up @@ -528,7 +528,7 @@ def __str__(self):


def _docker_datetime_factory():
"""utcnow datetime + timezone as string"""
"""Utcnow datetime + timezone as string"""
return datetime.datetime.utcnow().astimezone().isoformat()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from conda_store_server._internal.server.app import CondaStoreServer


main = CondaStoreServer.launch_instance

if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import posixpath
import sys
import time

from enum import Enum
from threading import Thread

import uvicorn

from fastapi import FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, JSONResponse, RedirectResponse
Expand All @@ -34,7 +32,6 @@
from traitlets.config import Application, catch_config_error

import conda_store_server

from conda_store_server import __version__, storage
from conda_store_server._internal import dbutil, orm
from conda_store_server._internal.server import views
Expand Down Expand Up @@ -167,9 +164,7 @@ def _default_templates(self):
def _validate_config_file(self, proposal):
if not os.path.isfile(proposal.value):
print(
"ERROR: Failed to find specified config file: {}".format(
proposal.value
),
f"ERROR: Failed to find specified config file: {proposal.value}",
file=sys.stderr,
)
sys.exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
# license that can be found in the LICENSE file.

import datetime

from typing import Any, Dict, List, Optional, TypedDict

import pydantic
import yaml

from celery.result import AsyncResult
from fastapi import APIRouter, Body, Depends, HTTPException, Query, Request
from fastapi.responses import PlainTextResponse, RedirectResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from conda_store_server.server import dependencies


router_conda_store_ui = APIRouter(tags=["conda-store-ui"])


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from conda_store_server import api
from conda_store_server.server import dependencies


router_metrics = APIRouter(tags=["metrics"])


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from conda_store_server._internal.schema import Permissions
from conda_store_server.server import dependencies


router_registry = APIRouter(tags=["registry"])


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Optional

import yaml

from fastapi import APIRouter, Depends, Request
from fastapi.responses import RedirectResponse

Expand All @@ -16,7 +15,6 @@
from conda_store_server._internal.schema import Permissions
from conda_store_server.server import dependencies


router_ui = APIRouter(tags=["ui"])


Expand All @@ -38,7 +36,7 @@ async def ui_create_get_environment(
)

def sort_namespace(n):
"Default namespace always first, then alphabetical"
"""Default namespace always first, then alphabetical"""
if n.name == default_namespace:
return f"0{n.name}"
return f"1{n.name}"
Expand Down
1 change: 0 additions & 1 deletion conda-store-server/conda_store_server/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import subprocess
import sys
import time

from typing import AnyStr

from filelock import FileLock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from conda_store_server._internal.worker.app import CondaStoreWorker


main = CondaStoreWorker.launch_instance

if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ class CondaStoreWorker(Application):
def _validate_config_file(self, proposal):
if not os.path.isfile(proposal.value):
print(
"ERROR: Failed to find specified config file: {}".format(
proposal.value
),
f"ERROR: Failed to find specified config file: {proposal.value}",
file=sys.stderr,
)
sys.exit(1)
Expand Down Expand Up @@ -85,7 +83,6 @@ def logger_to_celery_logging_level(self, logging_level):
return logging_to_celery_level_map[logging_level]

def start(self):

argv = [
"worker",
f"--loglevel={self.logger_to_celery_logging_level(self.log_level)}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import typing

import yaml

from celery import Task, platforms, shared_task
from celery.execute import send_task
from celery.signals import worker_ready
Expand Down
5 changes: 1 addition & 4 deletions conda-store-server/conda_store_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import annotations

import re

from typing import Any, Dict, List, Union

from sqlalchemy import distinct, func, null, or_
Expand Down Expand Up @@ -569,9 +568,7 @@ def get_build_lockfile_legacy(db, build_id: int):
return """#platform: {0}
@EXPLICIT
{1}
""".format(
conda_utils.conda_platform(), "\n".join(packages)
)
""".format(conda_utils.conda_platform(), "\n".join(packages))


def get_build_artifact_types(db, build_id: int):
Expand Down
Loading

0 comments on commit eaa0968

Please sign in to comment.