-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Refactor MultiDomainBasicAuth #12934
Open
jfly
wants to merge
2
commits into
pypa:main
Choose a base branch
from
jfly:issue-12750-pre-work-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jfly
force-pushed
the
issue-12750-pre-work-refactor
branch
from
August 24, 2024 07:19
34e2385
to
b23d14f
Compare
I found the original code a little dense. IMO, this refactor makes it a little easier to see what's going on, and more importantly, *why*.
jfly
force-pushed
the
issue-12750-pre-work-refactor
branch
2 times, most recently
from
August 24, 2024 08:07
a19d48d
to
082a173
Compare
I was starting to work on pypa#12750, but got hung up on some strange OOP patterns going on here. In particular, I found it odd that there are 2 different ways we set some knobs (`prompting` and `keyring_provider`) and for instances of `MultiDomainBasicAuth`: 1. In tests, we do it by passing these knobs as constructor parameters to `MultiDomainBasicAuth`. 2. In the real cli codepath, we do it by mutating `session.auth` (an instance of `MultiDomainBasicAuth`) after it's constructed. I believe that 2) is the reason for the careful cache management logic you see me tearing out in the PR. Basically: when a `MultiDomainBasicAuth` is constructed, it's possible that the keyring provider will change after the fact, so we can't do any useful caching in our constructor. In this PR, I reworked all of this to behave like more normal OOP: I've tightened up the API of `MultiDomainBasicAuth` so that these knobs are only passed in as constructor parameters, and the other instance attributes are now "private" (underscore-prefixed) values that you're not supposed to read or write to (except for some tests that look at these attributes to verify things are working). This change allowed me to get rid of all the careful cache management code we had, and sets me up to implement pypa#12750 as I'm going to be adding yet another knob (`keyring_executable`). This new pattern will allow me to validate that `keyring_executable` is compatible with `keyring_provider` in `MultiDomainAuthSettings`'s constructor (it doesn't make any sense to specify a path to an executable if you're using the import provider, for example). With the previous code pattern, there was just no good place to validate that. You'll notice I did end up touching a couple of tests: - `test_collector.py`: Logging is slightly different now, as we now immediately go fetch the keyring provider, rather than lazily. I could rework this to preserve the old behavior, but I don't think it's an important difference, it only affects tests that are trying to assert on every single log message. - `test_network_auth.py`: Nothing significant here. Just removing the now-unnecessary `reset_keyring` logic, and updating `.password` to `._password` to reflect the new api.
jfly
force-pushed
the
issue-12750-pre-work-refactor
branch
from
August 24, 2024 08:08
082a173
to
1ec2c8d
Compare
Darsstar
reviewed
Aug 25, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(This PR is some refactoring that I want to land before creating a PR to implement #12750. If the additional context is useful, you can see my upcoming changes over in jfly/pip@jfly:issue-12750-pre-work-refactor...jfly:pip:issue-12750-configurable-keyring-subprocess-location)
I was starting to work on #12750, but
got hung up on some strange OOP patterns going on here. In particular, I
found it odd that there are 2 different ways we set some knobs
(
prompting
andkeyring_provider
) and for instances ofMultiDomainBasicAuth
:parameters to
MultiDomainBasicAuth
.session.auth
(aninstance of
MultiDomainBasicAuth
) after it's constructed.I believe that 2) is the reason for the careful cache management logic
you see me tearing out in the PR. Basically: when a
MultiDomainBasicAuth
is constructed, it's possible that the keyringprovider will change after the fact, so we can't do any useful caching
in our constructor.
In this PR, I reworked all of this to behave like more normal OOP: I've
tightened up the API of
MultiDomainBasicAuth
so that these knobs areonly passed in as constructor parameters, and the other instance
attributes are now "private" (underscore-prefixed) values that you're
not supposed to read or write to (except for some tests that look at
these attributes to verify things are working).
This change allowed me to get rid of all the careful cache management
code we had, and sets me up to implement
#12750 as I'm going to be adding yet
another knob (
keyring_executable
). This new pattern will allow me tovalidate that
keyring_executable
is compatible withkeyring_provider
in
MultiDomainAuthSettings
's constructor (it doesn't make any sense tospecify a path to an executable if you're using the import provider, for
example). With the previous code
pattern, there was just no good place to validate that.
You'll notice I did end up touching a couple of tests:
test_collector.py
: Logging is slightly different now, as we nowimmediately go fetch the keyring provider, rather than lazily. I could
rework this to preserve the old behavior, but I don't think it's an
important difference, it only affects tests that are trying to assert
on every single log message.
test_network_auth.py
: Nothing significant here. Just removing thenow-unnecessary
reset_keyring
logic, and updating.password
to._password
to reflect the new api.