Skip to content

Commit

Permalink
Use consistent naming for deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
MJGaughran committed Nov 7, 2024
1 parent 763f8c2 commit 9f07b1e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/deploy_tools/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from .models.load import load_from_yaml
from .models.module import Module, Release
from .module import get_default_version, in_deployment_area, in_deprecated_area
from .module import get_default_version, is_modulefile_deployed
from .snapshot import load_snapshot
from .validate import validate_default_versions

Expand Down Expand Up @@ -79,9 +79,9 @@ def _collect_modules(layout: Layout) -> list[Module]:


def _get_deprecated_status(name: str, version: str, layout: Layout) -> bool:
if in_deployment_area(name, version, layout):
if is_modulefile_deployed(name, version, layout):
return False
elif in_deprecated_area(name, version, layout):
elif is_modulefile_deployed(name, version, layout, in_deprecated=True):
return True

raise ComparisonError(
Expand Down
4 changes: 2 additions & 2 deletions src/deploy_tools/deploy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .layout import Layout
from .models.module import Module
from .module import in_deployment_area
from .module import is_modulefile_deployed
from .module_creator import ModuleCreator
from .templater import Templater

Expand All @@ -15,7 +15,7 @@ def check_deploy(modules: list[Module], layout: Layout) -> None:
name = module.name
version = module.version

if in_deployment_area(name, version, layout):
if is_modulefile_deployed(name, version, layout):
raise DeployError(
f"Cannot deploy {name}/{version}. Already found in deployment area."
)
Expand Down
6 changes: 3 additions & 3 deletions src/deploy_tools/deprecate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .layout import Layout
from .models.module import Module
from .module import deprecate_modulefile, in_deployment_area, in_deprecated_area
from .module import deprecate_modulefile, is_modulefile_deployed


class DeprecateError(Exception):
Expand All @@ -13,12 +13,12 @@ def check_deprecate(modules: list[Module], layout: Layout) -> None:
name = module.name
version = module.version

if not in_deployment_area(name, version, layout):
if not is_modulefile_deployed(name, version, layout):
raise DeprecateError(
f"Cannot deprecate {name}/{version}. Not found in deployment area."
)

if in_deprecated_area(name, version, layout):
if is_modulefile_deployed(name, version, layout, in_deprecated=True):
raise DeprecateError(
f"Cannot deprecate {name}/{version}. Already found in deprecated area."
)
Expand Down
19 changes: 9 additions & 10 deletions src/deploy_tools/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ def _move_modulefile(
shutil.move(src_path, dest_path)


def get_deployed_module_versions(layout: Layout) -> ModuleVersionsByName:
"""Return list of modules that have already been deployed."""
modulefiles_root = layout.get_modulefiles_root(from_deprecated=False)
def get_deployed_modulefile_versions(
layout: Layout, from_deprecated: bool = False
) -> ModuleVersionsByName:
"""Return list of modulefiles that have been deployed."""
modulefiles_root = layout.get_modulefiles_root(from_deprecated)
found_modules: ModuleVersionsByName = defaultdict(list)

for version_path in modulefiles_root.glob(VERSION_GLOB):
Expand All @@ -55,13 +57,10 @@ def get_deployed_module_versions(layout: Layout) -> ModuleVersionsByName:
return found_modules


def in_deployment_area(name: str, version: str, layout: Layout) -> bool:
modulefile = layout.get_modulefile(name, version)
return modulefile.exists()


def in_deprecated_area(name: str, version: str, layout: Layout) -> bool:
modulefile = layout.get_modulefile(name, version, True)
def is_modulefile_deployed(
name: str, version: str, layout: Layout, in_deprecated: bool = False
) -> bool:
modulefile = layout.get_modulefile(name, version, from_deprecated=in_deprecated)
return modulefile.exists()


Expand Down
4 changes: 2 additions & 2 deletions src/deploy_tools/module_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .models.deployment import DefaultVersionsByName
from .models.module import Module
from .models.shell import Shell
from .module import DEFAULT_VERSION_FILENAME, get_deployed_module_versions
from .module import DEFAULT_VERSION_FILENAME, get_deployed_modulefile_versions
from .shell_creator import ShellCreator
from .templater import Templater, TemplateType

Expand Down Expand Up @@ -49,7 +49,7 @@ def create_modulefile(self, module: Module) -> None:
def update_default_versions(
self, default_versions: DefaultVersionsByName, layout: Layout
) -> None:
deployed_module_versions = get_deployed_module_versions(layout)
deployed_module_versions = get_deployed_modulefile_versions(layout)

for name in deployed_module_versions:
version_file = (
Expand Down
21 changes: 8 additions & 13 deletions src/deploy_tools/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .layout import Layout
from .models.module import Module
from .module import in_deployment_area, in_deprecated_area, is_module_dev_mode
from .module import is_module_dev_mode, is_modulefile_deployed


class RemovalError(Exception):
Expand All @@ -16,13 +16,13 @@ def check_remove(modules: list[Module], layout: Layout) -> None:
version = module.version

if is_module_dev_mode(module):
if not in_deployment_area(name, version, layout):
if not is_modulefile_deployed(name, version, layout):
raise RemovalError(
f"Cannot remove {name}/{version}. Not found in deployment area."
)
continue

if not in_deprecated_area(name, version, layout):
if not is_modulefile_deployed(name, version, layout, in_deprecated=True):
raise RemovalError(
f"Cannot remove {name}/{version}. Not found in deprecated area."
)
Expand All @@ -36,18 +36,13 @@ def remove(modules: list[Module], layout: Layout) -> None:
if is_module_dev_mode(module):
remove_deployed_module(name, version, layout)
else:
remove_deprecated_module(name, version, layout)
remove_deployed_module(name, version, layout, from_deprecated=True)


def remove_deployed_module(name: str, version: str, layout: Layout) -> None:
modulefile = layout.get_modulefile(name, version)
modulefile.unlink()

remove_module(name, version, layout)


def remove_deprecated_module(name: str, version: str, layout: Layout) -> None:
modulefile = layout.get_modulefile(name, version, True)
def remove_deployed_module(
name: str, version: str, layout: Layout, from_deprecated: bool = False
) -> None:
modulefile = layout.get_modulefile(name, version, from_deprecated)
modulefile.unlink()

remove_module(name, version, layout)
Expand Down
6 changes: 3 additions & 3 deletions src/deploy_tools/restore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .layout import Layout
from .models.module import Module
from .module import in_deployment_area, in_deprecated_area, restore_modulefile
from .module import is_modulefile_deployed, restore_modulefile


class RestoreError(Exception):
Expand All @@ -13,12 +13,12 @@ def check_restore(modules: list[Module], layout: Layout) -> None:
name = module.name
version = module.version

if not in_deprecated_area(name, version, layout):
if not is_modulefile_deployed(name, version, layout, in_deprecated=True):
raise RestoreError(
f"Cannot restore {name}/{version}. Not found in deprecated area."
)

if in_deployment_area(name, version, layout):
if is_modulefile_deployed(name, version, layout):
raise RestoreError(
f"Cannot restore {name}/{version}. Already found in deployment area."
)
Expand Down
4 changes: 2 additions & 2 deletions src/deploy_tools/update.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .deploy import deploy
from .layout import Layout
from .models.module import Module
from .module import in_deployment_area
from .module import is_modulefile_deployed
from .remove import remove_deployed_module


Expand All @@ -15,7 +15,7 @@ def check_update(modules: list[Module], layout: Layout) -> None:
name = module.name
version = module.version

if not in_deployment_area(name, version, layout):
if not is_modulefile_deployed(name, version, layout):
raise UpdateError(
f"Cannot update {name}/{version}. Not found in deployment area."
)
Expand Down

0 comments on commit 9f07b1e

Please sign in to comment.