Changeset 68e7f9d in sasmodels


Ignore:
Timestamp:
Apr 4, 2016 12:18:02 PM (9 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
9d96649
Parents:
5b0335b
Message:

remove pyc file after loading custom model

Location:
sasmodels
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    r5b0335b r68e7f9d  
    99from os.path import basename, dirname, join as joinpath, splitext 
    1010from glob import glob 
    11 import imp 
    1211 
    1312import numpy as np 
     
    2928 
    3029try: 
    31     # Python 3.5 and up 
    32     from importlib.util import spec_from_file_location, module_from_spec 
    33     def load_module(fullname, path): 
    34         spec = spec_from_file_location(fullname, path) 
    35         module = module_from_spec(spec) 
    36         spec.loader.exec_module(module) 
    37         return module 
    38 except ImportError: 
    39     # CRUFT: python 2 
    40     import imp 
    41     def load_module(fullname, path): 
    42         module = imp.load_source(fullname, path) 
    43         return module 
    44  
    45 try: 
    4630    np.meshgrid([]) 
    4731    meshgrid = np.meshgrid 
     
    9882        return product.make_product_info(P_info, Q_info) 
    9983 
    100     kernel_module = load_kernel_module(model_name) 
     84    kernel_module = generate.load_kernel_module(model_name) 
    10185    return generate.make_model_info(kernel_module) 
    102  
    103  
    104 def load_kernel_module(model_name): 
    105     if model_name.endswith('.py'): 
    106         path = model_name 
    107         # Pull off the last .ext if it exists; there may be others 
    108         name = basename(splitext(path)[0]) 
    109         # Placing the model in the 'sasmodels.custom' name space. 
    110         from sasmodels import custom 
    111         kernel_module = load_module('sasmodels.custom.'+name, path) 
    112     else: 
    113         from sasmodels import models 
    114         __import__('sasmodels.models.'+model_name) 
    115         kernel_module = getattr(models, model_name, None) 
    116     #import sys; print "\n".join(sys.path) 
    117     __import__('sasmodels.models.'+model_name) 
    118     kernel_module = getattr(models, model_name, None) 
    119     return kernel_module 
    12086 
    12187 
  • sasmodels/direct_model.py

    raaf75b6 r68e7f9d  
    2525import numpy as np 
    2626 
    27 from .core import make_kernel 
    2827from .core import call_kernel, call_ER_VR 
    2928from . import sesans 
     
    171170    def _calc_theory(self, pars, cutoff=0.0): 
    172171        if self._kernel is None: 
    173             self._kernel = make_kernel(self._model, self._kernel_inputs)  # pylint: disable=attribute-dedata_type 
    174             self._kernel_mono = (make_kernel(self._model, self._kernel_mono_inputs) 
     172            self._kernel = self._model.make_kernel(self._kernel_inputs) 
     173            self._kernel_mono = (self._model.make_kernel(self._kernel_mono_inputs) 
    175174                                 if self._kernel_mono_inputs else None) 
    176175 
  • sasmodels/generate.py

    rce896fd r68e7f9d  
    193193 
    194194from .modelinfo import ModelInfo, Parameter, make_parameter_table, set_demo 
     195from .custom import load_custom_kernel_module 
    195196 
    196197# TODO: identify model files which have changed since loading and reload them. 
     
    662663            return Iq(np.sqrt(qx**2 + qy**2), **kw) 
    663664        model_info['Iqxy'] = Iqxy 
     665 
     666 
     667def load_kernel_module(model_name): 
     668    if model_name.endswith('.py'): 
     669        kernel_module = load_custom_kernel_module(model_name) 
     670    else: 
     671        from sasmodels import models 
     672        __import__('sasmodels.models.'+model_name) 
     673        kernel_module = getattr(models, model_name, None) 
     674    return kernel_module 
    664675 
    665676 
     
    811822    """ 
    812823    import sys 
    813     from sasmodels.core import make_model_by_name 
    814824    if len(sys.argv) <= 1: 
    815825        print("usage: python -m sasmodels.generate modelname") 
    816826    else: 
    817827        name = sys.argv[1] 
    818         model_info = make_model_by_name(name) 
     828        kernel_module = load_kernel_module(name) 
     829        model_info = make_model_info(kernel_module) 
    819830        source = make_source(model_info) 
    820831        print(source) 
Note: See TracChangeset for help on using the changeset viewer.