Skip to content

Commit

Permalink
CI: Manually download Cartopy maps
Browse files Browse the repository at this point in the history
This works around Cartopy <=0.19 on PyPI using an outdate URL for the
Natural Earth data. Instead of worrying about caching, just download
directly from S3 using Cartopy's own download code.
  • Loading branch information
dopplershift committed Sep 13, 2021
1 parent ff0a5a5 commit fc31528
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ jobs:
python -m pip install -c ci/${{ matrix.dep-versions }} numpy
python -m pip install -r ci/doc_requirements.txt -r ci/extra_requirements.txt -c ci/${{ matrix.dep-versions }}
- name: Download Cartopy Maps
run: ci/download_cartopy_maps.py

- name: Install self
run: python -m pip install -c ci/${{ matrix.dep-versions }} .

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/tests-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ jobs:
- name: Install test dependencies
run: python -m pip install -r ci/test_requirements.txt -c ci/${{ matrix.dep-versions }}

- name: Download Cartopy Maps
if: ${{ matrix.no-extras != 'No Extras' }}
run: ci/download_cartopy_maps.py

- name: Install
run: python -m pip install -c ci/${{ matrix.dep-versions }} .

Expand Down
29 changes: 29 additions & 0 deletions ci/download_cartopy_maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python
# Copyright (c) 2021 MetPy Developers.
"""Explicitly download needed Cartopy maps."""
from cartopy.io import config, Downloader

AWS_TEMPLATE = ('https://naturalearth.s3.amazonaws.com/{resolution}_'
'{category}/ne_{resolution}_{name}.zip')


def grab_ne(category, feature, res):
"""Download the correct Natural Earth feature using Cartopy."""
download = Downloader.from_config(('shapefiles', 'natural_earth'))
download.path({'category': category, 'name': feature, 'resolution': res, 'config': config})


if __name__ == '__main__':
# Need to override the pre-Cartopy 0.20 URL to use S3
config['downloaders'][('shapefiles', 'natural_earth')].url_template = AWS_TEMPLATE

for feat in ['admin_0_boundary_lines_land', 'admin_1_states_provinces_lakes']:
for r in ['110m', '50m', '10m']:
grab_ne('cultural', feat, r)

for feat, r in [('coastline', '10m'), ('coastline', '50m'), ('coastline', '110m'),
('lakes', '10m'), ('lakes', '50m'),
('land', '10m'), ('land', '50m'), ('land', '110m'),
('ocean', '110m'), ('ocean', '50m'),
('rivers_lake_centerlines', '10m'), ('rivers_lake_centerlines', '110m')]:
grab_ne('physical', feat, r)

0 comments on commit fc31528

Please sign in to comment.