20 """Medical Image Registration ToolKit 22 This is the Python package of MIRTK. It can be used to execute the MIRTK 23 commands as subprocesses within a image processing pipeline written in Python. 24 Moreover, some MIRTK modules may provide loadable Python modules. 26 To call a MIRTK command, either use the functions of the mirtk.subprocess module, 27 or simply execute a command using mirtk.<command>(args, option=value). 28 This will invoke the mirtk.subprocess.run function with name=<command> and 29 the provided positional and keyword arguments. 32 from __future__
import absolute_import
35 from types
import ModuleType
36 from mirtk
import subprocess
43 """Modify shared library search paths for MIRTK command execution.""" 48 ldpaths.append(os.path.join(libexec_dir, config))
49 ldpaths.append(libexec_dir)
50 for p
in [
'/Users/as12312/Software/VTK/Xcode/lib/Release',
'/System/Library/Frameworks',
'/usr/local/Cellar/flann/1.9.1_3/lib']:
51 if p !=
'': ldpaths.append(p)
52 if sys.platform.startswith(
'linux'):
53 ldpaths.extend(os.environ.get(
'LD_LIBRARY_PATH',
'').split(
':'))
54 os.environ[
'LD_LIBRARY_PATH'] =
':'.join(ldpaths)
55 elif sys.platform.startswith(
'darwin'):
56 ldpaths.extend(os.environ.get(
'DYLD_LIBRARY_PATH',
'').split(
':'))
57 os.environ[
'DYLD_LIBRARY_PATH'] =
':'.join(ldpaths)
58 elif sys.platform.startswith(
'win'):
59 ldpaths.extend(os.environ.get(
'PATH',
'').split(
';'))
60 os.environ[
'PATH'] =
';'.join(ldpaths)
69 """Module with dynamic creation of MIRTK command methods.""" 72 """Get method for execution of named MIRTK command.""" 73 if name ==
'subprocess':
75 if len(name) == 0
or name[0] ==
'_':
76 return ModuleType.__getattribute__(self, name)
77 if name
in [
"path",
"run",
"call",
"check_call",
"check_output"]:
78 return getattr(subprocess, name)
79 if not subprocess.path(name, quiet=
True):
80 command = name.replace(
'_',
'-')
81 if subprocess.path(command, quiet=
True):
84 return ModuleType.__getattribute__(self, name)
85 def run(*args, **kwargs):
86 return subprocess.run(name, *args, **kwargs)
87 setattr(self, name, run)
91 old_module = sys.modules[__name__]
94 new_module = sys.modules[__name__] =
Module(__name__)
95 for attr
in dict(old_module.__dict__):
97 new_module.__dict__[attr] = old_module.__dict__[attr]
def __getattr__(self, name)