ComputationalPhysiology / gotran

Library for declaring and translating ODEs
http://computationalphysiology.github.io/gotran/
GNU Lesser General Public License v3.0
2 stars 1 forks source link

Make it possible to run gotran executables using `python -m gotran` #4

Closed finsberg closed 4 years ago

finsberg commented 4 years ago

It is now possible to run gotran scripts, such as gotran2py as a module. More specifically, instead of typing

gotran2py file.ode

in the command line, you can now also do

python -m gotran gotran2py file.ode

This makes it more clear which python version that is associated with the executable you want to run.

The way this is implemented is by adding a __main__.py (which is what is being executed when you run python -m gotran) where all the scripts are imported from a sub package called scripts. This makes it also easier to test later (you don't have to spawn subprocesses), as the scripts are now part of the gotran package.

KGHustad commented 4 years ago

So with these changes, there are now three ways to run the scripts

python -m gotran gotran2py demo/gotran2py/tentusscher_panfilov_2006_M_cell.ode
gotran gotran2py demo/gotran2py/tentusscher_panfilov_2006_M_cell.ode
gotran2py.py demo/gotran2py/tentusscher_panfilov_2006_M_cell.ode

But it is no longer possible to run it the old way

gotran2py demo/gotran2py/tentusscher_panfilov_2006_M_cell.ode

I'm not sure if this was intended? If so, we should update all demos and docs before merging.

finsberg commented 4 years ago

So with these changes, there are now three ways to run the scripts

python -m gotran gotran2py demo/gotran2py/tentusscher_panfilov_2006_M_cell.ode
gotran gotran2py demo/gotran2py/tentusscher_panfilov_2006_M_cell.ode
gotran2py.py demo/gotran2py/tentusscher_panfilov_2006_M_cell.ode

But it is no longer possible to run it the old way

gotran2py demo/gotran2py/tentusscher_panfilov_2006_M_cell.ode

I'm not sure if this was intended? If so, we should update all demos and docs before merging.

I totally agree that this is not what we want. Preferable, it should be possible to run the scripts in the same way as before in addition to using python -m gotran gotran2py. I have pushed a solution for this (8bde55af9b0ef69c4323ebe3d7ad7629252235e2) where the scripts are added as entry points in stead of scripts.

KGHustad commented 4 years ago

It seems like the commands take slightly longer to run now, presumably because of extra overhead. The relative change is fairly small though, as the gotran scripts were already quite sluggish, so I don't think it's a big concern.

Old

(gotran) [kghustad@mithrandir 21:28:24 gotran (master)*]$ time gotran2c
Traceback (most recent call last):
  File "/Users/kghustad/miniconda3/envs/gotran/bin/gotran2c", line 64, in <module>
    raise RuntimeError("Expected a single gotran file argument")
RuntimeError: Expected a single gotran file argument

real    0m0.628s
user    0m0.499s
sys 0m0.123s
(gotran) [kghustad@mithrandir 21:28:27 gotran (master)*]$ time gotran2c
Traceback (most recent call last):
  File "/Users/kghustad/miniconda3/envs/gotran/bin/gotran2c", line 64, in <module>
    raise RuntimeError("Expected a single gotran file argument")
RuntimeError: Expected a single gotran file argument

real    0m0.628s
user    0m0.499s
sys 0m0.127s

New

(gotran) [kghustad@mithrandir 21:28:59 gotran (finsberg/run_scripts_as_module)*]$ time gotran2c
Traceback (most recent call last):
  File "/Users/kghustad/miniconda3/envs/gotran/bin/gotran2c", line 10, in <module>
    sys.exit(main())
  File "/Users/kghustad/miniconda3/envs/gotran/lib/python3.7/site-packages/gotran/scripts/gotran2c.py", line 82, in main
    raise RuntimeError("Expected a single gotran file argument")
RuntimeError: Expected a single gotran file argument

real    0m0.791s
user    0m0.646s
sys 0m0.139s
(gotran) [kghustad@mithrandir 21:29:00 gotran (finsberg/run_scripts_as_module)*]$ time gotran2c
Traceback (most recent call last):
  File "/Users/kghustad/miniconda3/envs/gotran/bin/gotran2c", line 10, in <module>
    sys.exit(main())
  File "/Users/kghustad/miniconda3/envs/gotran/lib/python3.7/site-packages/gotran/scripts/gotran2c.py", line 82, in main
    raise RuntimeError("Expected a single gotran file argument")
RuntimeError: Expected a single gotran file argument

real    0m0.793s
user    0m0.646s
sys 0m0.143s