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

Fix mypy error from urllib.Retry kwargs #858

Merged
merged 4 commits into from
Jan 19, 2022
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 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