diff --git a/setup.py b/setup.py index 2da8e09..3d61346 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,9 @@ 'vttools.vtmods.import_lists' ], include_dirs=[np.get_include()], - package_data = {'vttools.vtmods.import_lists': ['*.yaml']} + package_data = {'vttools.vtmods.import_lists': ['*.yaml'], + 'vttools': ['*.yaml'], + } ) diff --git a/vt_config/NSLS-II/init.py b/vt_config/NSLS-II/init.py index 00b60ce..f70a415 100644 --- a/vt_config/NSLS-II/init.py +++ b/vt_config/NSLS-II/init.py @@ -44,13 +44,67 @@ import importlib import collections import os -from vttools import wrap_lib +import vistrails from vttools.vtmods.import_lists import load_config +import_dict = load_config() + +from vttools import wrap_lib from vttools.wrap_lib import AutowrapError logger = logging.getLogger(__name__) -# get modules to import -import_dict = load_config() +import imp + + +class VTImporter(object): + """ + + """ + def __init__(self, path): + self._path = path + + def find_module(self, fullname, path=None): + import os + name = fullname.rpartition('.')[-1] + if path is None: + path = self._path + for dn in path: + filename = os.path.join(dn, name+'.yaml') + if os.path.exists(filename): + return StructYAMLLoader(filename) + return None + + +class StructYAMLLoader(object): + def __init__(self, filename): + self._filename = filename + + def load_module(self, fullname): + mod = sys.modules.setdefault(fullname, + imp.new_module(fullname)) + mod.__file__ = self._filename + mod.__loader__ = self + with open(self._filename, 'r') as modules: + import_dict = yaml.load(modules) + + # import the hand-built VisTrails modules + module_list = import_dict['import_modules'] + for module_path, mod_lst in six.iteritems(module_list): + for module_name in mod_lst: + mod.__dict__[module_name.strip('.')] = importlib.import_module( + module_name, module_path) + + for func_dict in import_dict['autowrap_func']: + try: + mod.__dict__[func_dict['func_name']] = ( + wrap_lib.wrap_function(**func_dict)) + except AttributeError: + print("failed to find {}".format(func_dict['func_name'])) + + return mod + + +def install_importer(path=sys.path): + sys.meta_path.append(VTImporter(path)) def get_modules(): @@ -96,5 +150,19 @@ def get_modules(): return all_mods +def get_modules2(): + Module = vistrails.core.modules.vistrails_module.Module + modules = [] + spec_list = ['vttools.vt_wraps'] + for spec in spec_list: + mod = importlib.import_module(spec) + for name, obj in six.iteritems(mod.__dict__): + if (isinstance(obj, type) and issubclass(obj, Module)): + modules.append(obj) + elif hasattr(obj, 'vistrails_modules'): + modules.extend(obj.vistrails_modules()) + return modules + # # init the modules list -_modules = get_modules() +install_importer() +_modules = get_modules2() diff --git a/vttools/vt_wraps.yaml b/vttools/vt_wraps.yaml new file mode 100644 index 0000000..9d3fb13 --- /dev/null +++ b/vttools/vt_wraps.yaml @@ -0,0 +1,85 @@ +--- +# there are two possible keys: +# - 'import' are for python modules that have a +# _vistrails_modules() function within them +# - 'autowrap_func' are for python functions +# that should be wrapped into vistrails +# - 'autowrap_class' are for python classes +# that should be wrapped into vistrails + +# list of modules to import +import_modules: + vttools.vtmods: + - .io + - .vis + - .utils + - .broker + +# list of functions to autowrap +autowrap_func: +- func_name: grid3d + module_path: nsls2.core + namespace: core +- func_name: process_to_q + module_path: nsls2.recip + namespace: recip + add_input_dict: true +- func_name: hkl_to_q + module_path: nsls2.recip + namespace: recip +- func_name: twotheta_to_q + module_path: nsls2.core + namespace: recip +- func_name: q_to_twotheta + module_path: nsls2.core + namespace: recip +- func_name: bin_1D + module_path: nsls2.core + namespace: core +- func_name : bin_edges_to_centers + module_path: nsls2.core + namespace: core +- func_name : pixel_to_radius + module_path: nsls2.core + namespace: core +- func_name : pixel_to_phi + module_path: nsls2.core + namespace: core +- func_name: read_binary + module_path: nsls2.io.binary + namespace: io +- func_name: convolve + module_path: numpy + namespace: numpy +- func_name: gauss_fit + module_path: nsls2.fitting.model.physics_model + namespace: fitting +- func_name: lorentzian_fit + module_path: nsls2.fitting.model.physics_model + namespace: fitting +- func_name: lorentzian2_fit + module_path: nsls2.fitting.model.physics_model + namespace: fitting +- func_name: refine_center + module_path: nsls2.calibration + namespace: calibration +- func_name: estimate_d_blind + module_path: nsls2.calibration + namespace: calibration +- func_name: find_ring_center_acorr_iD + module_path: nsls2.image + namespace: image + + +#- {func_name: emission_line_search, module_path: nsls2.constants, namespace: core, add_input_dict: true} +#- {func_name: snip_method, module_path: nsls2.fitting.model.background,namespace: core, add_input_dict: true} +#- {func_name: gauss_peak, module_path: nsls2.fitting.model.physics_peak, namespace:core, add_input_dict: true} +#- {func_name: gauss_step, module_path: nsls2.fitting.model.physics_peak} +#- {func_name: gauss_tail, module_path: nsls2.fitting.model.physics_peak} +#- {func_name: elastic_peak, module_path: nsls2.fitting.model.physics_peak} +#- {func_name: compton_peak, module_path: nsls2.fitting.model.physics_peak} +#- {func_name: fit_quad_to_peak, module_path: nsls2.spectroscopy} +#- {func_name: align_and_scale, module_path: nsls2.spectroscopy} +#- {func_name: find_largest_peak, module_path: nsls2.spectroscopy} +#- {func_name: integrate_ROI_spectrum, module_path: nsls2.spectroscopy} +#- {func_name: integrate_ROI, module_path: nsls2.spectroscopy} \ No newline at end of file diff --git a/vttools/wrap_lib.py b/vttools/wrap_lib.py index 6dd4b3d..3a5e60f 100644 --- a/vttools/wrap_lib.py +++ b/vttools/wrap_lib.py @@ -179,6 +179,7 @@ def docstring_func(pyobj): 'ndarray': 'basic:Variant', 'array': 'basic:Variant', 'array_like': 'basic:Variant', + 'array-like': 'basic:Variant', 'np.ndarray': 'basic:Variant', 'list': 'basic:List', 'int': 'basic:Integer',