Fix dashes in variant parsing (#4498)
- 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.
This commit is contained in:
parent
6762714302
commit
8c2447272e
@ -32,8 +32,8 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import inspect
|
import inspect
|
||||||
from argparse import _ArgumentGroup, ArgumentParser, RawTextHelpFormatter
|
|
||||||
import pstats
|
import pstats
|
||||||
|
import argparse
|
||||||
|
|
||||||
import llnl.util.tty as tty
|
import llnl.util.tty as tty
|
||||||
from llnl.util.tty.color import *
|
from llnl.util.tty.color import *
|
||||||
@ -126,7 +126,7 @@ def index_commands():
|
|||||||
return index
|
return index
|
||||||
|
|
||||||
|
|
||||||
class SpackArgumentParser(ArgumentParser):
|
class SpackArgumentParser(argparse.ArgumentParser):
|
||||||
def format_help_sections(self, level):
|
def format_help_sections(self, level):
|
||||||
"""Format help on sections for a particular verbosity level.
|
"""Format help on sections for a particular verbosity level.
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ def add_subcommand_group(title, commands):
|
|||||||
if action.metavar in cmd_set)
|
if action.metavar in cmd_set)
|
||||||
|
|
||||||
# add commands to a group in order, and add the group
|
# 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:
|
for name in commands:
|
||||||
group._add_action(cmds[name])
|
group._add_action(cmds[name])
|
||||||
if name in remaining:
|
if name in remaining:
|
||||||
@ -265,7 +265,7 @@ def format_help(self, level='short'):
|
|||||||
def make_argument_parser():
|
def make_argument_parser():
|
||||||
"""Create an basic argument parser without any subcommands added."""
|
"""Create an basic argument parser without any subcommands added."""
|
||||||
parser = SpackArgumentParser(
|
parser = SpackArgumentParser(
|
||||||
formatter_class=RawTextHelpFormatter, add_help=False,
|
formatter_class=argparse.RawTextHelpFormatter, add_help=False,
|
||||||
description=(
|
description=(
|
||||||
"A flexible package manager that supports multiple versions,\n"
|
"A flexible package manager that supports multiple versions,\n"
|
||||||
"configurations, platforms, and compilers."))
|
"configurations, platforms, and compilers."))
|
||||||
@ -410,8 +410,7 @@ def main(argv=None):
|
|||||||
# avoid loading all the modules from spack.cmd when we don't need
|
# avoid loading all the modules from spack.cmd when we don't need
|
||||||
# them, which reduces startup latency.
|
# them, which reduces startup latency.
|
||||||
parser = make_argument_parser()
|
parser = make_argument_parser()
|
||||||
parser.add_argument(
|
parser.add_argument('command', nargs=argparse.REMAINDER)
|
||||||
'command', metavar='COMMAND', nargs='?', action='store')
|
|
||||||
args, unknown = parser.parse_known_args(argv)
|
args, unknown = parser.parse_known_args(argv)
|
||||||
|
|
||||||
# Just print help and exit if run with no arguments at all
|
# Just print help and exit if run with no arguments at all
|
||||||
@ -432,13 +431,13 @@ def main(argv=None):
|
|||||||
|
|
||||||
# Try to load the particular command the caller asked for. If there
|
# Try to load the particular command the caller asked for. If there
|
||||||
# is no module for it, just die.
|
# is no module for it, just die.
|
||||||
command_name = args.command.replace('-', '_')
|
command_name = args.command[0].replace('-', '_')
|
||||||
try:
|
try:
|
||||||
parser.add_command(command_name)
|
parser.add_command(command_name)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if spack.debug:
|
if spack.debug:
|
||||||
raise
|
raise
|
||||||
tty.die("Unknown command: %s" % args.command)
|
tty.die("Unknown command: %s" % args.command[0])
|
||||||
|
|
||||||
# Re-parse with the proper sub-parser added.
|
# Re-parse with the proper sub-parser added.
|
||||||
args, unknown = parser.parse_known_args()
|
args, unknown = parser.parse_known_args()
|
||||||
|
@ -81,6 +81,7 @@ def test_changed_files(parser, flake8_package):
|
|||||||
sys.version_info[:2] <= (2, 6) or
|
sys.version_info[:2] <= (2, 6) or
|
||||||
(3, 0) <= sys.version_info[:2] <= (3, 3),
|
(3, 0) <= sys.version_info[:2] <= (3, 3),
|
||||||
reason='flake8 no longer supports Python 2.6 or 3.3 and older')
|
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):
|
def test_flake8(parser, flake8_package):
|
||||||
# Only test the flake8_package that we modified
|
# Only test the flake8_package that we modified
|
||||||
# Otherwise, the unit tests would fail every time
|
# Otherwise, the unit tests would fail every time
|
||||||
|
Loading…
Reference in New Issue
Block a user