xpsi-group / xpsi

X-PSI: X-ray Pulse Simulation and Inference
Other
34 stars 21 forks source link

Module generator bug fixed to correctly import Custom files #348

Closed DevarshiChoudhury closed 9 months ago

thjsal commented 10 months ago

The problem is that adding this dot in front of the imported module breaks modules if running them directly. Like this:

(xpsi_py3) tuomo@tuomo-XPS-13-9310:~/xpsi/xpsi_group/xpsi/examples/examples_module_generator$ python _auto_modules/main.py @config.ini 
/=============================================\
| X-PSI: X-ray Pulse Simulation and Inference |
|---------------------------------------------|
|                Version: 2.1.1               |
|---------------------------------------------|
|      https://xpsi-group.github.io/xpsi      |
\=============================================/

Imported GetDist version: 1.4.5
Imported nestcheck version: 0.2.1
Parsing configuration file...
--main-import-statements
...
Configuration file parsed.
Rank reporting: 0
Traceback (most recent call last):
  File "/home/tuomo/xpsi/xpsi_group/xpsi/examples/examples_module_generator/_auto_modules/main.py", line 858, in <module>
    from .CustomInstrument import CustomInstrument
ImportError: attempted relative import with no known parent package
DevarshiChoudhury commented 10 months ago

Let me test if I face the same issue. I don't think I have directly run the main module generated using py3 module generator. I was facing import issues when importing the main module from a notebook. If I am also able to reproduce the error above, I suppose a good way would to be put a if __name__ == '__main__' condition when importing the Custom modules in main

DevarshiChoudhury commented 10 months ago

@thjsal I have pushed another commit to account for relative imports.