Changeset 2852

Jun 2, 2017 4:52:19 PM (6 years ago)

cleanup GSASIIpath to only load one bin directory into path and to test pyspg works

1 edited


  • trunk/

    r2682 r2852  
    2020import sys
    2121import platform
     22import glob
    2223# see if a directory for local modifications is defined. If so, stick that in the path
    2324if os.path.exists(os.path.expanduser('~/.G2local/')):
    6263    else:
    6364        bindir = 'binlinux%d.%d' % sys.version_info[0:2]
    64 for loc in sys.path[0],os.path.abspath(os.path.split(__file__)[0]):
    65     if bindir:
    66         if os.path.exists(os.path.join(loc,bindir)) and os.path.join(loc,bindir) not in sys.path:
    67             sys.path.insert(0,os.path.join(loc,bindir))
    68         # is there a bin directory? (created by a local compile), if so put
    69         # that at the top of the path
    70     if os.path.exists(os.path.join(loc,'bin')) and os.path.getsize(os.path.join(loc,'bin')):
    71         bindir = 'bin'
    72         if os.path.join(loc,'bin') not in sys.path:
    73             sys.path.insert(0,os.path.join(loc,bindir))
    74 print 'GSAS-II binary directory: ',os.path.join(loc,bindir)
    75 if bindir == None:
     65binpath = None
     66# scan the first directory in path as well as the location of current file
     67# for location of GSAS-II shared libraries (binaries: .so or .pyd files)
     68for loc in os.path.abspath(sys.path[0]),os.path.abspath(os.path.split(__file__)[0]):
     69    # Look at bin directory (created by a local compile) before standard dist
     70    # that at the top of the path
     71    for d in 'bin',bindir:
     72        if not d: continue
     73        fpth = os.path.join(loc,d)
     74        if not os.path.exists(fpth): continue
     75        if not glob.glob(os.path.join(fpth,'pyspg.*')): continue
     76        savpath = sys.path[:]
     77        sys.path.insert(0,fpth)
     78        # test to see if a shared library can be used
     79        try:
     80            import pyspg
     81            pyspg.sgforpy('P -1')
     82        except Exception as err:
     83            print(70*'=')
     84            print('Failed to run pyspg in {}\nerror: {}'.format(fpth,err))
     85            print(70*'=')
     86            sys.path = savpath
     87            continue
     88        binpath = fpth
     89        break
     90    if binpath: break
     91if binpath:
     92    print('GSAS-II binary directory: {}'.format(binpath))
    7694    raise Exception,"**** ERROR GSAS-II binary libraries not found, GSAS-II fails ****"
    7795# add the data import and export directory to the search path
Note: See TracChangeset for help on using the changeset viewer.