Changeset a22d104 in sasmodels


Ignore:
Timestamp:
Mar 2, 2018 5:18:44 PM (7 years ago)
Author:
krzywon
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
2f733b1
Parents:
fc3ae1b
Message:

If cannot find built-in model, try plugin path.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    r108e70e ra22d104  
    169169 
    170170import sys 
    171 from os.path import abspath, dirname, join as joinpath, exists, getmtime 
     171from os import environ 
     172from os.path import abspath, dirname, join as joinpath, exists, getmtime, sep 
    172173import re 
    173174import string 
     
    897898    load it from :mod:`sasmodels.models`. 
    898899    """ 
     900    # TODO: Keep current scheme (.py looks in custom folders) 
     901    plugin_path = environ.get('PLUGIN_MODEL_DIR', None) 
    899902    if model_name.endswith('.py'): 
    900903        kernel_module = load_custom_kernel_module(model_name) 
    901904    else: 
    902         from sasmodels import models 
    903         __import__('sasmodels.models.'+model_name) 
    904         kernel_module = getattr(models, model_name, None) 
     905        try: 
     906            from sasmodels import models 
     907            __import__('sasmodels.models.'+model_name) 
     908            kernel_module = getattr(models, model_name, None) 
     909        except Exception: 
     910            if plugin_path is not None: 
     911                file_name = model_name.split(sep)[-1] 
     912                model_name = plugin_path + sep + file_name + ".py" 
     913            kernel_module = load_custom_kernel_module(model_name) 
    905914    return kernel_module 
    906915 
Note: See TracChangeset for help on using the changeset viewer.