Skip to content

Commit

Permalink
moved to the totally rust cli'
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekrubin committed Nov 10, 2023
1 parent 9daf73e commit e02d073
Show file tree
Hide file tree
Showing 14 changed files with 637 additions and 622 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/utiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ serde_json = "1.0.96"
thiserror = "1.0.50"
tilejson = "0.3.2"
tracing = { version = "0.1.40", features = [] }
log = "0.4.20"
9 changes: 6 additions & 3 deletions crates/utiles/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ pub fn parse_bbox(s: &str) -> serde_json::Result<BBox> {

let v: Value = serde_json::from_str(s)?;

debug!("{}", v);
// Assume a single pair of coordinates represents a CoordTuple
// and a four-element array represents a BBoxTuple
match v.as_array().map(|arr| arr.len()) {
let bbox = match v.as_array().map(|arr| arr.len()) {
Some(2) => {
let coord: (f64, f64) = serde_json::from_value(v)?;
let coord: (f64, f64) = serde_json::from_value::<(f64, f64)>(v)?;
Ok(BBox::new(coord.0, coord.1, coord.0, coord.1))
}
Some(4) => {
let bbox: (f64, f64, f64, f64) = serde_json::from_value(v)?;
Ok(BBox::from(bbox))
}
_ => panic!("Expected a two-element array or a four-element array"),
}
};
debug!("bbox: {:?}", bbox);
bbox
}

pub fn coords2bounds<I>(mut coords: I) -> Option<(f64, f64, f64, f64)>
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ dependencies = [

[project.scripts]
utiles = "utiles.cli:cli"
ut = "utiles._cli:cli"
ut = "utiles.cli:cli"
utilesv1 = "utiles._legacy.cli:cli"

[project.entry-points."rasterio.rio_plugins"]
utiles = "utiles.rio_plugin:rio_utiles"
Expand Down
4 changes: 4 additions & 0 deletions python/utiles/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ def main() -> None:
if __name__ == "__main__":
if sys.argv[-1].endswith("__main__.py"):
main()
else:
from utiles._cli import cli

cli()
22 changes: 0 additions & 22 deletions python/utiles/_cli.py

This file was deleted.

48 changes: 27 additions & 21 deletions python/utiles/_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import click

from utiles import __version__
from utiles._cli import cli
from utiles.cli import cli

logger = logging.getLogger(__name__)

Expand All @@ -17,25 +17,31 @@ def get_help_option(self, _ctx: click.Context) -> None:


# The CLI command group.
@click.command(
name="utiles",
cls=NoHelpCommand,
help="utiles cli (python-rust)",
no_args_is_help=False,
context_settings={
"ignore_unknown_options": True,
"allow_extra_args": True,
},
)
@click.version_option(version=__version__, message="%(version)s")
def cli_click() -> None:
"""Execute the main utiles command"""
try:
cli()
except Exception as e:
logger.error(e)
raise click.BadParameter(str(e)) from e

def _click_cli(name: str) -> NoHelpCommand:
@click.command(
name=name,
cls=NoHelpCommand,
help="utiles cli (python-rust)",
no_args_is_help=False,
context_settings={
"ignore_unknown_options": True,
"allow_extra_args": True,
},
)
@click.version_option(version=__version__, message="%(version)s")
def _cli_fn() -> None:
"""Execute the main utiles command"""
try:
cli()
except Exception as e:
logger.error(e)
raise click.BadParameter(str(e)) from e

return _cli_fn


utiles_click = _click_cli("utiles")
ut_click = _click_cli("ut")

if __name__ == "__main__":
cli_click()
utiles_click()
Empty file.
Loading

0 comments on commit e02d073

Please sign in to comment.