Skip to content

Commit

Permalink
Allow to set build_key_version via the config
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Karetnikov authored and nkaretnikov committed Nov 17, 2023
1 parent e2b14cc commit 9b731f6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions conda-store-server/conda_store_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@


CONDA_STORE_DIR = Path.home() / ".conda-store"


# Default build_key_version. Must be None here, initialized from the config file
_BUILD_KEY_VERSION = None
21 changes: 21 additions & 0 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ class CondaStore(LoggingConfigurable):
config=True,
)

build_key_version = Integer(
2,
help="Build key version to use: 1 (long, legacy), 2 (short, default)",
config=True,
)

@validate("build_key_version")
def _check_build_key_version(self, proposal):
expected = [1, 2]
if proposal.value not in expected:
raise TraitError(
f"c.CondaStore.build_key_version: invalid build key version: "
f"{proposal.value}, expected: {expected}"
)
return proposal.value

conda_command = Unicode(
"mamba",
help="conda executable to use for solves",
Expand Down Expand Up @@ -364,6 +380,11 @@ def session_factory(self):
url=self.database_url,
poolclass=QueuePool,
)

# Sets the default build_key_version value in the DB based on the config
import conda_store_server

conda_store_server._BUILD_KEY_VERSION = self.build_key_version
return self._session_factory

# Do not define this as a FastAPI dependency! That would cause Sessions
Expand Down
14 changes: 13 additions & 1 deletion conda-store-server/conda_store_server/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ class Solve(Base):
_BUILD_KEY_V2_HASH_SIZE = 8


# Avoids a cyclic dependency between the orm module and the module defining
# CondaStore.build_key_version. Because the orm module is loaded early on
# startup, we want to delay initialization of the build_key_version field until
# it's been read from the config.
def _get_build_key_version():
from conda_store_server import _BUILD_KEY_VERSION

# None means the value is not set, likely due to an import error
assert _BUILD_KEY_VERSION is not None
return _BUILD_KEY_VERSION


class Build(Base):
"""The state of a build of a given specification"""

Expand Down Expand Up @@ -185,7 +197,7 @@ class Build(Base):
started_on = Column(DateTime, default=None)
ended_on = Column(DateTime, default=None)
deleted_on = Column(DateTime, default=None)
build_key_version = Column(Integer, default=2, nullable=False)
build_key_version = Column(Integer, default=_get_build_key_version, nullable=False)

@validates("build_key_version")
def validate_build_key_version(self, key, build_key_version):
Expand Down

0 comments on commit 9b731f6

Please sign in to comment.