Skip to content

remove basecommand.merge_options() #904

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,29 @@ def parseopts(args):
description = [''] + ['%-27s %s' % (i, j) for i, j in command_summaries]
parser.description = '\n'.join(description)

options, args = parser.parse_args(args)
options, cmd_args = parser.parse_args(args)
# args: ['--timeout=5', 'install', '--user', 'INITools']
# cmd_args: ['install', '--user', 'INITools']
# note: parser calls disable_interspersed_args()
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these comments needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was good for me, because in the bottom part there is:

args.remove(cmd_args[0])
cmd_args = args  # --timeout=5 --user INITools

That is a complement to the first comments.


if options.version:
sys.stdout.write(parser.version)
sys.stdout.write(os.linesep)
sys.exit()

# pip || pip help || pip --help -> print_help()
if not args or (args[0] == 'help' and len(args) == 1):
if not cmd_args or (cmd_args[0] == 'help' and len(cmd_args) == 1):
parser.print_help()
sys.exit()

if not args:
if not cmd_args:
msg = ('You must give a command '
'(use "pip --help" to see a list of commands)')
raise CommandError(msg)

command = args[0].lower()
command = cmd_args[0].lower() # install
args.remove(cmd_args[0])
cmd_args = args # --timeout=5 --user INITools

if command not in commands:
guess = get_similar_commands(command)
Expand All @@ -128,7 +133,7 @@ def parseopts(args):

raise CommandError(' - '.join(msg))

return command, options, args, parser
return command, options, cmd_args, parser


def main(initial_args=None):
Expand All @@ -138,15 +143,15 @@ def main(initial_args=None):
autocomplete()

try:
cmd_name, options, args, parser = parseopts(initial_args)
cmd_name, options, cmd_args, parser = parseopts(initial_args)
except PipError:
e = sys.exc_info()[1]
sys.stderr.write("ERROR: %s" % e)
sys.stderr.write(os.linesep)
sys.exit(1)

command = commands[cmd_name](parser) # see baseparser.Command
return command.main(args[1:], options)
return command.main(cmd_args, options)


def bootstrap():
Expand Down
14 changes: 0 additions & 14 deletions pip/basecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,11 @@ def _copy_option_group(self, parser, group):

parser.add_option_group(new_group)

def merge_options(self, initial_options, options):
# Make sure we have all global options carried over
attrs = ['log', 'proxy', 'require_venv',
'log_explicit_levels', 'log_file',
'timeout', 'default_vcs',
'skip_requirements_regex',
'no_input', 'exists_action',
'cert']
for attr in attrs:
setattr(options, attr, getattr(initial_options, attr) or getattr(options, attr))
options.quiet += initial_options.quiet
options.verbose += initial_options.verbose

def setup_logging(self):
pass

def main(self, args, initial_options):
options, args = self.parser.parse_args(args)
self.merge_options(initial_options, options)

level = 1 # Notify
level += options.verbose
Expand Down