From 30b41355637fb4afd9ae2c87c316e9062db343cc Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Sat, 7 Oct 2023 08:21:39 -0600 Subject: [PATCH] MNT: Move cartopy feature download script into the package Move it from the tools directory into the feature module and make it an executable module by calling it __main__.py It can be invoked with `python -m cartopy.feature.download` now. --- .github/workflows/ci-testing.yml | 4 +++- .../cartopy/feature/download/__main__.py | 8 ++++++-- pyproject.toml | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) rename tools/cartopy_feature_download.py => lib/cartopy/feature/download/__main__.py (98%) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 82140eae6..64537cd63 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -72,7 +72,9 @@ jobs: shell: bash run: | # Check that the downloader tool at least knows where to get the data from (but don't actually download it) - python tools/cartopy_feature_download.py gshhs physical --dry-run + python -m cartopy.feature.download gshhs physical --dry-run + # It should also be available as a script + cartopy_feature_download gshhs physical --dry-run CARTOPY_GIT_DIR=$PWD pytest -ra -n 4 \ --color=yes \ diff --git a/tools/cartopy_feature_download.py b/lib/cartopy/feature/download/__main__.py similarity index 98% rename from tools/cartopy_feature_download.py rename to lib/cartopy/feature/download/__main__.py index ffa8f702a..977cc085f 100755 --- a/tools/cartopy_feature_download.py +++ b/lib/cartopy/feature/download/__main__.py @@ -10,7 +10,7 @@ For detail on how to use this tool, execute it with the `-h` option: - python cartopy_feature_download.py -h + python -m cartopy.feature.download -h """ @@ -107,7 +107,7 @@ def download_features(group_names, dry_run=True): ''.format(category, name, scale, len(geoms))) -if __name__ == '__main__': +def main(): parser = argparse.ArgumentParser(description='Download feature datasets.') parser.add_argument('group_names', nargs='+', choices=FEATURE_DEFN_GROUPS, @@ -146,3 +146,7 @@ def download_features(group_names, dry_run=True): config['downloaders'][SHP_NE_SPEC].url_template = URL_TEMPLATE download_features(args.group_names, dry_run=args.dry_run) + + +if __name__ == '__main__': + main() diff --git a/pyproject.toml b/pyproject.toml index f2ffe48af..99b3011d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ plotting = ["pillow>=6.1.0", "scipy>=1.3.1"] test = ["pytest>=5.1.2", "pytest-mpl>=0.11", "pytest-xdist", "pytest-cov", "coveralls"] [project.scripts] -feature_download = "tools.cartopy_feature_download.py:__main__" +cartopy_feature_download = "cartopy.feature.download.__main__:main" [project.urls] documentation='https://scitools.org.uk/cartopy/docs/latest/'