Skip to content

Commit 3f923a2

Browse files
Add precommit & ruff linter/formatter & fix initial set of errors (#45)
* Add pre-commit config with Ruff linter/formatter * Apply Ruff autofixes * Remove unused variable * Switch to explicit import * Switch lambda for def * Set Ruff to show fixes * fetchez.spatial imports To fix from fetchez.spatial import * we have to explicitly import everything from fetchez.spatial... * Update spatial.py --------- Co-authored-by: Matthew Love <33066727+matth-love@users.noreply.github.com>
1 parent 55c0ede commit 3f923a2

10 files changed

Lines changed: 107 additions & 19 deletions

File tree

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ci:
2+
autoupdate_schedule: quarterly
3+
autofix_prs: false
4+
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v6.0.0
8+
hooks:
9+
- id: forbid-new-submodules
10+
- id: end-of-file-fixer
11+
- id: check-case-conflict
12+
- id: requirements-txt-fixer
13+
- id: check-added-large-files
14+
args: ['--maxkb=500']
15+
- id: check-json
16+
- id: check-toml
17+
- id: check-yaml
18+
- id: debug-statements
19+
- id: check-builtin-literals
20+
- id: trailing-whitespace
21+
22+
- repo: https://github.com/astral-sh/ruff-pre-commit
23+
rev: v0.15.2
24+
hooks:
25+
- id: ruff-check
26+
args: ['--fix', '--show-fixes']
27+
- id: ruff-format

AUTHORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
* Elliot Lim (@e1im)
88
* Christopher Amante (@camante)
99
* Michael McFerrin (@mmacferrin)
10-
* Matt Fisher (@mfisher87)
10+
* Matt Fisher (@mfisher87)

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ website: https://transformez.readthedocs.io
1616
title: "Transformez"
1717
version: 0.3.6
1818
date-released: 2026-04-08
19-
url: "https://github.com/continuous-dems/transformez"
19+
url: "https://github.com/continuous-dems/transformez"

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Originally developed as the core transformation engine for the [CUDEM](https://g
2222

2323
### ❓ Why Transformez?
2424

25-
Vertical Datum transformations can cause a lot of confusion and headache when trying to process heterogeneous data from around the world into a single unified vertial reference.
25+
Vertical Datum transformations can cause a lot of confusion and headache when trying to process heterogeneous data from around the world into a single unified vertial reference.
2626

2727
**Transformez simplifies this process!**
2828

src/transformez/cli.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,30 @@ def install_vdatum():
329329
@vdatum_group.command("run")
330330
@click.argument("input_file", type=click.Path(exists=True))
331331
@click.argument("output_file", type=click.Path())
332-
@click.option("-I", "--in-datum", required=True, help="VDatum input datum string (e.g., 'navd88')")
333-
@click.option("-O", "--out-datum", required=True, help="VDatum output datum string (e.g., 'nad83_2011')")
332+
@click.option(
333+
"-I", "--in-datum", required=True, help="VDatum input datum string (e.g., 'navd88')"
334+
)
335+
@click.option(
336+
"-O",
337+
"--out-datum",
338+
required=True,
339+
help="VDatum output datum string (e.g., 'nad83_2011')",
340+
)
334341
@click.option("--in-unit", default="m", help="Input units (m, ft, us-ft)")
335342
@click.option("--out-unit", default="m", help="Output units (m, ft, us-ft)")
336343
@click.option("--region", default="4", help="VDatum region grid")
337-
def run_vdatum_cli(input_file, output_file, in_datum, out_datum, in_unit, out_unit, region):
344+
def run_vdatum_cli(
345+
input_file, output_file, in_datum, out_datum, in_unit, out_unit, region
346+
):
338347
"""Process an XYZ text file through the local VDatum Java engine."""
339348

340349
from transformez.vdatum import Vdatum
341350

342-
vd = Vdatum(ivert=f"{in_datum}:{in_unit}:height", overt=f"{out_datum}:{out_unit}:height", region=region).run_vdatum(input_file)
351+
Vdatum(
352+
ivert=f"{in_datum}:{in_unit}:height",
353+
overt=f"{out_datum}:{out_unit}:height",
354+
region=region,
355+
).run_vdatum(input_file)
343356

344357

345358
@vdatum_group.command("list")
@@ -351,5 +364,6 @@ def vdatum_list():
351364
vd = Vdatum().vdatum_help()
352365
click.echo(vd)
353366

367+
354368
if __name__ == "__main__":
355369
transformez_cli()

src/transformez/spatial.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,55 @@
1717

1818
import numpy as np
1919
from fetchez.utils import str_or
20-
from fetchez.spatial import *
20+
from fetchez.spatial import (
21+
Region,
22+
parse_region,
23+
region_from_geojson,
24+
region_from_place,
25+
fix_argparse_region,
26+
region_valid_p,
27+
region_center,
28+
region_to_shapely,
29+
region_to_wkt,
30+
_extract_coords,
31+
region_to_bbox,
32+
region_to_geojson_geom,
33+
region_from_list,
34+
region_from_string,
35+
chunk_region,
36+
buffer_region,
37+
)
2138
from . import srs
2239

2340
import pyproj
2441

2542
logger = logging.getLogger(__name__)
2643

44+
__all__ = [
45+
# Transformez
46+
"TransRegion",
47+
"parse_region",
48+
"x360",
49+
"transform_increment",
50+
# Fetchez
51+
"Region",
52+
"parse_region",
53+
"region_from_geojson",
54+
"region_from_place",
55+
"fix_argparse_region",
56+
"region_valid_p",
57+
"region_center",
58+
"region_to_shapely",
59+
"region_to_wkt",
60+
"_extract_coords",
61+
"region_to_bbox",
62+
"region_to_geojson_geom",
63+
"region_from_list",
64+
"region_from_string",
65+
"chunk_region",
66+
"buffer_region",
67+
]
68+
2769

2870
class TransRegion(Region):
2971
# gtl is (geo-transform, xcount, ycount)

src/transformez/transform.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ def fetch_grid_(self, module_name, **kwargs):
195195
return valid
196196

197197
def _get_grid(self, provider, name):
198-
import re
199198

200199
if not name:
201200
return np.zeros((self.ny, self.nx))
@@ -207,15 +206,16 @@ def _get_grid(self, provider, name):
207206
name = name.split("=")[1]
208207

209208
files = self.fetch_grid(provider, datatype=name, query=name)
210-
if provider == 'vdatum':
209+
if provider == "vdatum":
211210
import rasterio
211+
212212
def get_bbox_area(filepath):
213213
try:
214214
with rasterio.open(filepath) as src:
215215
b = src.bounds
216216
return (b.right - b.left) * (b.top - b.bottom)
217217
except Exception:
218-
return float('inf')
218+
return float("inf")
219219

220220
# Largest (Offshore) loads first, Smallest (Rivers) load last and overwrite
221221
files.sort(key=get_bbox_area, reverse=True)

src/transformez/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
import rasterio
1919

2020
logger = logging.getLogger(__name__)
21-
cmd_exists = lambda x: any(
22-
os.access(os.path.join(path, x), os.X_OK)
23-
for path in os.environ["PATH"].split(os.pathsep)
24-
)
21+
22+
23+
def cmd_exists(x: str) -> bool:
24+
return any(
25+
os.access(os.path.join(path, x), os.X_OK)
26+
for path in os.environ["PATH"].split(os.pathsep)
27+
)
2528

2629

2730
def run_cmd(args):

src/transformez/vdatum.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def vdatum_get_version(self):
8181
if self.jar is None:
8282
self.vdatum_locate_jar()
8383
if self.jar is not None:
84-
out, _ = utils.run_cmd(f"java -jar {self.jar} -")#, verbose=self.verbose)
84+
out, _ = utils.run_cmd(f"java -jar {self.jar} -") # , verbose=self.verbose)
8585
for i in out.decode("utf-8").split("\n"):
8686
if "- v" in i.strip():
8787
return i.strip().split("v")[-1]
@@ -108,7 +108,7 @@ def vdatum_xyz(self, xyz):
108108
)
109109

110110
out, _ = utils.run_cmd(
111-
f"java -Djava.awt.headless=false -jar {self.jar} {vdc}"#, verbose=False
111+
f"java -Djava.awt.headless=false -jar {self.jar} {vdc}" # , verbose=False
112112
)
113113
z = xyz[2]
114114
for i in out.split("\n"):
@@ -143,7 +143,9 @@ def run_vdatum(self, src_fn):
143143
f"-nodata -file:txt:{self.delim},{self.xyzl},skip{self.skip}:{src_fn}:{self.result_dir} "
144144
f"{epoch_str}region:{self.region}"
145145
)
146-
return utils.run_cmd(f"java -jar {self.jar} {vdc}")#, verbose=self.verbose)
146+
return utils.run_cmd(
147+
f"java -jar {self.jar} {vdc}"
148+
) # , verbose=self.verbose)
147149
else:
148150
return [], -1
149151

0 commit comments

Comments
 (0)