Skip to content

Commit 39ccffa

Browse files
committed
Add support for --disable-robot
It might be necessary to disable dependency resolution from the commandline. E.g. when it is enabled in the configfile and we want to upload a single file via `--new-pr`. Add new cmdline action `store_or_False` to generically add support for `--disable-<name>` for such cases.
1 parent 6cb6b5d commit 39ccffa

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

easybuild/base/generaloption.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ class ExtOption(CompleterOption):
182182
- set default to None if no option passed,
183183
- set to default if option without value passed,
184184
- set to value if option with value passed
185+
- store_or_False: Same as store_or_None, but set to False instead of None
186+
- Additionally supports --disable-
185187
186188
Types:
187189
- strlist, strtuple : convert comma-separated string in a list resp. tuple of strings
@@ -193,14 +195,15 @@ class ExtOption(CompleterOption):
193195

194196
ENABLE = 'enable' # do nothing
195197
DISABLE = 'disable' # inverse action
198+
STORE_OR_FALSE = 'store_or_False'
196199

197200
EXTOPTION_EXTRA_OPTIONS = ('date', 'datetime', 'regex', 'add', 'add_first', 'add_flex',)
198-
EXTOPTION_STORE_OR = ('store_or_None', 'help') # callback type
201+
EXTOPTION_STORE_OR = ('store_or_None', STORE_OR_FALSE, 'help') # callback type
199202
EXTOPTION_LOG = ('store_debuglog', 'store_infolog', 'store_warninglog',)
200203
EXTOPTION_HELP = ('shorthelp', 'confighelp', 'help')
201204

202205
ACTIONS = Option.ACTIONS + EXTOPTION_EXTRA_OPTIONS + EXTOPTION_STORE_OR + EXTOPTION_LOG + EXTOPTION_HELP
203-
STORE_ACTIONS = Option.STORE_ACTIONS + EXTOPTION_EXTRA_OPTIONS + EXTOPTION_LOG + ('store_or_None',)
206+
STORE_ACTIONS = Option.STORE_ACTIONS + EXTOPTION_EXTRA_OPTIONS + EXTOPTION_LOG + ('store_or_None', STORE_OR_FALSE)
204207
TYPED_ACTIONS = Option.TYPED_ACTIONS + EXTOPTION_EXTRA_OPTIONS + EXTOPTION_STORE_OR
205208
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + EXTOPTION_EXTRA_OPTIONS
206209

@@ -229,7 +232,9 @@ def store_or(option, opt_str, value, parser, *args, **kwargs): # pylint: disabl
229232
"""Callback for supporting options with optional values."""
230233
# see http://stackoverflow.com/questions/1229146/parsing-empty-options-in-python
231234
# ugly code, optparse is crap
232-
if parser.rargs and not parser.rargs[0].startswith('-'):
235+
if option.store_or == self.STORE_OR_FALSE and opt_str.startswith("--%s-" % self.DISABLE):
236+
val = False
237+
elif parser.rargs and not parser.rargs[0].startswith('-'):
233238
val = option.check_value(opt_str, parser.rargs.pop(0))
234239
else:
235240
val = kwargs.get('orig_default', None)
@@ -247,7 +252,7 @@ def store_or(option, opt_str, value, parser, *args, **kwargs): # pylint: disabl
247252
'orig_default': copy.deepcopy(self.default),
248253
}
249254
self.action = 'callback' # act as callback
250-
self.default = None
255+
self.default = False if self.action == self.STORE_OR_FALSE else None
251256

252257
def process(self, opt, value, values, parser):
253258
"""Handle option-as-value issues before actually processing option."""
@@ -1212,6 +1217,8 @@ def add_group_parser(self, opt_dict, description, prefix=None, otherdefaults=Non
12121217
if action in self.parser.option_class.BOOLEAN_ACTIONS:
12131218
args.append("--%s-%s" % (self.parser.option_class.ENABLE, opt_name))
12141219
args.append("--%s-%s" % (self.parser.option_class.DISABLE, opt_name))
1220+
elif action == self.parser.option_class.STORE_OR_FALSE:
1221+
args.append("--%s-%s" % (self.parser.option_class.DISABLE, opt_name))
12151222

12161223
# force passed_kwargs as final nameds
12171224
nameds.update(passed_kwargs)

easybuild/tools/options.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def basic_options(self):
278278
'rebuild': ("Rebuild software, even if module already exists (don't skip OS dependencies checks)",
279279
None, 'store_true', False),
280280
'robot': ("Enable dependency resolution, optionally consider additional paths to search for easyconfigs",
281-
'pathlist', 'store_or_None', [], 'r', {'metavar': '[PATH[%sPATH]]' % os.pathsep}),
281+
'pathlist', 'store_or_False', [], 'r', {'metavar': '[PATH[%sPATH]]' % os.pathsep}),
282282
'robot-paths': ("Additional paths to consider by robot for easyconfigs (--robot paths get priority)",
283283
'pathlist', 'add_flex', self.default_robot_paths, {'metavar': 'PATH[%sPATH]' % os.pathsep}),
284284
'search-paths': ("Additional locations to consider in --search (next to --robot and --robot-paths paths)",
@@ -1181,7 +1181,9 @@ def _postprocess_config(self):
11811181
if self.options.pretend:
11821182
self.options.installpath = get_pretend_installpath()
11831183

1184-
if self.options.robot is not None:
1184+
if self.options.robot is False:
1185+
self.options.robot = None # Set to None as-if not specified
1186+
elif self.options.robot is not None:
11851187
# if a single path is specified to --robot/-r, it must be an existing directory;
11861188
# this is required since an argument to --robot is optional,
11871189
# which makes it susceptible to 'eating' the following argument/option;

test/framework/options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,6 +3326,11 @@ def test_robot(self):
33263326
ec_regex = re.compile(r'^\s\*\s\[[xF ]\]\s%s' % os.path.join(test_ecs_path, ecfile), re.M)
33273327
self.assertTrue(ec_regex.search(outtxt), "Pattern %s found in %s" % (ec_regex.pattern, outtxt))
33283328

3329+
# Check for disabling --robot
3330+
args.append('--disable-robot')
3331+
self.assertErrorRegex(EasyBuildError, 'Missing dependencies', self.eb_main, args, raise_error=True)
3332+
self.assertNotExists(tmpdir)
3333+
33293334
def test_robot_path_check(self):
33303335
"""Test path check for --robot"""
33313336
empty_file = os.path.join(self.test_prefix, 'empty')

0 commit comments

Comments
 (0)