-
Notifications
You must be signed in to change notification settings - Fork 5
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 #108 from MODFLOW-USGS/v1.1.0
Release 1.1.0
- Loading branch information
Showing
13 changed files
with
221 additions
and
24 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 |
---|---|---|
@@ -1 +1,4 @@ | ||
from pathlib import Path | ||
|
||
pytest_plugins = ["modflow_devtools.fixtures"] | ||
project_root_path = Path(__file__).parent |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
__author__ = "Joseph D. Hughes" | ||
__date__ = "Aug 05, 2023" | ||
__version__ = "1.0.0" | ||
__date__ = "Aug 12, 2023" | ||
__version__ = "1.1.0" | ||
__maintainer__ = "Joseph D. Hughes" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
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 |
---|---|---|
|
@@ -82,7 +82,12 @@ def __exit__(self, exc_type, exc_value, traceback): | |
|
||
|
||
def get_ostag() -> str: | ||
"""Determine operating system tag from sys.platform.""" | ||
""" | ||
Determine operating system tag from sys.platform. | ||
.. deprecated:: 1.1.0 | ||
Use ``ostags.get_modflow_ostag()`` instead. | ||
""" | ||
if sys.platform.startswith("linux"): | ||
return "linux" | ||
elif sys.platform.startswith("win"): | ||
|
@@ -93,7 +98,12 @@ def get_ostag() -> str: | |
|
||
|
||
def get_suffixes(ostag) -> Tuple[str, str]: | ||
"""Returns executable and library suffixes for the given OS (as returned by sys.platform)""" | ||
""" | ||
Returns executable and library suffixes for the given OS (as returned by sys.platform) | ||
.. deprecated:: 1.1.0 | ||
Use ``ostags.get_binary_suffixes()`` instead. | ||
""" | ||
|
||
tag = ostag.lower() | ||
|
||
|
@@ -136,6 +146,23 @@ def run_py_script(script, *args, verbose=False): | |
|
||
|
||
def get_current_branch() -> str: | ||
""" | ||
Tries to determine the name of the current branch, first by the GITHUB_REF | ||
environent variable, then by asking ``git`` if GITHUB_REF is not set. | ||
Returns | ||
------- | ||
str | ||
name of the current branch | ||
Raises | ||
------ | ||
RuntimeError | ||
if ``git`` is not available | ||
ValueError | ||
if the current branch could not be determined | ||
""" | ||
|
||
# check if on GitHub Actions CI | ||
ref = environ.get("GITHUB_REF") | ||
if ref is not None: | ||
|
@@ -160,6 +187,7 @@ def get_packages(namefile_path: PathLike) -> List[str]: | |
---------- | ||
namefile_path : PathLike | ||
path to MODFLOW 6 simulation or model name file | ||
Returns | ||
------- | ||
a list of packages used by the simulation or model | ||
|
@@ -215,7 +243,9 @@ def parse_model_namefile(line): | |
|
||
|
||
def has_package(namefile_path: PathLike, package: str) -> bool: | ||
"""Determines whether the model with the given namefile contains the selected package""" | ||
""" | ||
Determines whether the model with the given namefile contains the selected package. | ||
""" | ||
packages = get_packages(namefile_path) | ||
return package.lower() in packages | ||
|
||
|
@@ -306,7 +336,9 @@ def get_model_paths( | |
def is_connected(hostname): | ||
""" | ||
Tests whether the given URL is accessible. | ||
See https://stackoverflow.com/a/20913928/.""" | ||
See https://stackoverflow.com/a/20913928/. | ||
""" | ||
|
||
try: | ||
host = socket.gethostbyname(hostname) | ||
s = socket.create_connection((host, 80), 2) | ||
|
@@ -318,7 +350,10 @@ def is_connected(hostname): | |
|
||
|
||
def is_in_ci(): | ||
"""Determines whether the current process is running GitHub Actions CI""" | ||
""" | ||
Determines whether the current process is running GitHub Actions CI | ||
by checking for the "CI" environment variable. | ||
""" | ||
|
||
# if running in GitHub Actions CI, "CI" variable always set to true | ||
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables | ||
|
@@ -328,7 +363,7 @@ def is_in_ci(): | |
def is_github_rate_limited() -> Optional[bool]: | ||
""" | ||
Determines if a GitHub API rate limit is applied to the current IP. | ||
Running this function will consume an API request! | ||
Calling this function will consume an API request! | ||
Returns | ||
------- | ||
|
@@ -363,21 +398,47 @@ def has_exe(exe): | |
return _has_exe_cache[exe] | ||
|
||
|
||
def has_pkg(pkg): | ||
def has_pkg(pkg: str, strict: bool = False) -> bool: | ||
""" | ||
Determines if the given Python package is installed. | ||
Parameters | ||
---------- | ||
pkg : str | ||
Name of the package to check. | ||
strict : bool | ||
If False, only check if package metadata is available. | ||
If True, try to import the package (all dependencies must be present). | ||
Returns | ||
------- | ||
bool | ||
True if the package is installed, otherwise False. | ||
Notes | ||
----- | ||
Originally written by Mike Toews ([email protected]) for FloPy. | ||
""" | ||
if pkg not in _has_pkg_cache: | ||
found = True | ||
|
||
def try_import(): | ||
try: # import name, e.g. "import shapefile" | ||
importlib.import_module(pkg) | ||
return True | ||
except ModuleNotFoundError: | ||
return False | ||
|
||
def try_metadata() -> bool: | ||
try: # package name, e.g. pyshp | ||
metadata.distribution(pkg) | ||
return True | ||
except metadata.PackageNotFoundError: | ||
try: # import name, e.g. "import shapefile" | ||
importlib.import_module(pkg) | ||
except ModuleNotFoundError: | ||
found = False | ||
_has_pkg_cache[pkg] = found | ||
return False | ||
|
||
found = False | ||
if not strict: | ||
found = pkg in _has_pkg_cache or try_metadata() | ||
if not found: | ||
found = try_import() | ||
_has_pkg_cache[pkg] = found | ||
|
||
return _has_pkg_cache[pkg] |
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.