Skip to content

Commit

Permalink
chore(format): add isort rule, enforce line length (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli authored Apr 4, 2024
1 parent e65c4d3 commit 08eff72
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 33 deletions.
3 changes: 2 additions & 1 deletion autotest/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def test_get_release(repo):
actual_names = [asset["name"] for asset in assets]

if repo == "MODFLOW-USGS/modflow6":
# can remove if modflow6 releases follow asset name conventions followed in executables and nightly build repos
# can remove if modflow6 releases follow asset name
# conventions followed in executables and nightly build repos
assert set([a.rpartition("_")[2] for a in actual_names]) >= set(
[a for a in expected_names if not a.startswith("win")]
)
Expand Down
14 changes: 7 additions & 7 deletions autotest/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
from platform import python_version, system
from shutil import which

from packaging.version import Version
import pytest
from packaging.version import Version

from modflow_devtools.markers import (
requires_exe,
excludes_platform,
require_exe,
requires_program,
require_package,
require_platform,
require_program,
require_python,
requires_exe,
requires_pkg,
require_package,
requires_platform,
require_platform,
excludes_platform,
requires_program,
requires_python,
require_python,
)

exe = "pytest"
Expand Down
3 changes: 2 additions & 1 deletion autotest/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def test_get_packages_fails_on_invalid_namefile(module_tmpdir):
namefile_path = new_model_path / "mfsim.nam"
shutil.copytree(model_path, new_model_path)

# invalid gwf namefile reference - result should only contain packages from mfsim.nam
# invalid gwf namefile reference:
# result should only contain packages from mfsim.nam
lines = open(namefile_path, "r").read().splitlines()
with open(namefile_path, "w") as f:
for line in lines:
Expand Down
2 changes: 1 addition & 1 deletion autotest/test_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_compressall(function_tmpdir):
@pytest.fixture(scope="module")
def empty_archive(module_tmpdir) -> Path:
# https://stackoverflow.com/a/25195628/6514033
data = b"PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
data = b"PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" # noqa: E501
path = module_tmpdir / "empty.zip"
with open(path, "wb") as zip:
zip.write(data)
Expand Down
9 changes: 6 additions & 3 deletions modflow_devtools/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def get_response_json():
try:
if verbose:
print(
f"Fetching releases for repo {repo} (page {page}, {per_page} per page)"
f"Fetching releases for "
f"repo {repo} "
f"(page {page}, "
f"{per_page} per page)"
)
with urllib.request.urlopen(request, timeout=10) as resp:
return json.loads(resp.read().decode())
Expand Down Expand Up @@ -285,8 +288,8 @@ def list_artifacts(
Returns
-------
A list of dictionaries, each containing information about an artifact as returned
by the GitHub API.
A list of dictionaries, each containing information
about an artifact as returned by the GitHub API.
"""

if "/" not in repo:
Expand Down
27 changes: 18 additions & 9 deletions modflow_devtools/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,25 @@ def pytest_addoption(parser):
action="store",
default=None,
dest="KEEP",
help="Move the contents of temporary test directories to correspondingly named subdirectories at the given "
"location after tests complete. This option can be used to exclude test results from automatic cleanup, "
"e.g. for manual inspection. The provided path is created if it does not already exist. An error is "
help="Move the contents of temporary test directories to "
"correspondingly named subdirectories at the given "
"location after tests complete. This option can be used "
"to exclude test results from automatic cleanup, "
"e.g. for manual inspection. The provided path is "
"created if it does not already exist. An error is "
"thrown if any matching files already exist.",
)

parser.addoption(
"--keep-failed",
action="store",
default=None,
help="Move the contents of temporary test directories to correspondingly named subdirectories at the given "
"location if the test case fails. This option automatically saves the outputs of failed tests in the "
"given location. The path is created if it doesn't already exist. An error is thrown if files with the "
help="Move the contents of temporary test directories to "
"correspondingly named subdirectories at the given "
"location if the test case fails. This option saves "
"the outputs of failed tests in the "
"given location. The path is created if it doesn't "
"already exist. An error is thrown if files with the "
"same names already exist in the given location.",
)

Expand All @@ -144,7 +150,8 @@ def pytest_addoption(parser):
"--meta",
action="store",
metavar="NAME",
help="Indicates a test should only be run by other tests (e.g., to test framework or fixtures).",
help="Indicates a test should only be run by other tests (e.g., "
"to test framework or fixtures).",
)

parser.addoption(
Expand All @@ -167,7 +174,8 @@ def pytest_addoption(parser):
action="store",
default="yes",
dest="PANDAS",
help="Indicates whether to use pandas, where multiple approaches are available. Select 'yes', 'no', or 'random'.",
help="Indicates whether to use pandas, where multiple approaches "
"are available. Select 'yes', 'no', or 'random'.",
)

parser.addoption(
Expand All @@ -176,7 +184,8 @@ def pytest_addoption(parser):
action="store",
default="raw",
dest="TABULAR",
help="Configure tabular data representation for model input. Select 'raw', 'recarray', or 'dataframe'.",
help="Configure tabular data representation for model input. "
"Select 'raw', 'recarray', or 'dataframe'.",
)


Expand Down
2 changes: 1 addition & 1 deletion modflow_devtools/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is dual licensed under the terms of the BSD 3-Clause License.
# BSD 3-Clause License
#
# Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
# Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team # noqa: E501
# All rights reserved.
#
# Copyright (c) 2011-2021, Open source contributors.
Expand Down
31 changes: 22 additions & 9 deletions modflow_devtools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from timeit import timeit
from typing import List, Optional, Tuple
from urllib import request
from urllib.error import URLError

from _warnings import warn
from urllib.error import URLError


@contextmanager
Expand Down Expand Up @@ -71,7 +71,8 @@ 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.
Expand Down Expand Up @@ -151,9 +152,11 @@ def get_current_branch() -> str:

def get_packages(namefile_path: PathLike) -> List[str]:
"""
Return a list of packages used by the simulation or model defined in the given namefile.
The namefile may be for an entire simulation or for a GWF or GWT model. If a simulation
namefile is given, packages used in its component model namefiles will be included.
Return a list of packages used by the simulation
or model defined in the given namefile. The namefile
may be for an entire simulation or for a GWF or GWT
model. If a simulation namefile is given, packages
used in its component model namefiles will be included.
Parameters
----------
Expand All @@ -175,7 +178,8 @@ def parse_model_namefile(line):
nf_path = [path.parent / s for s in line.split(" ") if s != ""][1]
if nf_path.suffix != ".nam":
raise ValueError(
f"Failed to parse GWF or GWT model namefile from simulation namefile line: {line}"
"Failed to parse GWF or GWT model namefile "
f"from simulation namefile line: {line}"
)
return nf_path

Expand Down Expand Up @@ -324,14 +328,16 @@ def is_github_rate_limited() -> Optional[bool]:
Returns
-------
True if rate-limiting is applied, otherwise False (or None if the connection fails).
True if rate-limiting is applied, otherwise False
(or None if the connection fails).
"""
try:
with request.urlopen("https://api.github.com/users/octocat") as response:
remaining = int(response.headers["x-ratelimit-remaining"])
if remaining < 10:
warn(
f"Only {remaining} GitHub API requests remaining before rate-limiting"
f"Only {remaining} GitHub API requests "
"remaining before rate-limiting"
)
return remaining > 0
except (ValueError, URLError):
Expand Down Expand Up @@ -465,7 +471,14 @@ def get_env(name: str, default: object = None) -> Optional[object]:
if isinstance(default, bool):
v = v.lower().title()
v = literal_eval(v)
except (AttributeError, ValueError, TypeError, SyntaxError, MemoryError, RecursionError):
except (
AttributeError,
ValueError,
TypeError,
SyntaxError,
MemoryError,
RecursionError,
):
return default
if default is None:
return v
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ include = [
".github/**/*.py",
]

[tool.ruff.lint]
select = ["F", "E", "I001"]

[tool.setuptools]
packages = ["modflow_devtools"]
include-package-data = true
Expand Down
3 changes: 2 additions & 1 deletion scripts/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def update_version(
"--get",
required=False,
action="store_true",
help="Just get the current version number, don't update anything (defaults to false)",
help="Just get the current version number, "
"don't update anything (defaults to false)",
)
args = parser.parse_args()

Expand Down

0 comments on commit 08eff72

Please sign in to comment.