1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import argparse
import llnl.util.tty as tty
import spack.cmd.modules.lmod
import spack.cmd.modules.tcl
description = "manipulate module files"
section = "modules"
level = "short"
_subcommands = {}
_deprecated_commands = ('refresh', 'find', 'rm', 'loads')
def setup_parser(subparser):
sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='module_command')
spack.cmd.modules.lmod.add_command(sp, _subcommands)
spack.cmd.modules.tcl.add_command(sp, _subcommands)
for name in _deprecated_commands:
add_deprecated_command(sp, name)
def add_deprecated_command(subparser, name):
parser = subparser.add_parser(name)
parser.add_argument(
'-m', '--module-type', help=argparse.SUPPRESS,
choices=spack.modules.module_types.keys(), action='append'
)
def handle_deprecated_command(args, unknown_args):
command = args.module_command
unknown = ' '.join(unknown_args)
module_types = args.module_type or ['tcl']
msg = '`spack module {0} {1}` has moved. Use these commands instead:\n'
msg = msg.format(command, ' '.join('-m ' + x for x in module_types))
for x in module_types:
msg += '\n\t$ spack module {0} {1} {2}'.format(x, command, unknown)
msg += '\n'
tty.die(msg)
def module(parser, args, unknown_args):
# Here we permit unknown arguments to intercept deprecated calls
if args.module_command in _deprecated_commands:
handle_deprecated_command(args, unknown_args)
# Fail if unknown arguments are present, once we excluded a deprecated
# command
if unknown_args:
tty.die('unrecognized arguments: {0}'.format(' '.join(unknown_args)))
_subcommands[args.module_command](parser, args)
|