Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce stable aws endpoint for cartopy_feature_download.py #1837

Merged
merged 2 commits into from
Sep 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions tools/cartopy_feature_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@

For detail on how to use this tool, execute it with the `-h` option:

python download.py -h
python cartopy_feature_download.py -h

"""

import argparse
import pathlib

from cartopy import config
from cartopy.feature import Feature, GSHHSFeature, NaturalEarthFeature
from cartopy.io import Downloader
from cartopy.io import Downloader, DownloadWarning


ALL_SCALES = ('110m', '50m', '10m')

# See https://github.com/SciTools/cartopy/pull/1833
URL_TEMPLATE = ('https://naturalearth.s3.amazonaws.com/{resolution}_'
'{category}/ne_{resolution}_{name}.zip')
SHP_NE_SPEC = ('shapefiles', 'natural_earth')

FEATURE_DEFN_GROUPS = {
# Only need one GSHHS resolution because they *all* get downloaded
Expand Down Expand Up @@ -114,11 +119,28 @@ def download_features(group_names, dry_run=True):
action='store_true')
parser.add_argument('--ignore-repo-data', action='store_true',
help='ignore existing repo data when downloading')
parser.add_argument('--no-warn',
action='store_true',
help='ignore cartopy "DownloadWarning" warnings')
args = parser.parse_args()

if args.output:
config['pre_existing_data_dir'] = args.output
config['data_dir'] = args.output
target_dir = pathlib.Path(args.output).expanduser().resolve()
target_dir.mkdir(parents=True, exist_ok=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exist_ok flag was added in Python 3.5, so I assume it's okay to use here...surely 😜

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you'll just get an error if you want to try with an earlier Python version ;)

config['pre_existing_data_dir'] = target_dir
config['data_dir'] = target_dir
if args.ignore_repo_data:
config['repo_data_dir'] = config['data_dir']
if args.no_warn:
import warnings
warnings.filterwarnings('ignore', category=DownloadWarning)

# Enforce use of stable AWS endpoint, regardless of cartopy version.
# In doing so, this allows users to download this script and execute it
# with any version of cartopy, thus taking advantage of the stable AWS
# endpoint.
# This removes the need to backport the associated fix
# https://github.com/SciTools/cartopy/pull/1833.
config['downloaders'][SHP_NE_SPEC].url_template = URL_TEMPLATE

download_features(args.group_names, dry_run=args.dry_run)