Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with io.defaultsRead #465

Open
slimguat opened this issue Aug 20, 2024 · 7 comments
Open

Issue with io.defaultsRead #465

slimguat opened this issue Aug 20, 2024 · 7 comments

Comments

@slimguat
Copy link

Upon importing ChiantiPy.tools.data I have this error


TypeError Traceback (most recent call last)
Cell In[4], line 1
----> 1 import ChiantiPy.tools.data

File \SaffronDev\Lib\site-packages\ChiantiPy\tools\data.py:46
44 try:
45 Xuvtop = os.environ['XUVTOP']
---> 46 Defaults = chio.defaultsRead()
47 Ip = chio.ipRead()
48 MasterList = chio.masterListRead()

File \SaffronDev\Lib\site-packages\ChiantiPy\tools\io.py:430, in defaultsRead(verbose)
428 print((' reading chiantirc file'))
429 config = configparser.RawConfigParser(initDefaults)
--> 430 config.read(rcfile)
431 defaults = {}
432 for anitem in config.items('chianti'):

File C:\Python312\Lib\configparser.py:681, in RawConfigParser.read(self, filenames, encoding)
679 encoding = io.text_encoding(encoding)
680 read_ok = []
--> 681 for filename in filenames:
682 try:
683 with open(filename, encoding=encoding) as fp:

TypeError: 'bool' object is not iterable

From what I understand, in io.py>defaultsRead function rcfile is False and right after there is a check for a file existance
os.path.isfile(rcfile) that actually checks with rcfile being False. so I think there might be a need to change rcfile to None instead or change the check from if os.path.isfile(rcfile): to if os.path.isfile(rcfile) and (rcfile!=False) :

I am on Windows 11 x64,
Python 3.12.3
ChiantiPy 0.15.1

@kdere
Copy link
Contributor

kdere commented Aug 20, 2024

to clarify, do you have an chianitrc file and if so where it it?

@slimguat
Copy link
Author

I don't know what is this file exactly and where it is supposed to be. So where should I search for it?
BTW: I work with the database CHIANTI_10.0.2_database that's in my C:/ drive.

@kdere
Copy link
Contributor

kdere commented Aug 21, 2024

It is a file that set some default values. You have to actually put it in the #HOME/.config or the #HOME/.chianti directory manually. Since you have not done this you do not have the file.

I have not run chiantipy under 3.12 but will try that this morning. I do not have any problems with 3.10 or 3.11

Ken

@kdere
Copy link
Contributor

kdere commented Aug 21, 2024

I can not reproduce this under Python 3.12 so I am puzzled.

I am using the latest CHIANTI version 10.1 but I also tried CHIANTI version 10.0 and things still worked.

My best suggestion is to see if editing your version of defaultsRead works for you

Ken

@kdere
Copy link
Contributor

kdere commented Aug 21, 2024

another thing you might try is to see if XUVTOP is properly set

import ChiantiPy.tools.constants as chconst

and

import ChiantiPy.tools.io as chio
lvl = chio.elvlcRead('c_4')

@slimguat
Copy link
Author

slimguat commented Aug 22, 2024

I believe I have identified the root of the issue. It appears to be related to the Jupyter notebook environment I am using with Python 3.12. Specifically, the Jupyter server is incorrectly identifying the existence of a file when the os.path.isfile function is called with a boolean False value. This behavior seems to occur because, in Unix systems, the boolean False is equivalent to 0, which in turn corresponds to '/' (the root directory). As a result, os.path.isfile(False) is returning True.

However, this issue appears to be specific to Jupyter notebooks running Python 3.12 or later. I did not observe the same behavior when running the script directly in a terminal. Therefore, I believe this issue is not related to ChiantiPy, but rather to the interaction between Python 3.12 and the Jupyter environment.

@kdere
Copy link
Contributor

kdere commented Aug 22, 2024

I am running python 3.12.4 in a virtulall environment and do no have the problem. I checked my PYTHONPATH and it looks pretty clean. and, yes I do run linux.

thanks for letting me know.

Ken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants