LDMX-Software / Framework

Event-by-event processing framework using CERN's ROOT and C++17
2 stars 1 forks source link

fire does not tolerate dots in config file name #61

Closed tomeichlersmith closed 12 months ago

tomeichlersmith commented 1 year ago

In order to check for the config script, fire looks at its first argument and checks if it has a .py extension. The method for checking this extension is eager in the sense that it considers everything after the first . character the extension. This is a lame restriction and can be fixed with some simple tweaking of how the extension is found. The two places referencing the extension are below - I think the second one is the culprit.

https://github.com/LDMX-Software/Framework/blob/5ddc20eb5284da3a062ccfd64de620b6854fc1a1/src/Framework/fire.cxx#L61-L73

https://github.com/LDMX-Software/Framework/blob/5ddc20eb5284da3a062ccfd64de620b6854fc1a1/src/Framework/ConfigurePython.cxx#L222-L226

tomeichlersmith commented 1 year ago

I just realized that this is due to how Python handles filenames. Since we do the C-API equivalent of import, dots are interpreted as directories in a package file tree.

https://github.com/LDMX-Software/Framework/blob/5ddc20eb5284da3a062ccfd64de620b6854fc1a1/src/Framework/ConfigurePython.cxx#L248-L249

We could tolerate dots in a config file by parsing the script as a string into memory and then running that string as a python command using the interpreter we spawned. Probably using PyRun_SimpleString or PyRun_AnyFile is what we want.

tomeichlersmith commented 12 months ago

Just for future users, this is what the error looks like

[ldmx] eichl008@spa-cms017 /export/scratch/users/eichl008/ldmx/ldmx-sw/build> ldmx fire bas.ic.py 
---- LDMXSW: Loading configuration --------
ModuleNotFoundError: No module named 'bas'
Configuration Error [ConfigureError] : Problem loading python script
  at /export/scratch/users/eichl008/ldmx/ldmx-sw/Framework/src/Framework/ConfigurePython.cxx:315 in ConfigurePython
Stack trace: 
    0 /export/scratch/users/eichl008/ldmx/ldmx-sw/install/lib/libFramework.so(+0x68576) [0x7f61cbde6576]
    1 main + 280 addr2line: 'fire': No such file

    2 /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f61cb3d8d90]
Configuration Error [ConfigureError] : Problem loading python script
  at /export/scratch/users/eichl008/ldmx/ldmx-sw/Framework/src/Framework/ConfigurePython.cxx:315 in ConfigurePython
[ldmx] eichl008@spa-cms017 /export/scratch/users/eichl008/ldmx/ldmx-sw/build> ll bas*
lrwxrwxrwx 1 eichl008 CSEL-student   8 Sep 25 10:27 bas.ic.py -> basic.py
-rw-r--r-- 1 eichl008 CSEL-student 843 Sep 25 10:27 basic.py