Skip to content

Extract auth options resolver #537

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

Merged
merged 11 commits into from
Nov 17, 2019
Merged

Extract auth options resolver #537

merged 11 commits into from
Nov 17, 2019

Conversation

jaraco
Copy link
Member

@jaraco jaraco commented Nov 16, 2019

In #489, I raised a concern:

The implementation as proposed weaves a boolean variable through several function calls. I'll want to first identify a refactoring that limits the number of code blocks that this one option touches.

This pull request implements that refactoring. As you can see, the 'non_interactive' boolean parameter now is passed into one function and causes its effect there. This change uses many fewer lines to enact the same work and in many ways provides a cleaner abstraction around authentication handling.

Unfortunately, although the tests pass against the commit where I made the change, when I tried to merge that change with the static typing code, it now deadlocks in the tests. I'll take another look at this at some point.

Edit: my first attempt at this refactoring is at d7ff2c8

Copy link
Contributor

@bhrutledge bhrutledge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this direction. Here's some initial feedback and suggestions. Also, when I run the tests, I get prompted for a password:

$ tox -e py37
...
py37 run-test: commands[0] | coverage run --source twine -m pytest tests
============================= test session starts ==============================
platform darwin -- Python 3.7.3, pytest-5.2.4, py-1.8.0, pluggy-0.13.0
cachedir: .tox/py37/.pytest_cache
rootdir: /Users/brian/Code/twine, inifile: pytest.ini
plugins: services-2.0.1
collected 104 items

tests/test_auth.py Enter your password:

@jaraco
Copy link
Member Author

jaraco commented Nov 17, 2019

Also, when I run the tests, I get prompted for a password:

That's the weird thing. I'm seeing that too (what I previously characterized as a deadlock), but only after merging with the latest master, and only sometimes does the prompt appear (other times, the text from the prompt is missing, but it still blocks).

@jaraco
Copy link
Member Author

jaraco commented Nov 17, 2019

Also, when I run the tests, I get prompted for a password:

That's the weird thing. I'm seeing that too...

And in f50efaa, I've corrected the issue. What's really strange and I still don't understand is why were the tests passing on earlier commits, before the typing adjustments.

…ettings' object. This change requires the Resolver to be aware of internal details on the object, but simplifies the interface and interactions with Settings objects.
@jaraco jaraco merged commit 0fb2f51 into master Nov 17, 2019
@jaraco jaraco deleted the refactor/auth-options branch November 17, 2019 22:03
Copy link
Contributor

@bhrutledge bhrutledge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for considering and responding to all my feedback. Happy to see this merged. I've got a few more questions/ideas that, as you suggested could be addressed in the future.

Comment on lines +133 to +136
self.auth = auth.Resolver.choose(not non_interactive)(
self.repository_config,
auth.CredentialInput(username, password),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I like this.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there two returns here? I'm surprised this passed linting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's me being a little pedantic in reaction to mypy being unnecessarily pedantic. Mypy requires the first return None, which in my mind is redundant lint. I learned over 20 years ago that a Python function that reaches the end of the block without returning anything has an implicit return None, but now mypy is violating that language construct by requiring an explicit return.

def system(self) -> Optional[str]:
return self.config['repository']

def get_username_from_keyring(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could still use type annotations.

@bhrutledge bhrutledge mentioned this pull request Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants