AllenInstitute / bmtk

Brain Modeling Toolkit
https://alleninstitute.github.io/bmtk/
BSD 3-Clause "New" or "Revised" License
265 stars 86 forks source link

Many examples won't work if config file is not specified in Python 3.9+ #374

Open shixnya opened 2 months ago

shixnya commented 2 months ago

Many examples under examples/ use the following line to set the 'default' config file.

if __file__ != sys.argv[-1]:

However, in Python 3.9+, this won't work because __file__ is an absolute path.

An easy way to fix it will be using something like:

if sys.argv[-1] in __file__:

Or, alternatively, we can change __file__ to os.path.basename(__file__).

There might be a better idea, so making an issue to discuss.

shixnya commented 2 months ago

This change of behavior in Python 3.9+ is documented here. https://docs.python.org/3/whatsnew/3.9.html#other-language-changes

Python now gets the absolute path of the script filename specified on the command line (ex: python3 script.py): the file attribute of the main module became an absolute path, rather than a relative path.

kaeldai commented 2 months ago

We should replace the if statement with using argparse library. It's relatively easy to implement but we'll have to change most of the run_[bionet|pointnet|filternet].py examples