Skip to content

Commit

Permalink
De-lint project files (#71)
Browse files Browse the repository at this point in the history
* Remove trailing whitespace

* Format files

* Remove unused, obsolete Tuple imports

* Strip outputs from notebooks

* Remove unused import

* Escape shell commands in cells

* Make pretty

* Use ruff check

* Use f-strings consistently

* Use single quotes inside double quotes
  • Loading branch information
mdpiper authored Aug 10, 2024
1 parent 4a34cb4 commit e09ec64
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 1,019 deletions.
2 changes: 1 addition & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Acknowledgments
---------------

This work is supported by the National Science Foundation under Award No.
[2026951](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2026951),
[2026951](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2026951),
*EarthCube Capabilities: Cloud-Based Accessible and Reproducible Modeling for Water and Sediment Research*.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ there are three ways to use it with *bmi-topography*:
3. *dot file*: Put the API key in the file `.opentopography.txt` in the current directory or in your home directory.

If you attempt to use *bmi-topography* to access an OpenTopography dataset without an API key,
you'll get a error like this:
you'll get a error like this:
```
requests.exceptions.HTTPError: 401 Client Error: This dataset requires an API Key for access.
```
Expand Down
2 changes: 1 addition & 1 deletion bmi_topography/api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def from_env(cls):
def from_file(cls):
"""Read the key from a file."""
if filepath := _find_first_of(ApiKey.API_KEY_FILES):
with open(filepath, "r") as fp:
with open(filepath) as fp:
api_key = fp.read().strip()
else:
raise MissingKeyError(
Expand Down
37 changes: 10 additions & 27 deletions bmi_topography/bbox.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections.abc import Iterable
from typing import Tuple


class BoundingBox:
Expand All @@ -16,56 +15,40 @@ class BoundingBox:
"""

def __init__(self, lower_left: Tuple[float], upper_right: Tuple[float]) -> None:
def __init__(self, lower_left: tuple[float], upper_right: tuple[float]) -> None:
self._lower_left = lower_left
self._upper_right = upper_right

if not isinstance(self.lower_left, Iterable) or len(self.lower_left) != 2:
raise ValueError(
"lower left coordinate ({0}) must have two elements".format(
self.lower_left
)
f"lower left coordinate ({self.lower_left}) must have two elements"
)

if not isinstance(self.upper_right, Iterable) or len(self.upper_right) != 2:
raise ValueError(
"upper right coordinate ({0}) must have two elements".format(
self.upper_right
)
f"upper right coordinate ({self.upper_right}) must have two elements"
)

if self.south > 90 or self.south < -90:
raise ValueError(
"south coordinate ({0}) must be in [-90,90]".format(self.south)
)
raise ValueError(f"south coordinate ({self.south}) must be in [-90,90]")

if self.north > 90 or self.north < -90:
raise ValueError(
"north coordinate ({0}) must be in [-90,90]".format(self.north)
)
raise ValueError(f"north coordinate ({self.north}) must be in [-90,90]")

if self.south > self.north:
raise ValueError(
"south coordinate ({0}) must be less than north ({1})".format(
self.south, self.north
)
f"south coordinate ({self.south}) must be less than north ({self.north})"
)

if self.west > 180 or self.west < -180:
raise ValueError(
"west coordinate ({0}) must be in [-180,180]".format(self.west)
)
raise ValueError(f"west coordinate ({self.west}) must be in [-180,180]")

if self.east > 180 or self.east < -180:
raise ValueError(
"east coordinate ({0}) must be in [-180,180]".format(self.east)
)
raise ValueError(f"east coordinate ({self.east}) must be in [-180,180]")

if self.west > self.east:
raise ValueError(
"west coordinate ({0}) must be less than east ({1})".format(
self.west, self.east
)
f"west coordinate ({self.west}) must be less than east ({self.east})"
)

@property
Expand Down Expand Up @@ -95,5 +78,5 @@ def east(self):
return self.upper_right[1]

def __str__(self):
s = "[{0}, {1}]".format(self.lower_left, self.upper_right)
s = f"[{self.lower_left}, {self.upper_right}]"
return s
8 changes: 3 additions & 5 deletions bmi_topography/bmi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from collections import namedtuple
from typing import Tuple

import numpy
import yaml
Expand Down Expand Up @@ -357,7 +355,7 @@ def get_input_item_count(self) -> int:
"""
return len(self._input_var_names)

def get_input_var_names(self) -> Tuple[str]:
def get_input_var_names(self) -> tuple[str]:
"""List of a model's input variables.
Input variable names must be CSDMS Standard Names, also known
Expand Down Expand Up @@ -389,7 +387,7 @@ def get_output_item_count(self) -> int:
"""
return len(self._output_var_names)

def get_output_var_names(self) -> Tuple[str]:
def get_output_var_names(self) -> tuple[str]:
"""List of a model's output variables.
Output variable names must be CSDMS Standard Names, also known
Expand Down Expand Up @@ -650,7 +648,7 @@ def initialize(self, config_file: str) -> None:
with placeholder values is used by the BMI.
"""
if config_file:
with open(config_file, "r") as fp:
with open(config_file) as fp:
self._config = yaml.safe_load(fp).get("bmi-topography", {})
else:
self._config = Topography.DEFAULT.copy()
Expand Down
2 changes: 1 addition & 1 deletion bmi_topography/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def main(quiet, dem_type, south, north, west, east, output_format, api_key, no_f
path_to_dem = topo.fetch()
if not quiet:
click.secho(
"File downloaded to {}".format(getattr(topo, "cache_dir")),
f"File downloaded to {getattr(topo, 'cache_dir')}",
fg="green",
err=True,
)
Expand Down
4 changes: 1 addition & 3 deletions bmi_topography/topography.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def __init__(
if dem_type in Topography.VALID_DEM_TYPES:
self._dem_type = dem_type
else:
raise ValueError(
"dem_type must be one of %s." % (Topography.VALID_DEM_TYPES,)
)
raise ValueError(f"dem_type must be one of {Topography.VALID_DEM_TYPES}.")

if output_format in Topography.VALID_OUTPUT_FORMATS.keys():
self._output_format = output_format
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
version = pkg_resources.get_distribution("bmi_topography").version
release = version
this_year = datetime.date.today().year
copyright = "%s, %s" % (this_year, author)
copyright = f"{this_year}, {author}"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ Acknowledgments
---------------

This work is supported by the National Science Foundation under Award No.
`2026951 <https://www.nsf.gov/awardsearch/showAward?AWD_ID=2026951>`_,
`2026951 <https://www.nsf.gov/awardsearch/showAward?AWD_ID=2026951>`_,
*EarthCube Capabilities: Cloud-Based Accessible and Reproducible Modeling for Water and Sediment Research*.
Loading

0 comments on commit e09ec64

Please sign in to comment.