Changeset a5da1f2 in sasmodels for sasmodels/generate.py


Ignore:
Timestamp:
May 10, 2016 4:36:09 PM (8 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.