Skip to content

Commit bb9a94b

Browse files
committed
Factor out Khiops and task argument preprocessing in a separate function
closes #208
1 parent a3ef98e commit bb9a94b

1 file changed

Lines changed: 38 additions & 21 deletions

File tree

khiops/core/api.py

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,7 @@ def _run_task(task_name, task_args):
122122
stdout_file_path = task_args["stdout_file_path"]
123123
stderr_file_path = task_args["stderr_file_path"]
124124

125-
# Execute the preprocess of common task arguments
126-
task_called_with_domain = _preprocess_task_arguments(task_args)
127-
128-
# Create a command line options object
129-
command_line_options = CommandLineOptions(
130-
batch_mode=task_args["batch_mode"] if "batch_mode" in task_args else True,
131-
log_file_path=(
132-
task_args["log_file_path"] if "log_file_path" in task_args else ""
133-
),
134-
output_scenario_path=(
135-
task_args["output_scenario_path"]
136-
if "output_scenario_path" in task_args
137-
else ""
138-
),
139-
task_file_path=(
140-
task_args["task_file_path"] if "task_file_path" in task_args else ""
141-
),
142-
)
143-
144-
# Clean the task_args to leave only the task arguments
145-
_clean_task_args(task_args)
125+
command_line_options, task_called_with_domain = _preprocess_arguments(task_args)
146126

147127
# Obtain the api function from the registry
148128
task = get_task_registry().get_task(task_name, get_khiops_version())
@@ -162,6 +142,43 @@ def _run_task(task_name, task_args):
162142
fs.remove(task_args["dictionary_file_path"])
163143

164144

145+
def _preprocess_arguments(args):
146+
"""Preprocessing of Khiops arguments
147+
148+
Parameters
149+
----------
150+
args : dict
151+
The Khiops arguments.
152+
153+
Returns
154+
-------
155+
tuple
156+
A 2-tuple containing:
157+
- A `~.CommandLineOptions` instance
158+
- A `bool` that is ``True`` if the value of the `dictionary_file_or_domain`
159+
`args` key is a `~.DictionaryDomain` instance.
160+
161+
.. note:: This function *mutates* the input `args` dictionary.
162+
"""
163+
# Execute the preprocess of common task arguments
164+
task_is_called_with_domain = _preprocess_task_arguments(args)
165+
166+
# Create a command line options object
167+
command_line_options = CommandLineOptions(
168+
batch_mode=args["batch_mode"] if "batch_mode" in args else True,
169+
log_file_path=(args["log_file_path"] if "log_file_path" in args else ""),
170+
output_scenario_path=(
171+
args["output_scenario_path"] if "output_scenario_path" in args else ""
172+
),
173+
task_file_path=(args["task_file_path"] if "task_file_path" in args else ""),
174+
)
175+
176+
# Clean the args to leave only the task arguments
177+
_clean_task_args(args)
178+
179+
return command_line_options, task_is_called_with_domain
180+
181+
165182
def _preprocess_task_arguments(task_args):
166183
"""Preprocessing of task arguments common to various tasks
167184

0 commit comments

Comments
 (0)