xraypy / xraylarch

Larch: Applications and Python Library for Data Analysis of X-ray Absorption Spectroscopy (XAS, XANES, XAFS, EXAFS), X-ray Fluorescence (XRF) Spectroscopy and Imaging, and more.
https://xraypy.github.io/xraylarch
MIT License
138 stars 68 forks source link

Bug fix for using feff6l and feff8l #534

Closed liqunkang closed 3 weeks ago

liqunkang commented 3 weeks ago

@newville

I noticed a bug when I was using the feff6l and feff8l functions from larch.xafs.feffrunner in my Jupyter Notebook. This is due the find_exe function only accept a string as argument, instead of a pathlib.Path object. This fix should solve the problem.

Error message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 feff6l(feffinp = 'feff.inp', folder = './feff6l', verbose = True)

File ~\Documents\GitHub\xraylarch\larch\xafs\feffrunner.py:257, in feff6l(feffinp, folder, verbose, _larch, **kws)
    254 feffrunner = FeffRunner(folder=folder, feffinp=feffinp, verbose=verbose,
    255                         _larch=_larch, **kws)
    256 exe = find_exe('feff6l')
--> 257 feffrunner.run(exe=exe)
    258 return feffrunner

File ~\Documents\GitHub\xraylarch\larch\xafs\feffrunner.py:134, in FeffRunner.run(self, feffinp, folder, exe)
    131 if exe in self.Feff8l_modules:
    132     exe = f"feff8l_{exe}"
--> 134 resolved_exe = find_exe(exe)
    135 if resolved_exe is not None:
    136     program = resolved_exe

File ~\Documents\GitHub\xraylarch\larch\xafs\feffrunner.py:19, in find_exe(exename)
     16 def find_exe(exename):
     17     # if isinstance(exename, Path):
     18     #     exename = str(exename)
---> 19     if uname == 'win' and not exename.endswith('.exe'):
     20         exename = f"{exename}.exe"
     21     exefile = Path(bindir, exename)

AttributeError: 'WindowsPath' object has no attribute 'endswith'
newville commented 3 weeks ago

@liqunkang Oh, thanks for catching that!