From ee63c58dde23c7edc5b752a6eb6300aaa0c21335 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 24 Feb 2021 16:09:29 -0500 Subject: [PATCH] Rely on importlib_metadata 3.6 for nicer protocol. --- changelog/732.feature.rst | 1 + setup.cfg | 2 +- twine/cli.py | 17 +++++------------ 3 files changed, 7 insertions(+), 13 deletions(-) create mode 100644 changelog/732.feature.rst diff --git a/changelog/732.feature.rst b/changelog/732.feature.rst new file mode 100644 index 00000000..57eefc48 --- /dev/null +++ b/changelog/732.feature.rst @@ -0,0 +1 @@ +Rely on importlib_metadata 3.6 for nicer entry point processing. diff --git a/setup.cfg b/setup.cfg index fe95e81d..f47de473 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ install_requires= requests-toolbelt >= 0.8.0, != 0.9.0 setuptools >= 0.7.0 tqdm >= 4.14 - importlib_metadata; python_version < "3.8" + importlib_metadata >= 3.6 keyring >= 15.1 rfc3986 >= 1.4.0 colorama >= 0.4.3 diff --git a/twine/cli.py b/twine/cli.py index 5bd57c56..65864bc2 100644 --- a/twine/cli.py +++ b/twine/cli.py @@ -12,8 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. import argparse -from typing import Any, Dict, List, Tuple +from typing import Any, List, Tuple +import importlib_metadata import pkginfo import requests import requests_toolbelt @@ -22,19 +23,10 @@ import twine from twine import _installed -from twine import importlib_metadata args = argparse.Namespace() -def _registered_commands( - group: str = "twine.registered_commands", -) -> Dict[str, importlib_metadata.EntryPoint]: - # todo: with python/importlib_metadata#278: - # return importlib_metadata.entry_points()[group] - return {ep.name: ep for ep in importlib_metadata.entry_points()[group]} - - def list_dependencies_and_versions() -> List[Tuple[str, str]]: return [ ("pkginfo", _installed.Installed(pkginfo).version), @@ -52,7 +44,8 @@ def dep_versions() -> str: def dispatch(argv: List[str]) -> Any: - registered_commands = _registered_commands() + registered_commands = importlib_metadata.entry_points( + group='twine.registered_commands') parser = argparse.ArgumentParser(prog="twine") parser.add_argument( "--version", @@ -68,7 +61,7 @@ def dispatch(argv: List[str]) -> Any: ) parser.add_argument( "command", - choices=registered_commands.keys(), + choices=registered_commands.names, ) parser.add_argument( "args",