File tree Expand file tree Collapse file tree 5 files changed +27
-11
lines changed
Expand file tree Collapse file tree 5 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 7777# Find all the `cmd-spack-*` references and add them to a command index
7878#
7979import spack
80- command_names = spack .cmd .all_commands
80+ import spack .cmd
81+ command_names = spack .cmd .all_commands ()
8182documented_commands = set ()
8283for filename in glob ('*rst' ):
8384 with open (filename ) as f :
Original file line number Diff line number Diff line change @@ -83,11 +83,26 @@ def cmd_name(python_name):
8383 return python_name .replace ('_' , '-' )
8484
8585
86- for file in os .listdir (spack .paths .command_path ):
87- if file .endswith (".py" ) and not re .search (ignore_files , file ):
88- cmd = re .sub (r'.py$' , '' , file )
89- all_commands .append (cmd_name (cmd ))
90- all_commands .sort ()
86+ #: global, cached list of all commands -- access through all_commands()
87+ _all_commands = None
88+
89+
90+ def all_commands ():
91+ """Get a sorted list of all spack commands.
92+
93+ This will list the lib/spack/spack/cmd directory and find the
94+ commands there to construct the list. It does not actually import
95+ the python files -- just gets the names.
96+ """
97+ global _all_commands
98+ if _all_commands is None :
99+ _all_commands = []
100+ for file in os .listdir (spack .paths .command_path ):
101+ if file .endswith (".py" ) and not re .search (ignore_files , file ):
102+ cmd = re .sub (r'.py$' , '' , file )
103+ _all_commands .append (cmd_name (cmd ))
104+ _all_commands .sort ()
105+ return _all_commands
91106
92107
93108def remove_options (parser , * options ):
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ def rst(args):
131131
132132@formatter
133133def names (args ):
134- for cmd in spack .cmd .all_commands :
134+ for cmd in spack .cmd .all_commands () :
135135 print (cmd )
136136
137137
Original file line number Diff line number Diff line change @@ -108,14 +108,14 @@ def set_working_dir():
108108
109109def add_all_commands (parser ):
110110 """Add all spack subcommands to the parser."""
111- for cmd in spack .cmd .all_commands :
111+ for cmd in spack .cmd .all_commands () :
112112 parser .add_command (cmd )
113113
114114
115115def index_commands ():
116116 """create an index of commands by section for this help level"""
117117 index = {}
118- for command in spack .cmd .all_commands :
118+ for command in spack .cmd .all_commands () :
119119 cmd_module = spack .cmd .get_module (command )
120120
121121 # make sure command modules have required properties
@@ -174,7 +174,7 @@ def format_help_sections(self, level):
174174 self .actions = self ._subparsers ._actions [- 1 ]._get_subactions ()
175175
176176 # make a set of commands not yet added.
177- remaining = set (spack .cmd .all_commands )
177+ remaining = set (spack .cmd .all_commands () )
178178
179179 def add_group (group ):
180180 formatter .start_section (group .title )
Original file line number Diff line number Diff line change 3939def test_commands_by_name ():
4040 """Test default output of spack commands."""
4141 out = commands ()
42- assert out .strip ().split ('\n ' ) == sorted (spack .cmd .all_commands )
42+ assert out .strip ().split ('\n ' ) == sorted (spack .cmd .all_commands () )
4343
4444
4545def test_subcommands ():
You can’t perform that action at this time.
0 commit comments