Skip to content

Commit

Permalink
Address review comments (part 2: make_command).
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek committed Aug 18, 2019
1 parent 3842e85 commit 5ffc930
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
14 changes: 12 additions & 2 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,19 @@ def unpack_file(


def make_command(*args):
# type: (Union[str, HiddenText]) -> CommandArgs
# type: (Union[str, HiddenText, CommandArgs]) -> CommandArgs
"""
Create a CommandArgs object.
"""
command_args = [] # type: CommandArgs
command_args.extend(args)
for arg in args:
# Check for list instead of CommandArgs since CommandArgs is
# only known during type-checking.
if isinstance(arg, list):
command_args.extend(arg)
else:
# Otherwise, arg is str or HiddenText.
command_args.append(arg)

return command_args

Expand Down
6 changes: 3 additions & 3 deletions src/pip/_internal/vcs/bazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def export(self, location, url):

url, rev_options = self.get_url_rev_options(url)
self.run_command(
make_command('export', location, url) + rev_options.to_args(),
make_command('export', location, url, rev_options.to_args()),
show_stdout=False,
)

Expand All @@ -68,7 +68,7 @@ def fetch_new(self, dest, url, rev_options):
display_path(dest),
)
cmd_args = (
make_command('branch', '-q') + rev_options.to_args() + [url, dest]
make_command('branch', '-q', rev_options.to_args(), url, dest)
)
self.run_command(cmd_args)

Expand All @@ -78,7 +78,7 @@ def switch(self, dest, url, rev_options):

def update(self, dest, url, rev_options):
# type: (str, HiddenText, RevOptions) -> None
cmd_args = make_command('pull', '-q') + rev_options.to_args()
cmd_args = make_command('pull', '-q', rev_options.to_args())
self.run_command(cmd_args, cwd=dest)

@classmethod
Expand Down
12 changes: 5 additions & 7 deletions src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def resolve_revision(cls, dest, url, rev_options):

# If it looks like a ref, we have to fetch it explicitly.
cls.run_command(
make_command('fetch', '-q', url) + rev_options.to_args(),
make_command('fetch', '-q', url, rev_options.to_args()),
cwd=dest,
)
# Change the revision to the SHA of the ref we fetched
Expand Down Expand Up @@ -211,8 +211,8 @@ def fetch_new(self, dest, url, rev_options):
# Only do a checkout if the current commit id doesn't match
# the requested revision.
if not self.is_commit_id_equal(dest, rev_options.rev):
cmd_args = (
make_command('checkout', '-q') + rev_options.to_args()
cmd_args = make_command(
'checkout', '-q', rev_options.to_args(),
)
self.run_command(cmd_args, cwd=dest)
elif self.get_current_branch(dest) != branch_name:
Expand All @@ -233,7 +233,7 @@ def switch(self, dest, url, rev_options):
make_command('config', 'remote.origin.url', url),
cwd=dest,
)
cmd_args = make_command('checkout', '-q') + rev_options.to_args()
cmd_args = make_command('checkout', '-q', rev_options.to_args())
self.run_command(cmd_args, cwd=dest)

self.update_submodules(dest)
Expand All @@ -248,9 +248,7 @@ def update(self, dest, url, rev_options):
self.run_command(['fetch', '-q'], cwd=dest)
# Then reset to wanted revision (maybe even origin/master)
rev_options = self.resolve_revision(dest, url, rev_options)
cmd_args = (
make_command('reset', '--hard', '-q') + rev_options.to_args()
)
cmd_args = make_command('reset', '--hard', '-q', rev_options.to_args())
self.run_command(cmd_args, cwd=dest)
#: update submodules
self.update_submodules(dest)
Expand Down
6 changes: 3 additions & 3 deletions src/pip/_internal/vcs/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def fetch_new(self, dest, url, rev_options):
)
self.run_command(make_command('clone', '--noupdate', '-q', url, dest))
self.run_command(
make_command('update', '-q') + rev_options.to_args(),
make_command('update', '-q', rev_options.to_args()),
cwd=dest,
)

Expand All @@ -67,13 +67,13 @@ def switch(self, dest, url, rev_options):
'Could not switch Mercurial repository to %s: %s', url, exc,
)
else:
cmd_args = make_command('update', '-q') + rev_options.to_args()
cmd_args = make_command('update', '-q', rev_options.to_args())
self.run_command(cmd_args, cwd=dest)

def update(self, dest, url, rev_options):
# type: (str, HiddenText, RevOptions) -> None
self.run_command(['pull', '-q'], cwd=dest)
cmd_args = make_command('update', '-q') + rev_options.to_args()
cmd_args = make_command('update', '-q', rev_options.to_args())
self.run_command(cmd_args, cwd=dest)

@classmethod
Expand Down
24 changes: 12 additions & 12 deletions src/pip/_internal/vcs/subversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ def export(self, location, url):
# Subversion doesn't like to check out over an existing
# directory --force fixes this, but was only added in svn 1.5
rmtree(location)
cmd_args = (
make_command('export') + self.get_remote_call_options() +
rev_options.to_args() + [url, location]
cmd_args = make_command(
'export', self.get_remote_call_options(),
rev_options.to_args(), url, location,
)
self.run_command(cmd_args, show_stdout=False)

Expand All @@ -303,25 +303,25 @@ def fetch_new(self, dest, url, rev_options):
rev_display,
display_path(dest),
)
cmd_args = (
make_command('checkout', '-q') + self.get_remote_call_options() +
rev_options.to_args() + [url, dest]
cmd_args = make_command(
'checkout', '-q', self.get_remote_call_options(),
rev_options.to_args(), url, dest,
)
self.run_command(cmd_args)

def switch(self, dest, url, rev_options):
# type: (str, HiddenText, RevOptions) -> None
cmd_args = (
make_command('switch') + self.get_remote_call_options() +
rev_options.to_args() + [url, dest]
cmd_args = make_command(
'switch', self.get_remote_call_options(), rev_options.to_args(),
url, dest,
)
self.run_command(cmd_args)

def update(self, dest, url, rev_options):
# type: (str, HiddenText, RevOptions) -> None
cmd_args = (
make_command('update') + self.get_remote_call_options() +
rev_options.to_args() + [dest]
cmd_args = make_command(
'update', self.get_remote_call_options(), rev_options.to_args(),
dest,
)
self.run_command(cmd_args)

Expand Down

0 comments on commit 5ffc930

Please sign in to comment.