From 1f66551b8c5429cd88ab8a98e5f329d23d1233ae Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov Date: Thu, 26 Oct 2023 22:05:33 +0200 Subject: [PATCH] Store the state and database files in ~/.conda-store by default (#639) Co-authored-by: Aaron Meurer --- .../conda_store_server/__init__.py | 5 +++++ conda-store-server/conda_store_server/app.py | 6 ++++-- .../conda_store_server/server/app.py | 8 ++++++++ .../conda_store_server/storage.py | 4 ++-- conda-store-server/tests/conftest.py | 19 +++++++++++++++---- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/conda-store-server/conda_store_server/__init__.py b/conda-store-server/conda_store_server/__init__.py index b32942c0f..d3b075936 100644 --- a/conda-store-server/conda_store_server/__init__.py +++ b/conda-store-server/conda_store_server/__init__.py @@ -1 +1,6 @@ +from pathlib import Path + __version__ = "2023.10.1" + + +CONDA_STORE_DIR = Path.home() / ".conda-store" diff --git a/conda-store-server/conda_store_server/app.py b/conda-store-server/conda_store_server/app.py index 36f88e0d0..a3aa62564 100644 --- a/conda-store-server/conda_store_server/app.py +++ b/conda-store-server/conda_store_server/app.py @@ -7,6 +7,7 @@ import pydantic from celery import Celery, group from conda_store_server import ( + CONDA_STORE_DIR, api, conda_utils, environment, @@ -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, ) @@ -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, ) @@ -434,6 +435,7 @@ def celery_config(self): "kwargs": {}, }, }, + "beat_schedule_filename": str(CONDA_STORE_DIR / "celerybeat-schedule"), "triatlets": {}, } diff --git a/conda-store-server/conda_store_server/server/app.py b/conda-store-server/conda_store_server/server/app.py index 9a0a91c90..c3febe623 100644 --- a/conda-store-server/conda_store_server/server/app.py +++ b/conda-store-server/conda_store_server/server/app.py @@ -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) diff --git a/conda-store-server/conda_store_server/storage.py b/conda-store-server/conda_store_server/storage.py index 5f349a676..1ee77a5ea 100644 --- a/conda-store-server/conda_store_server/storage.py +++ b/conda-store-server/conda_store_server/storage.py @@ -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 @@ -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, ) diff --git a/conda-store-server/tests/conftest.py b/conda-store-server/tests/conftest.py index 4cf9e2bff..b2cfc9b47 100644 --- a/conda-store-server/tests/conftest.py +++ b/conda-store-server/tests/conftest.py @@ -7,14 +7,18 @@ 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 @@ -22,11 +26,18 @@ def celery_config(conda_store): 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" ) )