Reputation: 113
I am working on a HPC-Linux-cluster and need to conduct a lot of Post Processing of data with python functions and scripts. My current workflow looks like the following:
python myfunction arg1 arg2
Since this doesn't allow me to store my python functions in one location it can get quite annoying sometimes when debugging.
So I was wondering if it is possible to store my functions at one location and autocomplete them after the python command without declaring their entire paths?
Ideally it would look like this:
python myfunction arg1 arg2
and not
python path-to-function/myfunction arg1 arg2
I have already managed to do so in the python interactive via the $PYTHONPATH and then import my functions, but frankly I don't like this solution since it is just a couple of more lines to type.
I also set a global variable to proceed as following: python $MYFUNCTIONS_PATH/myfunction arg1 arg2
but autocomplete won't work and it is also extra typing.
This is my first post here, I hope the question is nicely understood.
Upvotes: 4
Views: 358
Reputation: 113
I found a solution that fits my problem and is even more comfortable.
In the first line of your python scripts (the Shebang) add python as an executor with its path:
#!/usr/bin/python
If you are unsure about your pyhton path do: ẁhich python
Store all your wished python scripts at a fitting location and add this location to your PATH (e.g. in you .bashrc):
PATH=$PATH:/path/to/your/python/scripts
Make all your scripts in this location executable with:
chmod +x
After a new login or sourcing your .bashrc you should now be able to run the scripts from everywhere with autocomplete and you don't even have to type "python" before the script name:
yourscript.py arg1 arg2
Also see here.
Upvotes: 1
Reputation: 6090
Well not sure but I was doing that to chain process on HPC:
ls your/paths/of/interests/*/ > list.dat
Then:
#You process each of the element in your list
cat list.dat | while read -r line; do
#You cd to it
cd ${line}/gromacs/
#You use EOF to pass arguments
gmx distance -f step7_all.xtc -oall DIST_D103_K81_${line}.xvg -n index.ndx -
select 'cog of group "r_103_&_OD1_OD2" plus cog of group "r_81_&_NZ"' <<EOF
20
EOF
#You take your stuff away and cd back
cp DIST*xvg ../../
cd ../../
Upvotes: 0