Skip to content

RFC: ENH: allow direct execution of CLI python scripts using Slicer's python

Isaiah requested to merge github/fork/ihnorton/pythonscripted_cli into master

This is a quick hack demonstrating a potential solution to this issue and related problems (e.g. running multiprocessing).

tl;dr, this detects a .pycli file in a CLI directory (cli-modules), and then configures the CLI node to run the script via Slicer's python interpreter. As an example, for SlicerRadiomicsCLI, this gives the following command line:

RadiomicsCLI command line:

/opt/bld/s5nj/python-install/bin/python inner-build/lib/Slicer-4.9/cli-modules/SlicerRadiomicsCLI.py --label 1 --out /var/folders/7l/2qsp6sqx4_b5x9kf_yzzm4lc0000gn/T/Slicer/EBACJ_vtkMRMLTableNodeB.csv /var/folders/7l/2qsp6sqx4_b5x9kf_yzzm4lc0000gn/T/Slicer/EBACJ_vtkMRMLScalarVolumeNodeB.nrrd /var/folders/7l/2qsp6sqx4_b5x9kf_yzzm4lc0000gn/T/Slicer/EBACJ_vtkMRMLLabelMapVolumeNodeB.nrrd

The command is exec'd via the existing CLI mechanism, runs out-of-process and async as any other CLI would be, but it inherits the full Slicer environment without requiring any launcher/cmake/etc. steps. Running directly also avoids OS security policy issues caused by shelling-out to protected interpreters.

Note that this is different from the current scripted CLI module path which runs in-process and blocks on the interpreter for the duration of the call (but should have no effect on that code path).

This PR does not handlepython-real in a factory-packaged Slicer, and other issues, but I wanted to put it up for feedback before spending time on it.

cc @fedorov @lassoan @pieper @ljod

Merge request reports