diff --git a/autotest/test_download.py b/autotest/test_download.py index dc3b43b..b1ecc47 100644 --- a/autotest/test_download.py +++ b/autotest/test_download.py @@ -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")] ) diff --git a/autotest/test_markers.py b/autotest/test_markers.py index e93020b..8df2a49 100644 --- a/autotest/test_markers.py +++ b/autotest/test_markers.py @@ -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" diff --git a/autotest/test_misc.py b/autotest/test_misc.py index e6c5b00..c3034a3 100644 --- a/autotest/test_misc.py +++ b/autotest/test_misc.py @@ -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: diff --git a/autotest/test_zip.py b/autotest/test_zip.py index 070b9c4..96f1c79 100644 --- a/autotest/test_zip.py +++ b/autotest/test_zip.py @@ -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) diff --git a/modflow_devtools/download.py b/modflow_devtools/download.py index 719220d..4c2b67e 100644 --- a/modflow_devtools/download.py +++ b/modflow_devtools/download.py @@ -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()) @@ -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: diff --git a/modflow_devtools/fixtures.py b/modflow_devtools/fixtures.py index ec4d412..fe7b1ce 100644 --- a/modflow_devtools/fixtures.py +++ b/modflow_devtools/fixtures.py @@ -115,9 +115,12 @@ 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.", ) @@ -125,9 +128,12 @@ def pytest_addoption(parser): "--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.", ) @@ -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( @@ -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( @@ -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'.", ) diff --git a/modflow_devtools/imports.py b/modflow_devtools/imports.py index 625c59d..909e1d2 100644 --- a/modflow_devtools/imports.py +++ b/modflow_devtools/imports.py @@ -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. diff --git a/modflow_devtools/misc.py b/modflow_devtools/misc.py index e5ce467..fac9ce9 100644 --- a/modflow_devtools/misc.py +++ b/modflow_devtools/misc.py @@ -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 @@ -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. @@ -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 ---------- @@ -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 @@ -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): @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 794e61c..2fd9627 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,6 +82,9 @@ include = [ ".github/**/*.py", ] +[tool.ruff.lint] +select = ["F", "E", "I001"] + [tool.setuptools] packages = ["modflow_devtools"] include-package-data = true diff --git a/scripts/update_version.py b/scripts/update_version.py index 92a7724..26d34c0 100644 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -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()