...
Code Block |
---|
distance - for the convenience all the code is in one dir |-- distance_c_wrapper - C based wrapper - layer that allows to call | |-- Makefile Fortran code from Python | |-- include | | `-- distance_c_wrapper.h Note! All the code inside distance_c_wrapper | `-- src will be autogenerated. Shape of the code will depend | |-- distancewrapper on project definition (description of what is supposed | | `-- distance_c_wrapper.c to be generated) | `-- main.c |-- distance_fortran - This is the only code that will be provided by user | |-- Makefile Result of the compilation is a lib##.a file that | `-- src is later on packed inside shared lib that is called | |-- distance from Python | | `-- distance.F90 | `-- main.F90 `-- distance_python - Python based wrapper. This is the code that will |-- MANIFEST.in be incorporated inside Python scripts/Python workflows |-- README.md |-- distance_wrapper | |-- __init__.py Note! This code will be autogenerated (see above) | `-- actor.py |-- setup.cfg `-- setup.py |
Benefits of this approach
This approach allows to use the code in numerous scenarios
PYTHONPATH
It is possible to use the code directly inside script by simply exporting location of the code using PYTHONPATH
.
Code Block |
---|
> export PYTHONPATH=`pwd`/distance_python:${PYTHONPATH} |
PIP install
Current structure allows to install wrapper inside central installation of Python or inside virtual environment. All we have to do is to use pip install.
Code Block |
---|
> pip3 install --upgrade --force-reinstall `pwd`/distance_python |
PIP repository
With this structure it is possible to generate compressed versions of pip packages and distribute them via custom, self hosted, pip repository.
References
- pip documentation: https://pip.pypa.io/en/stable/
- Packaging Python Projects: https://packaging.python.org/tutorials/packaging-projects/
- Packaging Python Projects - sampleHosting your own simple repository: https://packaging.python.org/guides/hosting-your-own-index/
- ISO_C_BINDING: https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html