diff --git a/coupledmodeldriver/_depend.py b/coupledmodeldriver/_depend.py index cc2f7eab..8a42984a 100644 --- a/coupledmodeldriver/_depend.py +++ b/coupledmodeldriver/_depend.py @@ -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 ... @@ -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 - diff --git a/coupledmodeldriver/client/__init__.py b/coupledmodeldriver/client/__init__.py index e222bb27..9e808c2b 100644 --- a/coupledmodeldriver/client/__init__.py +++ b/coupledmodeldriver/client/__init__.py @@ -12,7 +12,6 @@ ] if optional_import('adcircpy') is not None: - __all__.extend([ - 'generate_adcirc', - 'initialize_adcirc', - ]) + __all__.extend( + ['generate_adcirc', 'initialize_adcirc',] + ) diff --git a/coupledmodeldriver/client/check_completion.py b/coupledmodeldriver/client/check_completion.py index 9a0a76b1..739be862 100644 --- a/coupledmodeldriver/client/check_completion.py +++ b/coupledmodeldriver/client/check_completion.py @@ -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( @@ -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' ) diff --git a/coupledmodeldriver/configure/configure.py b/coupledmodeldriver/configure/configure.py index a0631c88..0c5eb2a5 100644 --- a/coupledmodeldriver/configure/configure.py +++ b/coupledmodeldriver/configure/configure.py @@ -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): """ diff --git a/coupledmodeldriver/configure/forcings/base.py b/coupledmodeldriver/configure/forcings/base.py index f9dba601..8155e87e 100644 --- a/coupledmodeldriver/configure/forcings/base.py +++ b/coupledmodeldriver/configure/forcings/base.py @@ -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 diff --git a/tests/test_client.py b/tests/test_client.py index ad862dea..c9939828 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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, diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 2c6fd17a..7e999bc1 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -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)) diff --git a/tests/test_generation.py b/tests/test_generation.py index 0ee71436..2635a4ea 100644 --- a/tests/test_generation.py +++ b/tests/test_generation.py @@ -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 ( @@ -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 = ""