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 Jun 17, 2024
1 parent a98d96f commit 8fa29ff
Show file tree
Hide file tree
Showing 109 changed files with 195 additions and 195 deletions.
2 changes: 1 addition & 1 deletion conda-store-server/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include conda_store LICENSE
recursive-include conda_store_server/server/templates *
recursive-include conda_store_server/_internal/server/templates *
prune .github
global-exclude *.py[cod] __pycache__ *.so *.nix .envrc
2 changes: 1 addition & 1 deletion conda-store-server/conda_store_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def parse_build_key(
) -> int:
"""Returns build id from build key"""
# This import is here to avoid cyclic imports
from conda_store_server import orm
from conda_store_server._internal import orm

parts = build_key.split("-")
# Note: cannot rely on the number of dashes to differentiate between
Expand Down
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.base import action # noqa isort: skip
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.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,8 @@

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
from conda_store_server._internal.action.utils import logged_command


def get_installer_platform():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

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
from conda_store_server._internal.action.utils import logged_command


@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, 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 @@ -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,12 @@
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 import __version__, storage
from conda_store_server._internal import dbutil, orm
from conda_store_server._internal.server import views
from conda_store_server.app import CondaStore
from conda_store_server.server import auth, views
from conda_store_server.server import auth


class _Color(str, Enum):
Expand Down Expand Up @@ -151,10 +152,10 @@ class CondaStoreServer(Application):

@default("templates")
def _default_templates(self):
import conda_store_server.server
from conda_store_server._internal import server

templates_directory = os.path.join(
os.path.dirname(conda_store_server.server.__file__), "templates"
os.path.dirname(server.__file__), "templates"
)
return Jinja2Templates(directory=templates_directory)

Expand Down Expand Up @@ -303,13 +304,13 @@ async def exception_handler(request, exc):
)

# serving static files
import conda_store_server.server
from conda_store_server._internal import server

app.mount(
trim_slash(self.url_prefix) + "/static/",
StaticFiles(
directory=os.path.join(
os.path.dirname(conda_store_server.server.__file__),
os.path.dirname(server.__file__),
"static",
),
),
Expand All @@ -328,7 +329,7 @@ def redirect_home(request: Request):
async def favicon():
return FileResponse(
os.path.join(
os.path.dirname(conda_store_server.server.__file__),
os.path.dirname(server.__file__),
"static",
"favicon.ico",
)
Expand Down Expand Up @@ -421,7 +422,7 @@ def start(self):

multiprocessing.set_start_method("spawn")

from conda_store_server.worker.app import CondaStoreWorker
from conda_store_server._internal.worker.app import CondaStoreWorker

process = multiprocessing.Process(target=CondaStoreWorker.launch_instance)
process.start()
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from conda_store_server._internal.server.views.api import router_api # noqa
from conda_store_server._internal.server.views.conda_store_ui import ( # noqa
router_conda_store_ui,
)
from conda_store_server._internal.server.views.metrics import router_metrics # noqa
from conda_store_server._internal.server.views.registry import router_registry # noqa
from conda_store_server._internal.server.views.ui import router_ui # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
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 import __version__, api
from conda_store_server._internal import orm, schema, utils
from conda_store_server._internal.schema import Permissions
from conda_store_server.server import dependencies


Expand Down Expand Up @@ -1000,7 +1001,7 @@ async def api_put_build_cancel(
signal="SIGTERM",
)

from conda_store_server.worker import tasks
from conda_store_server._internal.worker import tasks

# Waits 5 seconds to ensure enough time for the task to actually be
# canceled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
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 import api
from conda_store_server._internal import orm, schema
from conda_store_server._internal.schema import Permissions
from conda_store_server.server import dependencies


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from fastapi.responses import RedirectResponse

from conda_store_server import api
from conda_store_server.action.generate_constructor_installer import (
from conda_store_server._internal.action.generate_constructor_installer import (
get_installer_platform,
)
from conda_store_server.schema import Permissions
from conda_store_server._internal.schema import Permissions
from conda_store_server.server import dependencies


Expand Down
Loading

0 comments on commit 8fa29ff

Please sign in to comment.