Skip to content

Commit 227919e

Browse files
authored
Make estimate-area and rasterio/GDAL optional (#149)
1 parent bffa475 commit 227919e

File tree

9 files changed

+62
-14
lines changed

9 files changed

+62
-14
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: python
22
python:
33
- '3.6'
4+
- '3.7'
45
install:
56
- pip install -r requirements.txt -e .[test]
67
script:
@@ -16,4 +17,5 @@ deploy:
1617
password: $PYPI_PASSWORD
1718
distributions: "sdist bdist_wheel"
1819
on:
20+
python: 3.7
1921
tags: true

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Unreleased
2-
- Hide deprecated `add-source` command from command list.
3-
- Raise error in `tilesets status` for non-200s (includes unpublished tilesets).
42

53
=======
64

5+
# 1.7.3 (2022-03-14)
6+
- Loads `supermercado` on request because binaries for arm64 MacOS and Windows are not easily available.
7+
- Hide deprecated `add-source` command from command list.
8+
- Raise error in `tilesets status` for non-200s (includes unpublished tilesets).
9+
710
# 1.7.2 (2021-10-01)
811
- Provide description for `upload-source` command, and label `add-source` command as deprecated.
912

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Releases to PyPi are handled via TravisCI and GitHub tags. Once changes have bee
7070
All tests are runnable with pytest. pytest is not installed by default and can be installed with the pip test extras
7171

7272
```shell
73-
pip install -e .[test]
73+
pip install -e '.[test]'
7474
```
7575

7676
Running tests

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,38 @@ CLI for interacting with and preparing data for the [Mapbox Tiling Service](http
1212
[CONTRIBUTING.md](/CONTRIBUTING.md) includes information about release processes & running tests. :raised_hands:
1313

1414
# Installation
15-
`pip install mapbox-tilesets`
1615

17-
#### Requirements
16+
## Requirements
1817

1918
- Python >= 3.6 (can be installed via virtualenv)
2019
- Recommended: [virtualenv](https://virtualenv.pypa.io/) / [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/)
21-
- Windows only: binaries installed for [GDAL](http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal) and [rasterio](http://www.lfd.uci.edu/~gohlke/pythonlibs/#rasterio) (note: Windows is not officially supported at this time)
2220

23-
#### Mapbox Access Tokens
21+
## Basic installation
22+
23+
`pip install mapbox-tilesets` will install everything but [`estimate-area`](#estimate-area).
24+
## Installing optional `estimate-area` command
25+
If you are using an x86 Mac or Linux machine, run:
26+
`pip install 'mapbox-tilesets[estimate-area]'`
27+
28+
Otherwise, you will need to install some dependencies.
29+
30+
### arm64 MacOS
31+
If you're on an arm64 Mac (e.g., with an M1 chip), you'll need to install [GDAL](https://gdal.org/) first. On Mac, a simple way is to use [Homebrew](https://brew.sh/):
32+
```sh
33+
$ brew install gdal
34+
...
35+
$ pip install 'mapbox-tilesets[estimate-area]'
36+
```
37+
38+
### Windows
39+
Note, Windows is not officially supported at this time.
40+
41+
Windows users need to install [GDAL](http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal) and [rasterio](http://www.lfd.uci.edu/~gohlke/pythonlibs/#rasterio).
42+
Then `pip install 'mapbox-tilesets[estimate-area]'`
43+
44+
45+
46+
## Mapbox Access Tokens
2447

2548
In order to use the tilesets endpoints, you need a Mapbox Access Token with `tilesets:write`, `tilesets:read`, and `tilesets:list` scopes. This is a secret token, so do not share it publicly!
2649

mapbox_tilesets/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""mapbox_tilesets package"""
22

3-
__version__ = "1.7.2"
3+
__version__ = "1.7.3"

mapbox_tilesets/scripts/cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tilesets command line interface"""
2+
import builtins
23
import json
34
import tempfile
45

@@ -9,8 +10,6 @@
910

1011
import mapbox_tilesets
1112
from mapbox_tilesets import utils, errors
12-
from supermercado.super_utils import filter_features
13-
import builtins
1413

1514

1615
@click.version_option(version=mapbox_tilesets.__version__, message="%(version)s")
@@ -748,12 +747,14 @@ def validate_stream(features):
748747
help="Enables 1cm precision",
749748
)
750749
def estimate_area(features, precision, no_validation=False, force_1cm=False):
751-
"""Estimate area of features with a precision level.
750+
"""Estimate area of features with a precision level. Requires extra installation steps: see https://github.com/mapbox/tilesets-cli/blob/master/README.md
752751
753752
tilesets estimate-area <features> <precision>
754753
755754
features must be a list of paths to local files containing GeoJSON feature collections or feature sequences from argument or stdin, or a list of string-encoded coordinate pairs of the form "[lng, lat]", or "lng, lat", or "lng lat".
756755
"""
756+
filter_features = utils.load_module("supermercado.super_utils").filter_features
757+
757758
area = 0
758759
if precision == "1cm" and not force_1cm:
759760
raise errors.TilesetsError(

mapbox_tilesets/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1+
import importlib
12
import os
23
import re
34

45
import numpy as np
56

67
from jsonschema import validate
78
from requests import Session
8-
from supermercado.burntiles import burn
99

1010
import mapbox_tilesets
1111

1212

13+
def load_module(modulename):
14+
"""Dynamically imports a module and throws a readable exception if not found"""
15+
try:
16+
module = importlib.import_module(modulename)
17+
except (ImportError):
18+
raise ValueError(
19+
f"Couldn't find {modulename}. Check installation steps in the readme for help: https://github.com/mapbox/tilesets-cli/blob/master/README.md"
20+
) from None
21+
22+
return module
23+
24+
1325
def _get_token(token=None):
1426
"""Get Mapbox access token from arg or environment"""
1527
token = (
@@ -206,6 +218,8 @@ def calculate_tiles_area(features, precision):
206218
-------
207219
total area of all tiles in square kilometers
208220
"""
221+
burn = load_module("supermercado.burntiles").burn
222+
209223
zoom = _convert_precision_to_zoom(precision)
210224
tiles = burn(features, zoom)
211225
return np.sum(_calculate_tile_area(tiles))

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
boto3==1.9.99
22
Click==7.1.2
33
cligj==0.5.0
4+
numpy==1.19.5
45
requests==2.21.0
56
requests-toolbelt==0.9.1
67
jsonschema==3.0.1

setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,29 @@ def read(fname):
3030
"boto3",
3131
"click~=7.1.2",
3232
"cligj",
33+
"numpy",
3334
"requests",
3435
"requests-toolbelt",
3536
"jsonschema~=3.0",
3637
"jsonseq~=1.0",
3738
"mercantile~=1.1.6",
38-
"supermercado~=0.2.0",
3939
],
4040
include_package_data=True,
4141
zip_safe=False,
4242
extras_require={
43+
"estimate-area": [
44+
"supermercado~=0.2.0",
45+
],
4346
"test": [
4447
"codecov",
4548
"pytest==4.6.11",
4649
"pytest-cov",
4750
"pre-commit",
4851
"black==20.8b1",
4952
"pep8",
53+
"supermercado~=0.2.0",
5054
"toml==0.10.2",
51-
]
55+
],
5256
},
5357
entry_points="""
5458
[console_scripts]

0 commit comments

Comments
 (0)