-
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
Add a RevOptions class #4707
Add a RevOptions class #4707
Conversation
Also, this should be labeled: trivial, topic-vcs, and refactor. |
b75e7c9
to
c5f51f0
Compare
Whoops! I deleted my previous comment.
As an aside, the trivial tag is for marking a PR as not needing a news file. :) |
Okay, in the future, I'll do (as you suggested in your deleted comment):
And thanks for the explanation of the trivial tag! In the future, I'll add the empty news file instead of requesting a trivial tag. |
(I found the comment in my email; added to the previous comment) |
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
c5f51f0
to
167cb9f
Compare
Rebased. |
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
222735a
to
253be8a
Compare
src/pip/_internal/vcs/__init__.py
Outdated
|
||
return self.rev | ||
|
||
def to_args(self, start_args, end_args=None): |
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.
I'm not a fan:
I'd say cmd_args = ['branch', '-q'] + rev_options.to_args() + [url, dest]
reads better.
An __add__
might be overkill.
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.
That's a fair point. Thanks. I agree.
And thanks also for taking the time to review!
self.extra_args = extra_args | ||
self.rev = rev | ||
self.vcs = vcs | ||
|
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.
Some basic __repr__
would be welcome.
@@ -196,15 +285,19 @@ def check_version(self, dest, rev_options): | |||
""" |
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.
Maybe update check_version
's docstring also to stay consistent.
tests/unit/test_vcs.py
Outdated
@@ -14,6 +15,85 @@ | |||
VERBOSE_FALSE = 0 | |||
|
|||
|
|||
def check_to_args(vcs, expected1, expected2): |
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.
This could be a pytest.mark.parametrize()
test.
Thanks for the nice refactor ! 👍 |
You're welcome, and thank you again for your help, @xavfernandez! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR adds a
RevOptions
class to encapsulate the argument information needed to run VCS commands for a revision.Currently, the code base requires passing around at least three distinct, closely related pieces of information: the
rev
(revision to install), therev_options
(list of VCS command arguments), andrev_display
(how to display the revision to the end-user). It would be easier if this information can be passed around as a single unit.Also, in some cases the code "recomputes" the
rev
from therev_options
argument list. TheGit
class does this here:And here:
Accessing
rev_options[0]
is somewhat of a hack because it is brittle and VCS-specific. This can be done for the Git case becauserev_options
happens always to be[rev]
(at least whenrev_options
is non-empty). For Subversion though,rev_options
can take the form:The
RevOptions
class allows therev
to be accessed programmatically by storing this value as an attribute (e.g. letting us remove some Git-specific hacks like above).Another advantage of adding a
RevOptions
class is that more code can be moved into a class that can be unit-tested in a stand-alone fashion (and without using mocks, etc). This PR adds such tests for theRevOptions
class.