source: sasmodels/sasmodels/custom/__init__.py @ 2d65d51

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

Merge branch 'master' into polydisp

Conflicts:

README.rst
sasmodels/core.py
sasmodels/data.py
sasmodels/generate.py
sasmodels/kernelcl.py
sasmodels/kerneldll.py
sasmodels/sasview_model.py

  • Property mode set to 100644
File size: 1.2 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        spec = spec_from_file_location(fullname, path)
19        module = module_from_spec(spec)
20        spec.loader.exec_module(module)
21        return module
22except ImportError:
23    # CRUFT: python 2
24    import imp
25    def load_module_from_path(fullname, path):
26        module = imp.load_source(fullname, path)
27        #os.unlink(path+"c")  # remove the automatic pyc file
28        return module
29
30def load_custom_kernel_module(path):
31    # Pull off the last .ext if it exists; there may be others
32    name = basename(splitext(path)[0])
33    # Placing the model in the 'sasmodels.custom' name space.
34    kernel_module = load_module_from_path('sasmodels.custom.'+name, path)
35    return kernel_module
Note: See TracBrowser for help on using the repository browser.