Skip to content

Commit

Permalink
ENH: Update CLI definition
Browse files Browse the repository at this point in the history
Remove use .bat and .sh wrapper script, and instead define the CLI entry point as a python script.
This makes use of the new Slicer functionality described in Slicer/Slicer#894 and implemented in r27143-r27145.

This fixes #43.

Additionally, check if a `--label <label>` argument is present, and if so, update it to the new-style: `--setting=label:<label>`. Parameter `--label` is deprecated by PR AIM-Harvard/pyradiomics#347.
  • Loading branch information
JoostJM committed Apr 30, 2018
1 parent 41a3114 commit 6f7375a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
7 changes: 0 additions & 7 deletions SlicerRadiomicsCLI/SlicerRadiomicsCLI

This file was deleted.

9 changes: 0 additions & 9 deletions SlicerRadiomicsCLI/SlicerRadiomicsCLI.bat

This file was deleted.

Expand Up @@ -10,6 +10,18 @@
with open(__file__[:-6] + '.xml', 'r') as xmlFP: # Cut off "Script" from filename
print(xmlFP.read())
else:
# Check if old-style label argument is provided
if '--label' in sys.argv:
label_idx = sys.argv.index('--label')
# get the value for the label
label = sys.argv[label_idx + 1]
# Remove the old-style command argument and value
sys.argv.pop(label_idx + 1)
sys.argv.pop(label_idx)

# append new style
sys.argv.append('--setting=label:' + label)

sys.argv.append('--format=csv') # Append this format to ensure a csv return format (default is txt)
sys.argv.append('--verbosity=4') # Print out logging with level INFO and higher
parse_args() # Entry point for the "pyradiomics" script
2 changes: 1 addition & 1 deletion SlicerRadiomicsCLI/SlicerRadiomicsCLI.xml
Expand Up @@ -32,7 +32,7 @@
<description><![CDATA[YAML or JSON structured file defining the customization that is to be applied.]]></description>
</file>
<integer>
<longflag alias="l">label</longflag>
<longflag>label</longflag>
<label>ROI label value</label>
<minimum>1</minimum>
<maximum>255</maximum>
Expand Down
25 changes: 8 additions & 17 deletions cmake/SlicerRadiomicsAddCLI.cmake
Expand Up @@ -77,25 +77,16 @@ function(SlicerRadiomicsAddCLI)
endif()
endforeach()

set(cli_files
"${MY_NAME}.xml"
"${MY_NAME}Script"
)
set(cli_file "${MY_NAME}.xml" )

if(WIN32)
set(cli_script "${MY_NAME}.bat")
else()
set(cli_script "${MY_NAME}")
endif()
set(cli_script "${MY_NAME}.py")

set(build_dir ${SlicerExecutionModel_DEFAULT_CLI_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
set(copy_commands )
foreach(cli_file IN LISTS cli_files)
list(APPEND copy_commands

list(APPEND copy_commands
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cli_file} ${build_dir}/${cli_file}
)
endforeach()

list(APPEND copy_commands
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cli_script} ${build_dir}/${cli_script}
)
Expand All @@ -106,7 +97,7 @@ function(SlicerRadiomicsAddCLI)
COMMENT "Copying ${MY_NAME} files into build directory"
)

install(FILES ${cli_files}
install(FILES ${cli_file}
DESTINATION ${SlicerExecutionModel_DEFAULT_CLI_INSTALL_RUNTIME_DESTINATION}
COMPONENT RuntimeLibraries
)
Expand All @@ -117,10 +108,10 @@ function(SlicerRadiomicsAddCLI)
)

if(NOT WIN32)
add_custom_target(SetPermissions${MY_NAME}ShellScript ALL
COMMAND chmod u+x ${build_dir}/${MY_NAME}
add_custom_target(SetPermissions${MY_NAME}CLI ALL
COMMAND chmod u+x ${build_dir}/${cli_script}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Setting Executable (User) permission for ${MY_NAME} in build directory"
COMMENT "Setting Executable (User) permission for ${cli_script} in build directory"
DEPENDS Copy${MY_NAME}Scripts
)
endif()
Expand Down

0 comments on commit 6f7375a

Please sign in to comment.