Changeset c2c51a2 in sasmodels


Ignore:
Timestamp:
May 6, 2016 1:13:55 AM (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:
306e354
Parents:
948b8c1
Message:

allow sasmodels to look in sasmodels-data for builtin model c source

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/__init__.py

    r37a7252 rc2c51a2  
    1414defining new models. 
    1515""" 
     16__version__ = "0.9" 
    1617 
    17 __version__ = "0.9" 
     18def data_files(): 
     19    """ 
     20    Return the data files to be installed with the package. 
     21 
     22    The format is a list of (directory, [files...]) pairs which can be 
     23    used directly in setup(...,data_files=...) for setup.py. 
     24    """ 
     25    from os.path import join as joinpath 
     26    from .generate import SIBLING_DIR, DATA_PATH 
     27    data_files = {} 
     28    def add_patterns(path, patterns): 
     29        data_files[joinpath(SIBLING_DIR, *path)] \ 
     30            = [joinpath(DATA_PATH, *(path+[p])) for p in patterns] 
     31    add_patterns([], ['*.c', '*.cl', 'convert.json']) 
     32    add_patterns(['models'], ['*.c']) 
     33    add_patterns(['models', 'lib'], ['*.c']) 
     34 
     35    return data_files 
     36 
  • sasmodels/generate.py

    rc4c426b rc2c51a2  
    210210import sys 
    211211from os.path import abspath, dirname, join as joinpath, exists, basename, \ 
    212     splitext 
     212    splitext, isdir 
    213213import re 
    214214import string 
     
    224224Parameter = namedtuple('Parameter', PARAMETER_FIELDS) 
    225225 
    226 C_KERNEL_TEMPLATE_PATH = joinpath(dirname(__file__), 'kernel_template.c') 
     226SIBLING_DIR = 'sasmodels-data' 
     227PACKAGE_PATH = abspath(dirname(__file__)) 
     228SIBLING_PATH = abspath(joinpath(PACKAGE_PATH, '..', 'sasmodels-data')) 
     229DATA_PATH = SIBLING_PATH if isdir(SIBLING_PATH) else PACKAGE_PATH 
     230MODEL_PATH = joinpath(DATA_PATH, 'models') 
     231C_KERNEL_TEMPLATE_FILE = joinpath(DATA_PATH, 'kernel_template.c') 
     232 
    227233 
    228234F16 = np.dtype('float16') 
     
    336342    Return a list of the sources file paths for the module. 
    337343    """ 
    338     search_path = [dirname(model_info['filename']), 
    339                    abspath(joinpath(dirname(__file__), 'models'))] 
     344    search_path = [dirname(model_info['filename']), MODEL_PATH] 
    340345    return [_search(search_path, f) for f in model_info['source']] 
    341346 
     
    457462    global C_KERNEL_TEMPLATE 
    458463    if C_KERNEL_TEMPLATE is None: 
    459         with open(C_KERNEL_TEMPLATE_PATH) as fid: 
     464        with open(C_KERNEL_TEMPLATE_FILE) as fid: 
    460465            C_KERNEL_TEMPLATE = fid.read() 
    461466 
     
    466471              for p in ('#line 1 "%s"'%f.replace('\\', '\\\\'), open(f).read()) 
    467472              ] 
    468     source.append('#line 133 "%s"'%C_KERNEL_TEMPLATE_PATH.replace('\\', '\\\\')) 
     473    source.append('#line 133 "%s"'%C_KERNEL_TEMPLATE_FILE.replace('\\', '\\\\')) 
    469474 
    470475    # Prepare defines 
Note: See TracChangeset for help on using the changeset viewer.