Skip to content

Commit

Permalink
added a --params commandline option
Browse files Browse the repository at this point in the history
as in axon-runprocess, allows to pass parameters in a file
  • Loading branch information
denisri committed Apr 11, 2024
1 parent 6f23dfb commit d83840d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions capsul/process/runprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ def main():
'studyconfig file). If not specified neither on the '
'commandline nor study configfile, taken as the same as '
'input.')
group1.add_option('--params', dest='paramsfile', default=None,
help='specify a file containing commandline parameters. '
'The file will contain arguments for this commandline '
'(argv): it is an alternative to providing them here. '
'It can be useful to reuse parameters, or when the '
'parameters are too long (in a large iteration, '
'typically). The file syntax is one line per parameter, '
'with no further parsing. It will be processed after '
'all the current commanline arguments, not right now as '

Check failure on line 322 in capsul/process/runprocess.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

commanline ==> commandline
'the argument appears. But if a parameter has already '
'been set (via commandline), it will not be replaced: '
'first set arguments have priority. If the params file '
'itself contains a --params parameter, then another '
'file will be read afterwards, and so on.')
parser.add_option_group(group1)

group2 = OptionGroup(parser, 'Processing',
Expand Down Expand Up @@ -395,6 +409,17 @@ def main():
parser.disable_interspersed_args()
(options, args) = parser.parse_args()

while options.paramsfile:
pfile = options.paramsfile
options.paramsfile = None
with open(pfile) as f:
new_argv = [l.strip() for l in f.readlines()]
new_options, new_args = parser.parse_args(new_argv)
for k, v in new_options.__dict__.items():
if not getattr(options, k, None):
setattr(options, k, v)
args += new_args

if options.config:
engine = capsul_engine()
with open(options.config) as f:
Expand Down

0 comments on commit d83840d

Please sign in to comment.