Changes in sasmodels/generate.py [6cbdcd4:d86f0fc] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    r6cbdcd4 rd86f0fc  
    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 
     
    289290    import loops. 
    290291    """ 
    291     if (info.source and any(lib.startswith('lib/gauss') for lib in info.source)): 
    292         import os.path 
     292    if info.source and any(lib.startswith('lib/gauss') for lib in info.source): 
    293293        from .gengauss import gengauss 
    294         path = os.path.join(MODEL_PATH, "lib", "gauss%d.c"%n) 
    295         if not os.path.exists(path): 
     294        path = joinpath(MODEL_PATH, "lib", "gauss%d.c"%n) 
     295        if not exists(path): 
    296296            gengauss(n, path) 
    297297        info.source = ["lib/gauss%d.c"%n if lib.startswith('lib/gauss') 
    298                         else lib for lib in info.source] 
     298                       else lib for lib in info.source] 
    299299 
    300300def format_units(units): 
     
    320320                     for w, h in zip(column_widths, PARTABLE_HEADERS)] 
    321321 
    322     sep = " ".join("="*w for w in column_widths) 
     322    underbar = " ".join("="*w for w in column_widths) 
    323323    lines = [ 
    324         sep, 
     324        underbar, 
    325325        " ".join("%-*s" % (w, h) 
    326326                 for w, h in zip(column_widths, PARTABLE_HEADERS)), 
    327         sep, 
     327        underbar, 
    328328        ] 
    329329    for p in pars: 
     
    334334            "%*g" % (column_widths[3], p.default), 
    335335            ])) 
    336     lines.append(sep) 
     336    lines.append(underbar) 
    337337    return "\n".join(lines) 
    338338 
     
    612612    """ 
    613613    spaces = " "*depth 
    614     sep = "\n" + spaces 
    615     return spaces + sep.join(s.split("\n")) 
     614    interline_separator = "\n" + spaces 
     615    return spaces + interline_separator.join(s.split("\n")) 
    616616 
    617617 
     
    619619def load_template(filename): 
    620620    # type: (str) -> str 
     621    """ 
     622    Load template file from sasmodels resource directory. 
     623    """ 
    621624    path = joinpath(DATA_PATH, filename) 
    622625    mtime = getmtime(path) 
     
    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 ImportError: 
     910            # If the model isn't a built in model, try the plugin directory 
     911            plugin_path = environ.get('SAS_MODELPATH', None) 
     912            if plugin_path is not None: 
     913                file_name = model_name.split(sep)[-1] 
     914                model_name = plugin_path + sep + file_name + ".py" 
     915                kernel_module = load_custom_kernel_module(model_name) 
     916            else: 
     917                raise 
    905918    return kernel_module 
    906919 
Note: See TracChangeset for help on using the changeset viewer.