Skip to content

Commit

Permalink
Privatize internal conda-store API
Browse files Browse the repository at this point in the history
  • Loading branch information
peytondmurray committed May 6, 2024
1 parent b40b7e3 commit 5e45798
Show file tree
Hide file tree
Showing 86 changed files with 127 additions and 120 deletions.
41 changes: 41 additions & 0 deletions conda-store-server/conda_store_server/_internal/action/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from conda_store_server._internal.action.add_conda_prefix_packages import ( # noqa
action_add_conda_prefix_packages,
)
from conda_store_server._internal.action.add_lockfile_packages import ( # noqa
action_add_lockfile_packages,
)
from conda_store_server._internal.action.base import action # noqa
from conda_store_server._internal.action.download_packages import ( # noqa
action_fetch_and_extract_conda_packages,
)
from conda_store_server._internal.action.generate_conda_docker import ( # noqa
action_generate_conda_docker,
)
from conda_store_server._internal.action.generate_conda_export import ( # noqa
action_generate_conda_export,
)
from conda_store_server._internal.action.generate_conda_pack import ( # noqa
action_generate_conda_pack,
)
from conda_store_server._internal.action.generate_constructor_installer import ( # noqa
action_generate_constructor_installer,
)
from conda_store_server._internal.action.generate_lockfile import ( # noqa
action_save_lockfile,
action_solve_lockfile,
)
from conda_store_server._internal.action.get_conda_prefix_stats import ( # noqa
action_get_conda_prefix_stats,
)
from conda_store_server._internal.action.install_lockfile import ( # noqa
action_install_lockfile,
)
from conda_store_server._internal.action.install_specification import ( # noqa
action_install_specification,
)
from conda_store_server._internal.action.remove_conda_prefix import ( # noqa
action_remove_conda_prefix,
)
from conda_store_server._internal.action.set_conda_prefix_permissions import ( # noqa
action_set_conda_prefix_permissions,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from conda.core.prefix_data import PrefixData

from conda_store_server import action, api
from conda_store_server import api
from conda_store_server._internal import action


def list_conda_prefix_packages(conda_prefix: pathlib.Path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from conda.models.dist import Dist

from conda_store_server import action, api, conda_utils
from conda_store_server import api
from conda_store_server._internal import action, conda_utils


def list_lockfile_packages(conda_lock_spec: typing.Dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import typing
import uuid

from conda_store_server import utils
from conda_store_server._internal import utils


def action(f: typing.Callable):
Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(self, stdout=None, stderr=None):
self.id = str(uuid.uuid4())
self.stdout = stdout if stdout is not None else io.StringIO()
self.stderr = stderr if stderr is not None else io.StringIO()
self.log = logging.getLogger(f"conda_store_server.action.{self.id}")
self.log = logging.getLogger(f"conda_store_server._internal.action.{self.id}")
self.log.propagate = False
self.log.addHandler(logging.StreamHandler(stream=self.stdout))
self.log.setLevel(logging.INFO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from conda.gateways.disk.update import touch

from conda_store_server import action, conda_utils
from conda_store_server._internal import action, conda_utils


@action.action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pathlib

from conda_store_server import action
from conda_store_server._internal import action


@action.action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import pathlib

from conda_store_server import action
from conda_store_server._internal import action


@action.action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import conda_pack

from conda_store_server import action
from conda_store_server._internal import action


@action.action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import yaml

from conda_store_server import action, schema
from conda_store_server.action.utils import logged_command
from conda_store_server._internal import action, schema


def get_installer_platform():
Expand Down Expand Up @@ -43,7 +42,7 @@ def write_file(filename, s):
"constructor",
"--help",
]
logged_command(context, command)
action.utils.logged_command(context, command)
except FileNotFoundError:
warnings.warn(
"Installer generation requires constructor: https://github.com/conda/constructor"
Expand Down Expand Up @@ -147,6 +146,6 @@ def write_file(filename, s):
get_installer_platform(),
str(tmp_dir),
]
logged_command(context, command)
action.utils.logged_command(context, command)

return installer_filename
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from conda_lock.conda_lock import run_lock

from conda_store_server import action, conda_utils, schema, utils
from conda_store_server.action.utils import logged_command
from conda_store_server._internal import action, conda_utils, schema, utils


@action.action
Expand All @@ -28,10 +27,10 @@ def action_solve_lockfile(
json.dump(specification.dict(), f)

# The info command can be used with either mamba or conda
logged_command(context, [conda_command, "info"])
action.utils.logged_command(context, [conda_command, "info"])
# The config command is not supported by mamba
logged_command(context, ["conda", "config", "--show"])
logged_command(context, ["conda", "config", "--show-sources"])
action.utils.logged_command(context, ["conda", "config", "--show"])
action.utils.logged_command(context, ["conda", "config", "--show-sources"])

# conda-lock ignores variables defined in the specification, so this code
# gets the value of CONDA_OVERRIDE_CUDA and passes it to conda-lock via
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pathlib

from conda_store_server import action, conda_utils, utils
from conda_store_server._internal import action, conda_utils, utils


@action.action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import typing

from conda_store_server import action
from conda_store_server._internal import action


@action.action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import pathlib

from conda_store_server import action, schema
from conda_store_server._internal import action, schema


@action.action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib
import shutil

from conda_store_server import action, conda_utils
from conda_store_server._internal import action, conda_utils


@action.action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib
import stat

from conda_store_server import action, conda_utils, utils
from conda_store_server._internal import action, conda_utils, utils


@action.action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))

from conda_store_server.orm import Base # noqa E402
from conda_store_server._internal.orm import Base # noqa E402


target_metadata = Base.metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from filelock import FileLock
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 conda_store_server import api
from conda_store_server._internal import action, conda_utils, orm, schema, utils


class LoggedStream:
Expand Down Expand Up @@ -312,7 +312,7 @@ def build_conda_environment(db: Session, conda_store, build):
conda_store.log.exception(e)
append_to_logs(db, conda_store, build, e.output)
raise e
except BuildPathError as e:
except utils.BuildPathError as e:
# Provide status_info, which will be exposed to the user, ONLY in this
# case because the error message doesn't expose sensitive information
set_build_failed(db, build, status_info=e.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from alembic.config import Config
from sqlalchemy import create_engine, inspect

from conda_store_server import utils
from conda_store_server._internal import utils


_here = os.path.abspath(os.path.dirname(__file__))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pydantic
import yaml

from conda_store_server import conda_utils, schema
from conda_store_server._internal import conda_utils, schema


def validate_environment(specification):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
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
from conda_store_server._internal import conda_utils, schema, utils
from conda_store_server._internal.environment import validate_environment


logger = logging.getLogger("orm")
Expand Down Expand Up @@ -287,7 +286,7 @@ def build_path(self, conda_store):
# conda prefix must be less or equal to 255 chars
# https://github.com/conda-incubator/conda-store/issues/649
if len(str(res)) > 255:
raise BuildPathError("build_path too long: must be <= 255 characters")
raise utils.BuildPathError("build_path too long: must be <= 255 characters")
# Note: cannot use the '/' operator to prepend the extended-length
# prefix
if sys.platform == "win32" and conda_store.win_extended_length_prefix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from traitlets import Callable, Dict, default
from traitlets.config import LoggingConfigurable

from conda_store_server import orm, schema, utils
from conda_store_server._internal import orm, schema, utils


class ContainerRegistry(LoggingConfigurable):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pydantic import BaseModel, Field, ValidationError, constr, validator
from pydantic.error_wrappers import ErrorWrapper

from conda_store_server import conda_utils, utils
from conda_store_server._internal import conda_utils, utils


def _datetime_factory(offset: datetime.timedelta):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from conda_store_server.server.app import CondaStoreServer
from conda_store_server._internal.server.app import CondaStoreServer


main = CondaStoreServer.launch_instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
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._internal import dbutil, orm, server, storage
from conda_store_server.app import CondaStore
from conda_store_server.server import auth, views


class _Color(str, Enum):
Expand Down Expand Up @@ -171,8 +169,8 @@ def _validate_config_file(self, proposal):
return proposal.value

authentication_class = Type(
default_value=auth.DummyAuthentication,
klass=auth.Authentication,
default_value=server.auth.DummyAuthentication,
klass=server.auth.Authentication,
allow_none=False,
config=True,
)
Expand Down Expand Up @@ -220,7 +218,7 @@ def trim_slash(url):

app = FastAPI(
title="conda-store",
version=__version__,
version=conda_store_server.__version__,
openapi_url=posixpath.join(self.url_prefix, "openapi.json"),
docs_url=posixpath.join(self.url_prefix, "docs"),
redoc_url=posixpath.join(self.url_prefix, "redoc"),
Expand Down Expand Up @@ -283,22 +281,22 @@ async def exception_handler(request, exc):

if self.enable_api:
app.include_router(
views.router_api,
server.views.router_api,
prefix=trim_slash(self.url_prefix),
)

if self.enable_registry:
# docker registry api specification does not support a url_prefix
app.include_router(views.router_registry)
app.include_router(server.views.router_registry)

if self.enable_ui:
app.include_router(
views.router_ui,
server.views.router_ui,
prefix=trim_slash(self.url_prefix) + "/admin",
)

app.include_router(
views.router_conda_store_ui,
server.views.router_conda_store_ui,
prefix=trim_slash(self.url_prefix),
)

Expand Down Expand Up @@ -336,7 +334,7 @@ async def favicon():

if self.enable_metrics:
app.include_router(
views.router_metrics,
server.views.router_metrics,
prefix=trim_slash(self.url_prefix),
)

Expand Down
Loading

0 comments on commit 5e45798

Please sign in to comment.