Skip to content

Commit

Permalink
Fix mypy error from urllib.Retry kwargs (pypa#858)
Browse files Browse the repository at this point in the history
* Silence mypy kwargs error

* Require recent version of urllib3

* Add packages to --version

* Show version for all requirements
  • Loading branch information
bhrutledge committed Jan 23, 2022
1 parent 858e6b8 commit 6c5d0ea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ install_requires=
readme_renderer >= 21.0
requests >= 2.20
requests-toolbelt >= 0.8.0, != 0.9.0
urllib3 >= 1.26.0
tqdm >= 4.14
importlib_metadata >= 3.6
keyring >= 15.1
Expand Down
19 changes: 8 additions & 11 deletions twine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@
import argparse
from typing import Any, List, Tuple

from importlib_metadata import entry_points
from importlib_metadata import version
import importlib_metadata
from packaging import requirements

import twine

args = argparse.Namespace()


def list_dependencies_and_versions() -> List[Tuple[str, str]]:
deps = (
"importlib_metadata",
"pkginfo",
"requests",
"requests-toolbelt",
"tqdm",
)
return [(dep, version(dep)) for dep in deps] # type: ignore[no-untyped-call] # python/importlib_metadata#288 # noqa: E501
requires = importlib_metadata.requires("twine") # type: ignore[no-untyped-call] # python/importlib_metadata#288 # noqa: E501
deps = [requirements.Requirement(r).name for r in requires]
return [(dep, importlib_metadata.version(dep)) for dep in deps] # type: ignore[no-untyped-call] # python/importlib_metadata#288 # noqa: E501


def dep_versions() -> str:
Expand All @@ -40,7 +35,9 @@ def dep_versions() -> str:


def dispatch(argv: List[str]) -> Any:
registered_commands = entry_points(group="twine.registered_commands")
registered_commands = importlib_metadata.entry_points(
group="twine.registered_commands"
)
parser = argparse.ArgumentParser(prog="twine")
parser.add_argument(
"--version",
Expand Down
10 changes: 2 additions & 8 deletions twine/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,13 @@ def __init__(

@staticmethod
def _make_adapter_with_retries() -> adapters.HTTPAdapter:
retry_kwargs = dict(
retry = urllib3.Retry(
allowed_methods=["GET"],
connect=5,
total=10,
status_forcelist=[500, 501, 502, 503],
)

try:
retry = urllib3.Retry(allowed_methods=["GET"], **retry_kwargs)
except TypeError: # pragma: no cover
# Avoiding DeprecationWarning starting in urllib3 1.26
# Remove when that's the mininum version
retry = urllib3.Retry(method_whitelist=["GET"], **retry_kwargs)

return adapters.HTTPAdapter(max_retries=retry)

@staticmethod
Expand Down

0 comments on commit 6c5d0ea

Please sign in to comment.