Skip to content

Commit

Permalink
Update formatters (#690)
Browse files Browse the repository at this point in the history
* Update black formatting

* Update isort configuration
  • Loading branch information
bhrutledge committed Aug 27, 2020
1 parent 88b87fe commit b5fa957
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 73 deletions.
8 changes: 2 additions & 6 deletions .isort.cfg
@@ -1,10 +1,6 @@
[settings]
# NOTE: Consider single_line_exclusions=typing in next version of isort
profile=black
force_single_line=True
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
single_line_exclusions=typing
default_section=THIRDPARTY
known_first_party=twine,helpers
3 changes: 2 additions & 1 deletion tests/test_check.py
Expand Up @@ -25,7 +25,8 @@ class TestWarningStream:
def setup(self):
self.stream = check._WarningStream()
self.stream.output = pretend.stub(
write=pretend.call_recorder(lambda a: None), getvalue=lambda: "result",
write=pretend.call_recorder(lambda a: None),
getvalue=lambda: "result",
)

def test_write_match(self):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_register.py
Expand Up @@ -49,7 +49,9 @@ def test_exception_for_redirect(register_settings):
redirect_url = "https://malicious.website.org/danger"

stub_response = pretend.stub(
is_redirect=True, status_code=301, headers={"location": redirect_url},
is_redirect=True,
status_code=301,
headers={"location": redirect_url},
)

stub_repository = pretend.stub(
Expand Down
16 changes: 12 additions & 4 deletions tests/test_repository.py
Expand Up @@ -127,7 +127,9 @@ def test_package_is_uploaded_with_releases_using_cache(default_repo):
"""Return True when the package is in the releases cache."""
default_repo._releases_json_data = {"fake": {"0.1": [{"filename": "fake.whl"}]}}
package = pretend.stub(
safe_name="fake", basefilename="fake.whl", metadata=pretend.stub(version="0.1"),
safe_name="fake",
basefilename="fake.whl",
metadata=pretend.stub(version="0.1"),
)

assert default_repo.package_is_uploaded(package) is True
Expand All @@ -143,7 +145,9 @@ def test_package_is_uploaded_with_releases_not_using_cache(default_repo):
),
)
package = pretend.stub(
safe_name="fake", basefilename="fake.whl", metadata=pretend.stub(version="0.1"),
safe_name="fake",
basefilename="fake.whl",
metadata=pretend.stub(version="0.1"),
)

assert default_repo.package_is_uploaded(package, bypass_cache=True) is True
Expand All @@ -159,7 +163,9 @@ def test_package_is_uploaded_different_filenames(default_repo):
),
)
package = pretend.stub(
safe_name="fake", basefilename="foo.whl", metadata=pretend.stub(version="0.1"),
safe_name="fake",
basefilename="foo.whl",
metadata=pretend.stub(version="0.1"),
)

assert default_repo.package_is_uploaded(package) is False
Expand Down Expand Up @@ -313,7 +319,9 @@ def test_release_urls(package_meta, repository_url, release_urls):
]

repo = repository.Repository(
repository_url=repository_url, username="username", password="password",
repository_url=repository_url,
username="username",
password="password",
)

assert repo.release_urls(packages) == release_urls
Expand Down
3 changes: 2 additions & 1 deletion tests/test_settings.py
Expand Up @@ -69,7 +69,8 @@ def test_setup_logging(verbose, log_level):


@pytest.mark.parametrize(
"verbose", [True, False],
"verbose",
[True, False],
)
def test_print_config_path_if_verbose(tmpdir, capsys, make_settings, verbose):
"""Print the location of the .pypirc config used by the user."""
Expand Down
14 changes: 10 additions & 4 deletions tests/test_utils.py
Expand Up @@ -196,7 +196,8 @@ def test_get_repository_config_with_invalid_url(tmpdir, repo_url, message):
pypirc = os.path.join(str(tmpdir), ".pypirc")

with pytest.raises(
exceptions.UnreachableRepositoryURLDetected, match=message,
exceptions.UnreachableRepositoryURLDetected,
match=message,
):
utils.get_repository_from_config(pypirc, "pypi", repo_url)

Expand Down Expand Up @@ -253,7 +254,10 @@ def test_default_to_environment_action(env_name, default, environ, expected):
dest = "example"
with helpers.set_env(**environ):
action = utils.EnvironmentDefault(
env=env_name, default=default, option_strings=option_strings, dest=dest,
env=env_name,
default=default,
option_strings=option_strings,
dest=dest,
)
assert action.env == env_name
assert action.default == expected
Expand All @@ -271,10 +275,12 @@ def test_check_status_code_for_deprecated_pypi_url(repo_url):


@pytest.mark.parametrize(
"repo_url", ["https://pypi.python.org", "https://testpypi.python.org"],
"repo_url",
["https://pypi.python.org", "https://testpypi.python.org"],
)
@pytest.mark.parametrize(
"verbose", [True, False],
"verbose",
[True, False],
)
def test_check_status_code_for_missing_status_code(
capsys, repo_url, verbose, make_settings
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Expand Up @@ -45,7 +45,7 @@ deps =
isort
black
commands =
isort --recursive twine/ tests/
isort twine/ tests/
black twine/ tests/

[testenv:lint]
Expand All @@ -55,7 +55,7 @@ deps =
flake8
flake8-docstrings
commands =
isort --check-only --diff --recursive twine/ tests/
isort --check-only --diff twine/ tests/
black --check --diff twine/ tests/
flake8 twine/ tests/

Expand Down
5 changes: 1 addition & 4 deletions twine/auth.py
@@ -1,10 +1,7 @@
import functools
import getpass
import warnings
from typing import Callable
from typing import Optional
from typing import Type
from typing import cast
from typing import Callable, Optional, Type, cast

import keyring

Expand Down
12 changes: 6 additions & 6 deletions twine/cli.py
Expand Up @@ -12,10 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
from typing import Any
from typing import Dict
from typing import List
from typing import Tuple
from typing import Any, Dict, List, Tuple

import pkg_resources
import pkginfo
Expand Down Expand Up @@ -69,10 +66,13 @@ def dispatch(argv: List[str]) -> Any:
help="disable colored output",
)
parser.add_argument(
"command", choices=registered_commands.keys(),
"command",
choices=registered_commands.keys(),
)
parser.add_argument(
"args", help=argparse.SUPPRESS, nargs=argparse.REMAINDER,
"args",
help=argparse.SUPPRESS,
nargs=argparse.REMAINDER,
)

parser.parse_args(argv, namespace=args)
Expand Down
6 changes: 1 addition & 5 deletions twine/commands/check.py
Expand Up @@ -17,11 +17,7 @@
import re
import sys
import textwrap
from typing import IO
from typing import List
from typing import Optional
from typing import Tuple
from typing import cast
from typing import IO, List, Optional, Tuple, cast

import readme_renderer.rst

Expand Down
6 changes: 3 additions & 3 deletions twine/commands/register.py
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.
import argparse
import os.path
from typing import List
from typing import cast
from typing import List, cast

from twine import exceptions
from twine import package as package_file
Expand All @@ -38,7 +37,8 @@ def register(register_settings: settings.Settings, package: str) -> None:

if resp.is_redirect:
raise exceptions.RedirectDetected.from_args(
repository_url, resp.headers["location"],
repository_url,
resp.headers["location"],
)

resp.raise_for_status()
Expand Down
7 changes: 3 additions & 4 deletions twine/commands/upload.py
Expand Up @@ -14,9 +14,7 @@
import argparse
import logging
import os.path
from typing import Dict
from typing import List
from typing import cast
from typing import Dict, List, cast

import requests

Expand Down Expand Up @@ -111,7 +109,8 @@ def upload(upload_settings: settings.Settings, dists: List[str]) -> None:
# redirects as well.
if resp.is_redirect:
raise exceptions.RedirectDetected.from_args(
repository_url, resp.headers["location"],
repository_url,
resp.headers["location"],
)

if skip_upload(resp, upload_settings.skip_existing, package):
Expand Down
11 changes: 4 additions & 7 deletions twine/package.py
Expand Up @@ -15,12 +15,7 @@
import io
import os
import subprocess
from typing import Dict
from typing import NamedTuple
from typing import Optional
from typing import Sequence
from typing import Tuple
from typing import Union
from typing import Dict, NamedTuple, Optional, Sequence, Tuple, Union

import pkg_resources
import pkginfo
Expand Down Expand Up @@ -265,5 +260,7 @@ def hash(self) -> None:
def hexdigest(self) -> Hexdigest:
"""Return the hexdigest for the file."""
return Hexdigest(
self._md5_hexdigest(), self._sha2_hexdigest(), self._blake_hexdigest(),
self._md5_hexdigest(),
self._sha2_hexdigest(),
self._blake_hexdigest(),
)
8 changes: 1 addition & 7 deletions twine/repository.py
Expand Up @@ -12,13 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Set
from typing import Tuple
from typing import cast
from typing import Any, Dict, List, Optional, Set, Tuple, cast

import requests
import requests_toolbelt
Expand Down
23 changes: 14 additions & 9 deletions twine/settings.py
Expand Up @@ -16,10 +16,7 @@
import contextlib
import logging
import sys
from typing import Any
from typing import ContextManager
from typing import Optional
from typing import cast
from typing import Any, ContextManager, Optional, cast

from twine import auth
from twine import exceptions
Expand Down Expand Up @@ -128,15 +125,19 @@ def __init__(
self.disable_progress_bar = disable_progress_bar
self.skip_existing = skip_existing
self._handle_repository_options(
repository_name=repository_name, repository_url=repository_url,
repository_name=repository_name,
repository_url=repository_url,
)
self._handle_package_signing(
sign=sign, sign_with=sign_with, identity=identity,
sign=sign,
sign_with=sign_with,
identity=identity,
)
# _handle_certificates relies on the parsed repository config
self._handle_certificates(cacert, client_cert)
self.auth = auth.Resolver.choose(not non_interactive)(
self.repository_config, auth.CredentialInput(username, password),
self.repository_config,
auth.CredentialInput(username, password),
)

@property
Expand Down Expand Up @@ -204,7 +205,9 @@ def register_argparse_arguments(parser: argparse.ArgumentParser) -> None:
help="GPG program used to sign uploads (default: %(default)s).",
)
parser.add_argument(
"-i", "--identity", help="GPG identity used to sign files.",
"-i",
"--identity",
help="GPG identity used to sign files.",
)
parser.add_argument(
"-u",
Expand Down Expand Up @@ -306,7 +309,9 @@ def _handle_repository_options(
self, repository_name: str, repository_url: Optional[str]
) -> None:
self.repository_config = utils.get_repository_from_config(
self.config_file, repository_name, repository_url,
self.config_file,
repository_name,
repository_url,
)
self.repository_config["repository"] = utils.normalize_repository_url(
cast(str, self.repository_config["repository"]),
Expand Down
8 changes: 1 addition & 7 deletions twine/utils.py
Expand Up @@ -18,13 +18,7 @@
import logging
import os
import os.path
from typing import Any
from typing import Callable
from typing import DefaultDict
from typing import Dict
from typing import Optional
from typing import Sequence
from typing import Union
from typing import Any, Callable, DefaultDict, Dict, Optional, Sequence, Union
from urllib.parse import urlparse
from urllib.parse import urlunparse

Expand Down
3 changes: 1 addition & 2 deletions twine/wheel.py
Expand Up @@ -15,8 +15,7 @@
import os
import re
import zipfile
from typing import List
from typing import Optional
from typing import List, Optional

from pkginfo import distribution

Expand Down

0 comments on commit b5fa957

Please sign in to comment.