mapbox / tilesets-cli

CLI for interacting with the Mapbox Tilesets API and Mapbox Tiling Service
https://docs.mapbox.com/mapbox-tiling-service
BSD 2-Clause "Simplified" License
125 stars 27 forks source link

Make `estimate-area` and rasterio/GDAL optional #149

Closed johnk1 closed 2 years ago

johnk1 commented 2 years ago

fixes #147

This makes estimate-area an optional command. This command depends on rasterio w/GDAL, which is not as easily installed on arm64 Macs. So, this PR enables a simple installation for most uses while still keeping this command available.

testing

This shows the basic installation without estimate-area. We see the command fails with an exception.

$ pyenv activate env1
$ pip install mapbox-tilesets==1.7.3a1
    Collecting mapbox-tilesets==1.7.3a1
    Downloading mapbox_tilesets-1.7.3a1-py3-none-any.whl (15 kB)
    ...

$ tilesets --version
    1.7.3a1

$ tilesets list <account>
  ... list of tilesets

$ tilesets estimate-area valid.ldgeojson  -p 10m
    Traceback (most recent call last):
    File "/Users/johnklancer/.pyenv/versions/fresh/bin/tilesets", line 8, in <module>
        sys.exit(cli())
    File "/Users/johnklancer/.pyenv/versions/3.9.10/envs/fresh/lib/python3.9/site-packages/click/core.py", line 829, in __call__
        return self.main(*args, **kwargs)
    File "/Users/johnklancer/.pyenv/versions/3.9.10/envs/fresh/lib/python3.9/site-packages/click/core.py", line 782, in main
        rv = self.invoke(ctx)
    File "/Users/johnklancer/.pyenv/versions/3.9.10/envs/fresh/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/Users/johnklancer/.pyenv/versions/3.9.10/envs/fresh/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
        return ctx.invoke(self.callback, **ctx.params)
    File "/Users/johnklancer/.pyenv/versions/3.9.10/envs/fresh/lib/python3.9/site-packages/click/core.py", line 610, in invoke
        return callback(*args, **kwargs)
    File "/Users/johnklancer/.pyenv/versions/3.9.10/envs/fresh/lib/python3.9/site-packages/mapbox_tilesets/scripts/cli.py", line 756, in estimate_area
        filter_features = utils.load_module("supermercado.super_utils").filter_features
    File "/Users/johnklancer/.pyenv/versions/3.9.10/envs/fresh/lib/python3.9/site-packages/mapbox_tilesets/utils.py", line 18, in load_module
        raise ValueError(
    ValueError: Couldn't find supermercado.super_utils. Check installation steps in the readme for help.

This test shows the full installation including estimate-area. Testing on an M1 with brew install gdal already run.

$ pyenv activate env2
$ pip install 'mapbox-tilesets[estimate-area]'==1.7.3a1
Collecting mapbox-tilesets[estimate-area]==1.7.3a1
    ...
$ tilesets estimate-area valid.ldgeojson  -p 10m
{"km2": "382565", "precision": "10m", "pricing_docs": "For more information, visit https://www.mapbox.com/pricing/#tilesets"}

After review

Once this is merged, I will bump the version to 1.7.3, tag, and verify it's published.