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

Rely on importlib_metadata 3.6 for nicer protocol. #732

Merged
merged 3 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog/732.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rely on importlib_metadata 3.6 for nicer entry point processing.
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ strict_equality = True
ignore_missing_imports = True

[mypy-importlib_metadata]
; https://gitlab.com/python-devs/importlib_metadata/-/issues/10
; https://github.com/python/importlib_metadata/issues/10
ignore_missing_imports = True

[mypy-keyring]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions twine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@

__copyright__ = "Copyright 2019 Donald Stufft and individual contributors"

import sys

if sys.version_info[:2] >= (3, 8):
from importlib import metadata as importlib_metadata
else:
# Using `as` to workaround "implicit reexport disabled"
# https://mypy.readthedocs.io/en/stable/config_file.html#confval-implicit_reexport
import importlib_metadata as importlib_metadata

import importlib_metadata

metadata = importlib_metadata.metadata("twine")

Expand Down
16 changes: 4 additions & 12 deletions twine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,21 @@
# 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 pkginfo
import requests
import requests_toolbelt
import setuptools
import tqdm
from importlib_metadata import entry_points

import twine
from twine import _installed
from twine import importlib_metadata
jaraco marked this conversation as resolved.
Show resolved Hide resolved

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),
Expand All @@ -52,7 +44,7 @@ def dep_versions() -> str:


def dispatch(argv: List[str]) -> Any:
registered_commands = _registered_commands()
registered_commands = entry_points(group="twine.registered_commands")
parser = argparse.ArgumentParser(prog="twine")
parser.add_argument(
"--version",
Expand All @@ -68,7 +60,7 @@ def dispatch(argv: List[str]) -> Any:
)
parser.add_argument(
"command",
choices=registered_commands.keys(),
choices=registered_commands.names,
)
parser.add_argument(
"args",
Expand Down