Skip to content

Commit

Permalink
Fixup auth (#542)
Browse files Browse the repository at this point in the history
* Make CredentialInput a class

* Add missing type annotation

* Ignore new build directory
  • Loading branch information
bhrutledge authored and sigmavirus24 committed Nov 18, 2019
1 parent e7ef3e1 commit b59256e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ wheels/
.installed.cfg
*.egg
MANIFEST
pip-wheel-metadata/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)


cred = auth.CredentialInput.new
cred = auth.CredentialInput


@pytest.fixture
Expand Down
15 changes: 6 additions & 9 deletions twine/auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import warnings
import getpass
import functools
import typing
from typing import Optional, Callable

import keyring
Expand All @@ -10,13 +9,11 @@
from . import exceptions


class CredentialInput(typing.NamedTuple):
username: typing.Optional[str]
password: typing.Optional[str]
class CredentialInput:

@classmethod
def new(cls, username=None, password=None):
return cls(username, password)
def __init__(self, username: str = None, password: str = None):
self.username = username
self.password = password


class Resolver:
Expand Down Expand Up @@ -52,7 +49,7 @@ def password(self) -> Optional[str]:
def system(self) -> Optional[str]:
return self.config['repository']

def get_username_from_keyring(self):
def get_username_from_keyring(self) -> Optional[str]:
try:
creds = keyring.get_credential(self.system, None)
if creds:
Expand All @@ -62,13 +59,13 @@ def get_username_from_keyring(self):
pass
except Exception as exc:
warnings.warn(str(exc))
return None # TODO: mypy shouldn't require this

def get_password_from_keyring(self) -> Optional[str]:
try:
return keyring.get_password(self.system, self.username)
except Exception as exc:
warnings.warn(str(exc))
return None # TODO: mypy shouldn't require this
return None # any more than it should require this

def username_from_keyring_or_prompt(self) -> str:
Expand Down

0 comments on commit b59256e

Please sign in to comment.