source: sasmodels/sasmodels/custom/__init__.py @ 40a87fa

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 40a87fa was 40a87fa, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

lint and latex cleanup

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"""
2Custom Models
3-------------
4
5This is a place holder for the custom models namespace.  When models are
6loaded from a file by :func:`generate.load_kernel_module` they are loaded
7as if they exist in *sasmodels.custom*.  This package needs to exist for this
8to occur without error.
9"""
10
11import os
12from os.path import basename, splitext
13
14try:
15    # Python 3.5 and up
16    from importlib.util import spec_from_file_location, module_from_spec  # type: ignore
17    def load_module_from_path(fullname, path):
18        """load module from *path* as *fullname*"""
19        spec = spec_from_file_location(fullname, path)
20        module = module_from_spec(spec)
21        spec.loader.exec_module(module)
22        return module
23except ImportError:
24    # CRUFT: python 2
25    import imp
26    def load_module_from_path(fullname, path):
27        """load module from *path* as *fullname*"""
28        module = imp.load_source(fullname, path)
29        #os.unlink(path+"c")  # remove the automatic pyc file
30        return module
31
32def load_custom_kernel_module(path):
33    """load SAS kernel from *path* as *sasmodels.custom.modelname*"""
34    # Pull off the last .ext if it exists; there may be others
35    name = basename(splitext(path)[0])
36    # Placing the model in the 'sasmodels.custom' name space.
37    kernel_module = load_module_from_path('sasmodels.custom.'+name, path)
38    return kernel_module
Note: See TracBrowser for help on using the repository browser.