Skip to content

Commit e09ec64

Browse files
authored
De-lint project files (#71)
* 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
1 parent 4a34cb4 commit e09ec64

File tree

13 files changed

+144
-1019
lines changed

13 files changed

+144
-1019
lines changed

CREDITS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Acknowledgments
1616
---------------
1717

1818
This work is supported by the National Science Foundation under Award No.
19-
[2026951](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2026951),
19+
[2026951](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2026951),
2020
*EarthCube Capabilities: Cloud-Based Accessible and Reproducible Modeling for Water and Sediment Research*.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ there are three ways to use it with *bmi-topography*:
8181
3. *dot file*: Put the API key in the file `.opentopography.txt` in the current directory or in your home directory.
8282

8383
If you attempt to use *bmi-topography* to access an OpenTopography dataset without an API key,
84-
you'll get a error like this:
84+
you'll get a error like this:
8585
```
8686
requests.exceptions.HTTPError: 401 Client Error: This dataset requires an API Key for access.
8787
```

bmi_topography/api_key.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def from_env(cls):
7575
def from_file(cls):
7676
"""Read the key from a file."""
7777
if filepath := _find_first_of(ApiKey.API_KEY_FILES):
78-
with open(filepath, "r") as fp:
78+
with open(filepath) as fp:
7979
api_key = fp.read().strip()
8080
else:
8181
raise MissingKeyError(

bmi_topography/bbox.py

+10-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from collections.abc import Iterable
2-
from typing import Tuple
32

43

54
class BoundingBox:
@@ -16,56 +15,40 @@ class BoundingBox:
1615
1716
"""
1817

19-
def __init__(self, lower_left: Tuple[float], upper_right: Tuple[float]) -> None:
18+
def __init__(self, lower_left: tuple[float], upper_right: tuple[float]) -> None:
2019
self._lower_left = lower_left
2120
self._upper_right = upper_right
2221

2322
if not isinstance(self.lower_left, Iterable) or len(self.lower_left) != 2:
2423
raise ValueError(
25-
"lower left coordinate ({0}) must have two elements".format(
26-
self.lower_left
27-
)
24+
f"lower left coordinate ({self.lower_left}) must have two elements"
2825
)
2926

3027
if not isinstance(self.upper_right, Iterable) or len(self.upper_right) != 2:
3128
raise ValueError(
32-
"upper right coordinate ({0}) must have two elements".format(
33-
self.upper_right
34-
)
29+
f"upper right coordinate ({self.upper_right}) must have two elements"
3530
)
3631

3732
if self.south > 90 or self.south < -90:
38-
raise ValueError(
39-
"south coordinate ({0}) must be in [-90,90]".format(self.south)
40-
)
33+
raise ValueError(f"south coordinate ({self.south}) must be in [-90,90]")
4134

4235
if self.north > 90 or self.north < -90:
43-
raise ValueError(
44-
"north coordinate ({0}) must be in [-90,90]".format(self.north)
45-
)
36+
raise ValueError(f"north coordinate ({self.north}) must be in [-90,90]")
4637

4738
if self.south > self.north:
4839
raise ValueError(
49-
"south coordinate ({0}) must be less than north ({1})".format(
50-
self.south, self.north
51-
)
40+
f"south coordinate ({self.south}) must be less than north ({self.north})"
5241
)
5342

5443
if self.west > 180 or self.west < -180:
55-
raise ValueError(
56-
"west coordinate ({0}) must be in [-180,180]".format(self.west)
57-
)
44+
raise ValueError(f"west coordinate ({self.west}) must be in [-180,180]")
5845

5946
if self.east > 180 or self.east < -180:
60-
raise ValueError(
61-
"east coordinate ({0}) must be in [-180,180]".format(self.east)
62-
)
47+
raise ValueError(f"east coordinate ({self.east}) must be in [-180,180]")
6348

6449
if self.west > self.east:
6550
raise ValueError(
66-
"west coordinate ({0}) must be less than east ({1})".format(
67-
self.west, self.east
68-
)
51+
f"west coordinate ({self.west}) must be less than east ({self.east})"
6952
)
7053

7154
@property
@@ -95,5 +78,5 @@ def east(self):
9578
return self.upper_right[1]
9679

9780
def __str__(self):
98-
s = "[{0}, {1}]".format(self.lower_left, self.upper_right)
81+
s = f"[{self.lower_left}, {self.upper_right}]"
9982
return s

bmi_topography/bmi.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
from collections import namedtuple
3-
from typing import Tuple
42

53
import numpy
64
import yaml
@@ -357,7 +355,7 @@ def get_input_item_count(self) -> int:
357355
"""
358356
return len(self._input_var_names)
359357

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

392-
def get_output_var_names(self) -> Tuple[str]:
390+
def get_output_var_names(self) -> tuple[str]:
393391
"""List of a model's output variables.
394392
395393
Output variable names must be CSDMS Standard Names, also known
@@ -650,7 +648,7 @@ def initialize(self, config_file: str) -> None:
650648
with placeholder values is used by the BMI.
651649
"""
652650
if config_file:
653-
with open(config_file, "r") as fp:
651+
with open(config_file) as fp:
654652
self._config = yaml.safe_load(fp).get("bmi-topography", {})
655653
else:
656654
self._config = Topography.DEFAULT.copy()

bmi_topography/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def main(quiet, dem_type, south, north, west, east, output_format, api_key, no_f
7878
path_to_dem = topo.fetch()
7979
if not quiet:
8080
click.secho(
81-
"File downloaded to {}".format(getattr(topo, "cache_dir")),
81+
f"File downloaded to {getattr(topo, 'cache_dir')}",
8282
fg="green",
8383
err=True,
8484
)

bmi_topography/topography.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ def __init__(
6464
if dem_type in Topography.VALID_DEM_TYPES:
6565
self._dem_type = dem_type
6666
else:
67-
raise ValueError(
68-
"dem_type must be one of %s." % (Topography.VALID_DEM_TYPES,)
69-
)
67+
raise ValueError(f"dem_type must be one of {Topography.VALID_DEM_TYPES}.")
7068

7169
if output_format in Topography.VALID_OUTPUT_FORMATS.keys():
7270
self._output_format = output_format

docs/source/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
version = pkg_resources.get_distribution("bmi_topography").version
2929
release = version
3030
this_year = datetime.date.today().year
31-
copyright = "%s, %s" % (this_year, author)
31+
copyright = f"{this_year}, {author}"
3232

3333

3434
# -- General configuration ---------------------------------------------------

docs/source/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ Acknowledgments
5151
---------------
5252

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

0 commit comments

Comments
 (0)