Skip to content

Commit 0e1a2dc

Browse files
committed
merge in master
2 parents d21f72b + 1364d5a commit 0e1a2dc

File tree

11 files changed

+111
-47
lines changed

11 files changed

+111
-47
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ repos:
22
-
33
repo: 'https://github.com/ambv/black'
44
# 18.6b1
5-
rev: stable
5+
rev: 20.8b1
66
hooks:
77
- id: black
88
args: ['--safe']
99
-
10-
repo: 'https://github.com/pre-commit/pre-commit-hooks'
11-
rev: v2.0.0
10+
repo: 'https://gitlab.com/pycqa/flake8'
11+
rev: 3.9.0
1212
hooks:
1313
- id: flake8
1414
args: [

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
# Unreleased
22

3-
# 1.5.2
3+
=======
4+
5+
# 1.7.1 (2021-04-16)
46
- Switch to codecov python module
57

8+
# 1.7.0 (2021-04-02)
9+
- Update `tilesets publish` success message to include link to studio.mapbox.com/tilesets/* endpoint and include `tilesets job` command to view the status.
10+
11+
# 1.6.0 (2021-02-16)
12+
- Fix problem that prevented estimate-area from working for MultiPolygons
13+
- Improve documentation for delete-source and upload-source
14+
615
# 1.5.1 (2020-10-19)
716
- Update README for estimate-area
817

README.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export MAPBOX_ACCESS_TOKEN=my.token
4040
* *deprecated* [`add-source`](#deprecated-add-source)
4141
* [`validate-source`](#validate-source)
4242
* [`view-source`](#view-source)
43-
* [`list-sources`](#list-source)
43+
* [`list-sources`](#list-sources)
4444
* [`delete-source`](#delete-source)
4545
* [`estimate-area`](#estimate-area)
4646
* Recipes
@@ -61,11 +61,13 @@ export MAPBOX_ACCESS_TOKEN=my.token
6161
### upload-source
6262

6363
```shell
64-
tilesets upload-source <username> <id> <file>
64+
tilesets upload-source <username> <source_id> <file>
6565
```
6666

6767
Uploads GeoJSON files to a source for tiling. Accepts line-delimited GeoJSON or GeoJSON feature collections as files or via `stdin`. The CLI automatically converts data to line-delimited GeoJSON prior to uploading. Can be used to add data to a source or to replace all of the data in a source with the `--replace` flag.
6868

69+
Please note that if your source data is a FeatureCollection, `tilesets` must read it all into memory to split it up into separate features before uploading it to the Tilesets API. You are strongly encouraged to provide your data in line-delimited GeoJSON format instead, especially if it is large.
70+
6971
Flags:
7072

7173
* `--no-validation` [optional]: do not validate source data locally before uploading
@@ -76,26 +78,28 @@ Usage
7678

7779
```shell
7880
# single file
79-
tilesets upload-source <username> <id> ./file.geojson
81+
tilesets upload-source <username> <source_id> ./file.geojson
8082

8183
# multiple files
82-
tilesets upload-source <username> <id> file-1.geojson file-4.geojson
84+
tilesets upload-source <username> <source_id> file-1.geojson file-4.geojson
8385

8486
# directory of files
8587
# Reading from a directory will not distinguish between GeoJSON files and non GeoJSON files. All source files will be run through our validator unless you pass the `--no-validation` flag.
86-
tilesets upload-source <username> <id> ./path/to/multiple/files/
88+
tilesets upload-source <username> <source_id> ./path/to/multiple/files/
8789
```
8890

8991
### *deprecated* add-source
9092

9193
*WARNING: add-source is maintained for legacy purposes. Please use the `upload-source` command instead.*
9294

9395
```shell
94-
tilesets add-source <username> <id> <file>
96+
tilesets add-source <username> <source_id> <file>
9597
```
9698

9799
Adds GeoJSON files to a source for tiling. Accepts line-delimited GeoJSON or GeoJSON feature collections as files or via `stdin`. The CLI automatically converts data to line-delimited GeoJSON prior to uploading.
98100

101+
Please note that if your source data is a FeatureCollection, `tilesets` must read it all into memory to split it up into separate features before uploading it to the Tilesets API. You are strongly encouraged to provide your data in line-delimited GeoJSON format instead, especially if it is large.
102+
99103
Flags:
100104

101105
* `--no-validation` [optional]: do not validate source data locally before uploading
@@ -105,14 +109,14 @@ Usage
105109

106110
```shell
107111
# single file
108-
tilesets add-source <username> <id> ./file.geojson
112+
tilesets add-source <username> <source_id> ./file.geojson
109113

110114
# multiple files
111-
tilesets add-source <username> <id> file-1.geojson file-4.geojson
115+
tilesets add-source <username> <source_id> file-1.geojson file-4.geojson
112116

113117
# directory of files
114118
# Reading from a directory will not distinguish between GeoJSON files and non GeoJSON files. All source files will be run through our validator unless you pass the `--no-validation` flag.
115-
tilesets add-source <username> <id> ./path/to/multiple/files/
119+
tilesets add-source <username> <source_id> ./path/to/multiple/files/
116120
```
117121

118122
### validate-source
@@ -130,7 +134,7 @@ Invalid line delimited geojson.
130134
### view-source
131135

132136
```
133-
tilesets view-source <username> <id>
137+
tilesets view-source <username> <source_id>
134138
```
135139

136140
Get information for a tileset source, such as number of files, the size in bytes, and the ID in mapbox:// protocol format.
@@ -146,11 +150,22 @@ List all tileset sources from a particular account. Response is an array of sour
146150
### delete-source
147151

148152
```
149-
tilesets delete-source
153+
tilesets delete-source <username> <source_id>
150154
```
151155

152156
Permanently delete a tileset source and all of its files. This is not a recoverable action!
153157

158+
Flags:
159+
160+
* `-f` or `--force`: Do not ask for confirmation before deleting
161+
162+
Usage
163+
164+
```shell
165+
# to delete mapbox://tileset-source/user/source_id
166+
tilesets delete-source user source_id
167+
```
168+
154169
### estimate-area
155170

156171
```shell

codecov.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ codecov:
66
notify:
77
require_ci_to_pass: yes
88

9-
coverage:
10-
status:
11-
project:
12-
threshold: 3%
13-
base: auto
9+
coverage:
10+
status:
11+
project:
12+
default:
13+
threshold: 3%
14+
base: auto

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.5.2"
3+
__version__ = "1.7.1"

mapbox_tilesets/scripts/cli.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,19 @@ def publish(tileset, token=None, indent=None):
119119
)
120120
r = s.post(url)
121121
if r.status_code == 200:
122-
click.echo(json.dumps(r.json(), indent=indent))
122+
response_msg = r.json()
123+
click.echo(json.dumps(response_msg, indent=indent))
124+
125+
studio_url = click.style(
126+
f"https://studio.mapbox.com/tilesets/{tileset}", bold=True
127+
)
128+
job_id = response_msg["jobId"]
129+
job_cmd = click.style(f"tilesets job {tileset} {job_id}", bold=True)
130+
message = f"\n✔ Tileset job received. Visit {studio_url} or run {job_cmd} to view the status of your tileset."
131+
# print(message)
123132
click.echo(
124-
f"You can view the status of your tileset with the `tilesets status {tileset}` command.",
125-
err=True,
133+
message,
134+
err=True, # print to stderr so the JSON output can be parsed separately from the success message
126135
)
127136
else:
128137
raise errors.TilesetsError(r.text)
@@ -388,7 +397,7 @@ def list(
388397
If you would like an array of all tileset's information,
389398
use the --versbose flag.
390399
391-
tilests list <username>
400+
tilesets list <username>
392401
"""
393402
mapbox_api = utils._get_api()
394403
mapbox_token = utils._get_token(token)
@@ -525,7 +534,7 @@ def _upload_source(
525534
):
526535
"""Create/add a tileset source
527536
528-
tilesets add-source <username> <id> <path/to/source/data>
537+
tilesets add-source <username> <source_id> <path/to/source/data>
529538
"""
530539
mapbox_api = utils._get_api()
531540
mapbox_token = utils._get_token(token)
@@ -620,7 +629,7 @@ def add_source(
620629
):
621630
"""Create/add/replace a tileset source
622631
623-
tilesets add-source <username> <id> <path/to/source/data>
632+
tilesets add-source <username> <source_id> <path/to/source/data>
624633
"""
625634
return _upload_source(
626635
ctx, username, id, features, no_validation, quiet, False, token, indent
@@ -635,7 +644,7 @@ def add_source(
635644
def view_source(username, id, token=None, indent=None):
636645
"""View a Tileset Source's information
637646
638-
tilesets view-source <username> <id>
647+
tilesets view-source <username> <source_id>
639648
"""
640649
mapbox_api = utils._get_api()
641650
mapbox_token = utils._get_token(token)
@@ -658,7 +667,7 @@ def view_source(username, id, token=None, indent=None):
658667
def delete_source(username, id, force, token=None):
659668
"""Delete a Tileset Source + all of its files.
660669
661-
tilesets delete-source <username> <id>
670+
tilesets delete-source <username> <source_id>
662671
"""
663672
if not force:
664673
val = click.prompt(
@@ -707,6 +716,12 @@ def list_sources(username, token=None):
707716
raise errors.TilesetsError(r.text)
708717

709718

719+
def validate_stream(features):
720+
for feature in features:
721+
utils.validate_geojson(feature)
722+
yield feature
723+
724+
710725
@cli.command("estimate-area")
711726
@cligj.features_in_arg
712727
@click.option(
@@ -745,23 +760,20 @@ def estimate_area(features, precision, no_validation=False, force_1cm=False):
745760
"The --force-1cm flag is enabled but the precision is not 1cm."
746761
)
747762

748-
# builtins.list because there is a list command in the cli & will thrown an error
749763
try:
764+
# expect users to bypass source validation when users rerun command and their features passed validation previously
765+
if not no_validation:
766+
features = validate_stream(features)
767+
# builtins.list because there is a list command in the cli & will thrown an error
768+
# It is a list at all because calculate_tiles_area does not work with a stream
750769
features = builtins.list(filter_features(features))
751770
except (ValueError, json.decoder.JSONDecodeError):
752771
raise errors.TilesetsError(
753772
"Error with feature parsing. Ensure that feature inputs are valid and formatted correctly. Try 'tilesets estimate-area --help' for help."
754773
)
755-
except Exception:
756-
raise errors.TilesetsError("Error with feature filtering.")
757-
758-
# expect users to bypass source validation when users rerun command and their features passed validation previously
759-
if not no_validation:
760-
for feature in features:
761-
utils.validate_geojson(feature)
762774

763775
area = utils.calculate_tiles_area(features, precision)
764-
area = str(round(area))
776+
area = str(int(round(area)))
765777

766778
click.echo(
767779
json.dumps(

package-lock.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ def read(fname):
4141
zip_safe=False,
4242
extras_require={
4343
"test": [
44+
"codecov",
4445
"pytest==4.6.11",
4546
"pytest-cov",
4647
"pre-commit",
47-
"black",
48+
"black==20.8b1",
4849
"pep8",
49-
"codecov",
50+
"toml==0.10.2",
5051
]
5152
},
5253
entry_points="""

tests/fixtures/twostates.ldgeojson

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.

tests/test_cli_estimate_area.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ def test_cli_estimate_area_valid_features_files_and_valid_feature_input():
102102
assert validated_result.output == output
103103

104104

105+
def test_cli_estimate_area_large_valid_features_files_and_valid_feature_input():
106+
output = '{"km2": "1390828", "precision": "10m", "pricing_docs": "For more information, visit https://www.mapbox.com/pricing/#tilesets"}\n'
107+
runner = CliRunner()
108+
validated_result = runner.invoke(
109+
estimate_area,
110+
["tests/fixtures/twostates.ldgeojson", "-p", "10m"],
111+
)
112+
assert validated_result.exit_code == 0
113+
assert validated_result.output == output
114+
115+
116+
def test_cli_estimate_area_large_valid_features_files_and_valid_feature_input_no_validation():
117+
output = '{"km2": "1390828", "precision": "10m", "pricing_docs": "For more information, visit https://www.mapbox.com/pricing/#tilesets"}\n'
118+
runner = CliRunner()
119+
validated_result = runner.invoke(
120+
estimate_area,
121+
["tests/fixtures/twostates.ldgeojson", "-p", "10m", "--no-validation"],
122+
)
123+
assert validated_result.exit_code == 0
124+
assert validated_result.output == output
125+
126+
105127
def test_cli_estimate_area_valid_features_files_and_1cm_precision():
106128
output = '{"km2": "0", "precision": "1cm", "pricing_docs": "For more information, visit https://www.mapbox.com/pricing/#tilesets"}\n'
107129
runner = CliRunner()

0 commit comments

Comments
 (0)