Skip to content

Commit

Permalink
Fix dashes in variant parsing (spack#4498)
Browse files Browse the repository at this point in the history
- Skip spack flake8 test when flake8 is not installed.
- Fix parsing of dashes in specs broken by new help parser.
    - use argparse.REMAINDER instead of narg='?'
    - don't interpret parts of specs like -mpi as arguments.
  • Loading branch information
tgamblin authored Jun 15, 2017
1 parent 6762714 commit 8c24472
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/spack/spack/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import sys
import os
import inspect
from argparse import _ArgumentGroup, ArgumentParser, RawTextHelpFormatter
import pstats
import argparse

import llnl.util.tty as tty
from llnl.util.tty.color import *
Expand Down Expand Up @@ -126,7 +126,7 @@ def index_commands():
return index


class SpackArgumentParser(ArgumentParser):
class SpackArgumentParser(argparse.ArgumentParser):
def format_help_sections(self, level):
"""Format help on sections for a particular verbosity level.
Expand Down Expand Up @@ -165,7 +165,7 @@ def add_subcommand_group(title, commands):
if action.metavar in cmd_set)

# add commands to a group in order, and add the group
group = _ArgumentGroup(self, title=title)
group = argparse._ArgumentGroup(self, title=title)
for name in commands:
group._add_action(cmds[name])
if name in remaining:
Expand Down Expand Up @@ -265,7 +265,7 @@ def format_help(self, level='short'):
def make_argument_parser():
"""Create an basic argument parser without any subcommands added."""
parser = SpackArgumentParser(
formatter_class=RawTextHelpFormatter, add_help=False,
formatter_class=argparse.RawTextHelpFormatter, add_help=False,
description=(
"A flexible package manager that supports multiple versions,\n"
"configurations, platforms, and compilers."))
Expand Down Expand Up @@ -410,8 +410,7 @@ def main(argv=None):
# avoid loading all the modules from spack.cmd when we don't need
# them, which reduces startup latency.
parser = make_argument_parser()
parser.add_argument(
'command', metavar='COMMAND', nargs='?', action='store')
parser.add_argument('command', nargs=argparse.REMAINDER)
args, unknown = parser.parse_known_args(argv)

# Just print help and exit if run with no arguments at all
Expand All @@ -432,13 +431,13 @@ def main(argv=None):

# Try to load the particular command the caller asked for. If there
# is no module for it, just die.
command_name = args.command.replace('-', '_')
command_name = args.command[0].replace('-', '_')
try:
parser.add_command(command_name)
except ImportError:
if spack.debug:
raise
tty.die("Unknown command: %s" % args.command)
tty.die("Unknown command: %s" % args.command[0])

# Re-parse with the proper sub-parser added.
args, unknown = parser.parse_known_args()
Expand Down
1 change: 1 addition & 0 deletions lib/spack/spack/test/cmd/flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_changed_files(parser, flake8_package):
sys.version_info[:2] <= (2, 6) or
(3, 0) <= sys.version_info[:2] <= (3, 3),
reason='flake8 no longer supports Python 2.6 or 3.3 and older')
@pytest.mark.skipif(not which('flake8'), reason='flake8 is not installed.')
def test_flake8(parser, flake8_package):
# Only test the flake8_package that we modified
# Otherwise, the unit tests would fail every time
Expand Down

0 comments on commit 8c24472

Please sign in to comment.