-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from noaa-ocs-modeling/depend/pyver
Update python version limitation
- Loading branch information
Showing
27 changed files
with
288 additions
and
1,049 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import importlib.util | ||
import logging | ||
import sys | ||
|
||
|
||
_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') | ||
return sys.modules[name] | ||
elif (spec := importlib.util.find_spec(name)) is not None: | ||
# If you chose to perform the actual import ... | ||
module = importlib.util.module_from_spec(spec) | ||
sys.modules[name] = module | ||
spec.loader.exec_module(module) | ||
return module | ||
|
||
_logger.warning(f"can't find the {name!r} module") | ||
return None | ||
|
||
|
||
def can_import(name): | ||
if name in sys.modules: | ||
return True | ||
elif (spec := importlib.util.find_spec(name)) is not None: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
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!") | ||
return func(*args, **kwargs) | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
import logging | ||
|
||
from coupledmodeldriver._depend import optional_import | ||
|
||
logging.basicConfig(format='[%(asctime)s] %(name)-9s %(levelname)-8s: %(message)s') | ||
|
||
__all__ = [ | ||
'check_completion', | ||
'generate_schism', | ||
'initialize_schism', | ||
'unqueued_runs', | ||
] | ||
|
||
if optional_import('adcircpy') is not None: | ||
__all__.extend( | ||
['generate_adcirc', 'initialize_adcirc',] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.