Repository: SciTools/cartopy

Issue:
Don't use generic feature_download executable name
### Description

Since 0.22.0 `tools/cartopy_feature_download.py` gets installed as `/usr/bin/feature_download` which is a far too generic name.

The `cartopy_` prefix should be preserved as per this patch:
```diff
Description: Don't use generic feature_download executable name.
Author: Bas Couwenberg <sebastic@debian.org>

--- a/pyproject.toml
+++ b/pyproject.toml
@@ -56,7 +56,7 @@ plotting = ["pillow>=6.1.0", "scipy>=1.3
 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 = "tools.cartopy_feature_download.py:__main__"
 
 [project.urls]
 documentation='https://scitools.org.uk/cartopy/docs/latest/'
```

### Operating system

Debian unstable

### Cartopy version

0.22.0

</details>



Discussion:
I agree this is not super ideal. More generally, I wonder if we even want to install "cartopy_feature_download" as a script like this at all because I don't think it rises to the level of needing to be site-wide available as a script. Maybe we could move it into a function within the package somehow instead. Any other thoughts on this from anyone?
An option would be to have it as code in a `__main__` in an appropriate module, so you could run it like `python -m cartopy.feature` ?
I think it used to be installed as `cartopy_feature_download.py`, so this rename was accidental.
> I think it used to be installed as `cartopy_feature_download.py`, so this rename was accidental.

It was, and installing it without the language extension is better.
I think the current installation is actually broken? So a simple name change won't fix the underlying issue. It looks like setuptools expects scripts to be a part of the package, but we have put the script in a separate directory without an `__init__.py` so the tools directory isn't a module.

```bash
cartopy_feature_download gshhs physical --dry-run

/usr/bin/cartopy_feature_download", line 5, in <module>
    from tools.cartopy_feature_download.py import __main__
ModuleNotFoundError: No module named 'tools'
```

Note: we should switch CI to test the installed script instead of the direct path that we currently do with the dry-run if we do go this route to make sure we codify the expectation of how the script works.
Oh, that's a good catch; probably should move to `cartopy.feature` somewhere as @dopplershift suggested.

Resolving patch:
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
--- 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()


Test patch: