Changeset a5da1f2 in sasmodels


Ignore:
Timestamp:
May 10, 2016 4:36:09 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:
bd4ed1b
Parents:
848193e
Message:

fix path to models in frozen version of application

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/__init__.py

    rdc1e729 ra5da1f2  
    2424    """ 
    2525    from os.path import join as joinpath 
    26     from .generate import SIBLING_DIR, DATA_PATH 
     26    import glob 
     27 
     28    from .generate import EXTERNAL_DIR, DATA_PATH 
     29 
    2730    data_files = {} 
    2831    def add_patterns(path, patterns): 
    29         data_files[joinpath(SIBLING_DIR, *path)] \ 
     32        data_files[joinpath(EXTERNAL_DIR, *path)] \ 
    3033            = [joinpath(DATA_PATH, *(path+[p])) for p in patterns] 
    3134    add_patterns([], ['*.c', '*.cl', 'convert.json']) 
     
    3437 
    3538    # Fish out full paths for all files. 
    36     import glob 
    3739    return_list=[] 
    38     for key, values in data_files.iteritems(): 
     40    for path, patterns in data_files.items(): 
    3941        files_data=[] 
    40         for value in values: 
    41             files_data += [file for file in glob.glob(value)] 
    42         return_list.append([key, files_data]) 
     42        for pattern in patterns: 
     43            files_data.extend(glob.glob(pattern)) 
     44        return_list.append([path, files_data]) 
    4345    return return_list 
    4446 
  • sasmodels/generate.py

    rc2c51a2 ra5da1f2  
    224224Parameter = namedtuple('Parameter', PARAMETER_FIELDS) 
    225225 
    226 SIBLING_DIR = 'sasmodels-data' 
    227 PACKAGE_PATH = abspath(dirname(__file__)) 
    228 SIBLING_PATH = abspath(joinpath(PACKAGE_PATH, '..', 'sasmodels-data')) 
    229 DATA_PATH = SIBLING_PATH if isdir(SIBLING_PATH) else PACKAGE_PATH 
     226def get_data_path(external_dir, target_file): 
     227    path = abspath(dirname(__file__)) 
     228    if exists(joinpath(path, target_file)): 
     229        return path 
     230 
     231    # check next to exe/zip file 
     232    exepath = dirname(sys.executable) 
     233    path = joinpath(exepath, external_dir) 
     234    if exists(joinpath(path, target_file)): 
     235        return path 
     236 
     237    # check in py2app Contents/Resources 
     238    path = joinpath(exepath, '..', 'Resources', external_dir) 
     239    if exists(joinpath(path, target_file)): 
     240        return abspath(path) 
     241 
     242    raise RuntimeError('Could not find '+joinpath(external_dir, target_file)) 
     243 
     244EXTERNAL_DIR = 'sasmodels-data' 
     245DATA_PATH = get_data_path(EXTERNAL_DIR, 'kernel_template.c') 
    230246MODEL_PATH = joinpath(DATA_PATH, 'models') 
    231247C_KERNEL_TEMPLATE_FILE = joinpath(DATA_PATH, 'kernel_template.c') 
Note: See TracChangeset for help on using the changeset viewer.