Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store the state and database files in ~/.conda-store by default #639

Merged
merged 17 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": f"{CONDA_STORE_DIR}/celerybeat-schedule",
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved
"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,
}}
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved
config["beat_schedule_filename"] = str(tmp_path / "celerybeat-schedule")
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved
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 / "storage")
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved

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"
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved
)
)
Expand Down
Loading