Skip to content

Commit

Permalink
Simplify deprecation check for Moab and Slurm adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
giffels committed Aug 30, 2022
1 parent 1fc302f commit c9ab342
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
16 changes: 4 additions & 12 deletions tardis/adapters/sites/moab.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from ...utilities.asynccachemap import AsyncCacheMap
from ...utilities.utils import submit_cmd_option_formatter

from pydantic import PositiveInt, root_validator
from pydantic import PositiveInt

from asyncio import TimeoutError
from contextlib import contextmanager
from functools import partial
from datetime import datetime
from typing import Any, Dict, Optional
from typing import Optional

import asyncssh
import logging
Expand Down Expand Up @@ -57,15 +57,7 @@ class MoabAdapterConfigurationModel(SiteAdapterBaseModel):

executor: Optional[Executor] = ShellExecutor()
StatusUpdate: PositiveInt
StartupCommand: Optional[str] = None

@root_validator(allow_reuse=True)
def deprecate_startup_command(
cls, valuesDict: [str, Any] # noqa B902
) -> Dict[str, Any]:
if valuesDict["StartupCommand"] is None:
del valuesDict["StartupCommand"]
return valuesDict
StartupCommand: Optional[str]


class MoabAdapter(SiteAdapter):
Expand All @@ -77,7 +69,7 @@ def __init__(self, machine_type: str, site_name: str):
try:
self._startup_command = self.machine_type_configuration.StartupCommand
except AttributeError:
if not hasattr(self.configuration, "StartupCommand"):
if self.configuration.StartupCommand is None:
raise
warnings.warn(
"StartupCommand has been moved to the machine_type_configuration!",
Expand Down
16 changes: 4 additions & 12 deletions tardis/adapters/sites/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from ...utilities.asynccachemap import AsyncCacheMap
from ...utilities.utils import convert_to, csv_parser, submit_cmd_option_formatter

from pydantic import PositiveInt, root_validator
from pydantic import PositiveInt

from asyncio import TimeoutError
from contextlib import contextmanager
from functools import partial
from datetime import datetime
from typing import Any, Dict, Optional
from typing import Optional

import logging
import re
Expand Down Expand Up @@ -55,15 +55,7 @@ class SlurmAdapterConfigurationModel(SiteAdapterBaseModel):

executor: Optional[Executor] = ShellExecutor()
StatusUpdate: PositiveInt
StartupCommand: Optional[str] = None

@root_validator(allow_reuse=True)
def deprecate_startup_command(
cls, valuesDict: [str, Any] # noqa B902
) -> Dict[str, Any]:
if valuesDict["StartupCommand"] is None:
del valuesDict["StartupCommand"]
return valuesDict
StartupCommand: Optional[str]


class SlurmAdapter(SiteAdapter):
Expand All @@ -75,7 +67,7 @@ def __init__(self, machine_type: str, site_name: str):
try:
self._startup_command = self.machine_type_configuration.StartupCommand
except AttributeError:
if not hasattr(self.configuration, "StartupCommand"):
if self.configuration.StartupCommand is None:
raise
warnings.warn(
"StartupCommand has been moved to the machine_type_configuration!",
Expand Down

0 comments on commit c9ab342

Please sign in to comment.