Skip to content

Commit

Permalink
Fix menu creation
Browse files Browse the repository at this point in the history
  • Loading branch information
goanpeca committed Mar 8, 2023
1 parent 8208247 commit be091e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
34 changes: 22 additions & 12 deletions constructor-manager/src/constructor_manager/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ def _lock_environment(self, version, packages, date=None):
env_path = self._create_environment_file_for_locking(version, packages)

lockfile = (
get_state_path() / f"{self._application_name}-{version}-{date}-lock.yml"
get_state_path()
/ f"{self._application_name}-{version}-{date}-conda-lock.yml"
)
temp_lockfile = (
get_state_path() / f"{self._application_name}-{version}-{date}-temp.yml"
Expand Down Expand Up @@ -243,7 +244,7 @@ def _get_available_lists(self, version):

def _get_available_states(self) -> Dict:
"""Get available states and group them by version."""
pattern = f"{self._application_name}-*-lock.yml"
pattern = f"{self._application_name}-*-conda-lock.yml"
paths = [Path(p).name for p in glob.glob(str(get_state_path() / pattern))]
versions = set()
for path in paths:
Expand All @@ -255,7 +256,7 @@ def _get_available_states(self) -> Dict:

for path in paths:
prefix = f"{self._application_name}-{version}-"
suffix = "-lock.yml"
suffix = "-conda-lock.yml"
if path.startswith(prefix):
path = path.replace(prefix, "").replace(suffix, "")
data[version].append(str(path))
Expand Down Expand Up @@ -296,14 +297,17 @@ def _remove_shortcuts(self, version: str):
version : str
Version to remove shortcuts for.
"""
logger.debug(
f"Removing shortcuts for version: {self._application_name}={version}"
)
paths = remove_shortcut(self._application_name, version)

logger.debug(f"Removing menu package: {self._application_name}-menu={version}")
prefix = get_prefix_by_name(f"{self._application_name}-{version}")
menu_spec = f"{self._application_name}-menu={version}"
rc = self._installer.uninstall(
pkg_list=[menu_spec], prefix=str(prefix), shortcuts=True, block=True
)
# Remove shortcuts manually using menuinst
paths = remove_shortcut(self._application_name, version)
print(paths)
return rc, paths

# Install
Expand Down Expand Up @@ -439,6 +443,9 @@ def _create_from_lock(self, state_file, version):
self._installer.install_from_lock(str(prefix), str(state_path), block=True)
self._create_shortcuts(version=version)

# Create the sentinel file for the environment
create_sentinel_file(self._application_name, version)

# Other
# -------------------------------------------------------------------------
def _check_available_versions(self, dev: bool = False) -> List[str]:
Expand Down Expand Up @@ -598,7 +605,7 @@ def update(
new_prefix = get_prefix_by_name(f"{self._application_name}-{latest_version}")
if not installed:
available_plugins = []
if plugins_url:
if plugins_url and old_prefix.exists():
available_plugins = self._get_installed_plugins(old_prefix, plugins_url)

logger.debug(f"Available plugins {available_plugins}")
Expand All @@ -615,6 +622,7 @@ def update(
shortcuts=shortcuts,
)

logger.debug(f"delayed {delayed}?...")
if not delayed:
logger.debug(f"Removing prefix {old_prefix}...")
self._remove(self._current_version, shortcuts=shortcuts)
Expand All @@ -640,11 +648,12 @@ def restore(
This will only run if any restore points are found
"""
logger.debug("Restoring environment...")
states = self._get_available_states()
for version, states in states.items():
for state in states:
state_file_check = (
f"{self._application_name}-{version}-{state}-lock.yml"
f"{self._application_name}-{version}-{state}-conda-lock.yml"
)
if state_file is None:
break
Expand Down Expand Up @@ -677,11 +686,12 @@ def revert(
break

if state:
logger.debug("Removing environment...")
self._remove(version, shortcuts=True)
state_file = f"{self._application_name}-{version}-{state}-conda-lock.yml"
logger.debug(f"Reverting to {state_file}...")
self.restore(state_file)

state_file = f"{self._application_name}-{version}-{state}-lock.yml"
return self.restore(state_file)
logger.debug("Removing old environment...")
self._remove(self._current_version, shortcuts=True)

return {}

Expand Down
2 changes: 1 addition & 1 deletion constructor-manager/src/constructor_manager/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def install_from_lock(
block: bool = False,
) -> job_id:
"""Install packages from lockfile."""
args = ["-p", prefix, "--lockfile", lockfile]
args = ["install", lockfile, "--prefix", prefix]
return self._queue_args(args, bin="conda-lock", block=block)

def lock(
Expand Down
1 change: 1 addition & 0 deletions constructor-manager/src/constructor_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def main():
constructor_manager_dir.mkdir(parents=True, exist_ok=True)
lock_file_path = constructor_manager_dir / "constructor-manager.lock"

# result = _execute(args, lock_file_path)
try:
logger.debug("Executing: %s", args)
result = _execute(args, lock_file_path)
Expand Down

0 comments on commit be091e9

Please sign in to comment.