hpparvi / ldtk

Python toolkit for calculating stellar limb darkening profiles and model-specific coefficients using the stellar atmosphere spectrum library by Husser et al. (2013). Described in Parviainen & Aigrain, MNRAS 453, 3821–3826 (2015).
GNU General Public License v2.0
29 stars 19 forks source link

Core.py not platform independent #22

Closed Zorba256 closed 3 years ago

Zorba256 commented 3 years ago

Line 48 in core.py fails when running on Windows with an error as follows:

  File "c:\users\richa\pycharmprojects\exotic\venv\lib\site-packages\ldtk\__init__.py", line 21, in <module>
    from .ldtk import LDPSetCreator, LDPSet, load_ldpset
  File "c:\users\richa\pycharmprojects\exotic\venv\lib\site-packages\ldtk\ldtk.py", line 33, in <module>
    from .client import Client
  File "c:\users\richa\pycharmprojects\exotic\venv\lib\site-packages\ldtk\client.py", line 32, in <module>
    from .core import ldtk_root, FN_TEMPLATE, TEFF_POINTS, LOGG_POINTS, Z_POINTS, is_inside, SpecIntFile, message
  File "c:\users\richa\pycharmprojects\exotic\venv\lib\site-packages\ldtk\core.py", line 48, in <module>
    ldtk_root  = os.getenv('LDTK_ROOT') or join(os.getenv('HOME'),'.ldtk')
  File "C:\Users\richa\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 76, in join
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType

the relevant lines in core.py are:

48 ldtk_root  = os.getenv('LDTK_ROOT') or join(os.getenv('HOME'),'.ldtk')
49 if not exists(ldtk_root):
50    os.mkdir(ldtk_root)

I believe that the immediate error on Windows is because the variable "HOME" is not defined on this platform. Since the os.getenv call here has no defined default value, it returns not a string but a Nonetype object - which cannot be combined with os.join. I suggest the answer may be to use os.path.expanduser('~') to derive the platform independent home directory in line 48, or possibly Path.home if on Python 3.5+. Then to use os.path.join to build the path itself.

hpparvi commented 3 years ago

Hi,

This issue should be fixed now, but I can't test the fix because I haven't used Windows for quite a while (since XP or so.) Please pull the latest changes and let me know if everything works as it should.

Cheers, Hannu

rzellem commented 3 years ago

hi @hpparvi - I can confirm that the code on the master branch works on my Windows PC!!! Thank you for fixing this so quickly! Any estimate of when it will be released?

hpparvi commented 3 years ago

I've now updated the package in PyPI and created a new release in GitHub.