Skip to content

Commit

Permalink
Store the state and database files in ~/.conda-store by default (#639)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Meurer <[email protected]>
  • Loading branch information
Nikita Karetnikov and asmeurer authored Oct 26, 2023
1 parent 9018694 commit 1f66551
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
5 changes: 5 additions & 0 deletions conda-store-server/conda_store_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from pathlib import Path

__version__ = "2023.10.1"


CONDA_STORE_DIR = Path.home() / ".conda-store"
6 changes: 4 additions & 2 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pydantic
from celery import Celery, group
from conda_store_server import (
CONDA_STORE_DIR,
api,
conda_utils,
environment,
Expand Down Expand Up @@ -88,7 +89,7 @@ class CondaStore(LoggingConfigurable):
)

store_directory = Unicode(
"conda-store-state",
str(CONDA_STORE_DIR / "state"),
help="directory for conda-store to build environments and store state",
config=True,
)
Expand Down Expand Up @@ -201,7 +202,7 @@ class CondaStore(LoggingConfigurable):
)

database_url = Unicode(
"sqlite:///conda-store.sqlite",
"sqlite:///" + str(CONDA_STORE_DIR / "conda-store.sqlite"),
help="url for the database. e.g. 'sqlite:///conda-store.sqlite' tables will be automatically created if they do not exist",
config=True,
)
Expand Down Expand Up @@ -434,6 +435,7 @@ def celery_config(self):
"kwargs": {},
},
},
"beat_schedule_filename": str(CONDA_STORE_DIR / "celerybeat-schedule"),
"triatlets": {},
}

Expand Down
8 changes: 8 additions & 0 deletions conda-store-server/conda_store_server/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ def initialize(self, *args, **kwargs):

self.conda_store = CondaStore(parent=self, log=self.log)

self.conda_store.ensure_directories()
self.log.info(
f"Running conda-store with database: {self.conda_store.database_url}"
)
self.log.info(
f"Running conda-store with store directory: {self.conda_store.store_directory}"
)

if self.conda_store.upgrade_db:
dbutil.upgrade(self.conda_store.database_url)

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

import minio
from conda_store_server import api, orm, schema
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
Expand Down Expand Up @@ -194,7 +194,7 @@ def delete(self, db, build_id, key):

class LocalStorage(Storage):
storage_path = Unicode(
"conda-store-state/storage",
str(CONDA_STORE_DIR / "storage"),
help="directory to store binary blobs of conda-store artifacts",
config=True,
)
Expand Down
19 changes: 15 additions & 4 deletions conda-store-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,37 @@
import yaml
from fastapi.testclient import TestClient

from conda_store_server import action, api, app, dbutil, schema, testing, utils # isort:skip
from conda_store_server import action, api, app, dbutil, schema, storage, testing, utils # isort:skip
from conda_store_server.server import app as server_app # isort:skip


@pytest.fixture
def celery_config(conda_store):
def celery_config(tmp_path, conda_store):
config = conda_store.celery_config
config["traitlets"] = {"CondaStore": {"database_url": conda_store.database_url}}
config["traitlets"] = {"CondaStore": {
"database_url": conda_store.database_url,
"store_directory": conda_store.store_directory,
}}
config["beat_schedule_filename"] = str(tmp_path / ".conda-store" / "celerybeat-schedule")
return config


@pytest.fixture
def conda_store_config(tmp_path, request):
from traitlets.config import Config

filename = pathlib.Path(tmp_path) / "database.sqlite"
filename = tmp_path / ".conda-store" / "database.sqlite"

store_directory = tmp_path / ".conda-store" / "state"
store_directory.mkdir(parents=True)

storage.LocalStorage.storage_path = str(tmp_path / ".conda-store" / "storage")

with utils.chdir(tmp_path):
yield Config(
CondaStore=dict(
storage_class=storage.LocalStorage,
store_directory=str(store_directory),
database_url=f"sqlite:///{filename}?check_same_thread=False"
)
)
Expand Down

0 comments on commit 1f66551

Please sign in to comment.