Skip to content

Commit

Permalink
Lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SorooshMani-NOAA committed Aug 5, 2024
1 parent 0dc3317 commit 790d276
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
10 changes: 5 additions & 5 deletions coupledmodeldriver/_depend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
_logger = logging.getLogger(__file__)
# TODO: Forward proper types?


def optional_import(name):
if name in sys.modules:
_logger.warning(f"{name!r} already in sys.modules")
_logger.warning(f'{name!r} already in sys.modules')
return sys.modules[name]
elif (spec := importlib.util.find_spec(name)) is not None:
# If you chose to perform the actual import ...
Expand All @@ -31,13 +32,12 @@ def can_import(name):


HAS_ADCIRCPY = can_import('adcircpy')


def requires_adcircpy(func):
def wrapper(*args, **kwargs):
if not HAS_ADCIRCPY:
raise ImportError(
f"{func.__name__} requires `adcircpy`, but it's not available!"
)
raise ImportError(f"{func.__name__} requires `adcircpy`, but it's not available!")
return func(*args, **kwargs)

return wrapper

7 changes: 3 additions & 4 deletions coupledmodeldriver/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
]

if optional_import('adcircpy') is not None:
__all__.extend([
'generate_adcirc',
'initialize_adcirc',
])
__all__.extend(
['generate_adcirc', 'initialize_adcirc',]
)
5 changes: 3 additions & 2 deletions coupledmodeldriver/client/check_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
is_adcirc_run_directory = adcirc_check.is_adcirc_run_directory



def parse_check_completion_arguments():
argument_parser = ArgumentParser()
argument_parser.add_argument(
Expand All @@ -32,7 +31,9 @@ def parse_check_completion_arguments():
default=Path.cwd(),
help='directory containing model run configuration',
)
argument_parser.add_argument('--model', help='model that is running, one of: `ADCIRC`, `SCHISM`')
argument_parser.add_argument(
'--model', help='model that is running, one of: `ADCIRC`, `SCHISM`'
)
argument_parser.add_argument(
'--verbose', action='store_true', help='list all errors and problems with runs'
)
Expand Down
5 changes: 4 additions & 1 deletion coupledmodeldriver/configure/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

ADCIRCPY_FORCING_CLASSES = ()
if optional_import('adcircpy'):
ADCIRCPY_FORCING_CLASSES = coupledmodeldriver.configure.forcings.base.ADCIRCPY_FORCING_CLASSES
ADCIRCPY_FORCING_CLASSES = (
coupledmodeldriver.configure.forcings.base.ADCIRCPY_FORCING_CLASSES
)


class RunConfiguration(ABC):
"""
Expand Down
9 changes: 3 additions & 6 deletions coupledmodeldriver/configure/forcings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,15 @@ class TidalSource(IntEnum):


MODEL_TIDAL_SOURCE = {
TidalSource.TPXO: {
Model.SCHISM: PySCHISMTidalDatabase.TPXO,
},
TidalSource.HAMTIDE: {
Model.SCHISM: PySCHISMTidalDatabase.HAMTIDE,
},
TidalSource.TPXO: {Model.SCHISM: PySCHISMTidalDatabase.TPXO,},
TidalSource.HAMTIDE: {Model.SCHISM: PySCHISMTidalDatabase.HAMTIDE,},
}

if adcircpy is not None:
MODEL_TIDAL_SOURCE[TidalSource.TPXO][Model.ADCIRC] = ADCIRCPyTidalSource.TPXO
MODEL_TIDAL_SOURCE[TidalSource.HAMTIDE][Model.ADCIRC] = ADCIRCPyTidalSource.HAMTIDE


class ForcingJSON(ConfigurationJSON, ABC):
"""
abstraction of a forcing configuration
Expand Down
4 changes: 1 addition & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
from tests import INPUT_DIRECTORY



test_adcirc = False
skip_adcircpy_msg = "AdcircPy is not available!"
skip_adcircpy_msg = 'AdcircPy is not available!'
if optional_import('adcircpy'):
test_adcirc = True
skip_adcircpy_msg = ""
init_adcirc = optional_import('coupledmodeldriver.client.initialize_adcirc')
parse_initialize_adcirc_arguments = init_adcirc.parse_initialize_adcirc_arguments


ADCIRC_ARGUMENT_TYPES = {
'platform': Platform,
'mesh_directory': Path,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@


test_adcirc = False
skip_adcircpy_msg = "AdcircPy is not available!"
skip_adcircpy_msg = 'AdcircPy is not available!'
if optional_import('adcircpy'):
test_adcirc = True
skip_adcircpy_msg = ""
ADCIRCJSON = optional_import('coupledmodeldriver.generate.adcirc.base').ADCIRCJSON


def test_update():
configuration = SlurmJSON(account='coastal', tasks=602, job_duration=timedelta(hours=6))

Expand Down
7 changes: 2 additions & 5 deletions tests/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

from coupledmodeldriver import Platform
from coupledmodeldriver.client.initialize_schism import initialize_schism
from coupledmodeldriver.generate import (
generate_schism_configuration,
)
from coupledmodeldriver.generate import generate_schism_configuration
from coupledmodeldriver._depend import optional_import

from tests import (
Expand All @@ -24,9 +22,8 @@
)



test_adcirc = False
skip_adcircpy_msg = "AdcircPy is not available!"
skip_adcircpy_msg = 'AdcircPy is not available!'
if (adcircpy := optional_import('adcircpy')) is not None:
test_adcirc = True
skip_adcircpy_msg = ""
Expand Down

0 comments on commit 790d276

Please sign in to comment.