From a68b66e14204e482436f410b0b4574f79c4c3460 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 3 May 2022 15:09:49 +0200 Subject: [PATCH] Separate installation and build scripts --- python/README.md | 42 +++++++++++++++++++++++--------- python/build_pyqmckl.sh | 16 ++---------- python/manual_install_pyqmckl.sh | 23 +++++++++++++++++ python/pip_install_pyqmckl.sh | 13 ++++++++++ 4 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 python/manual_install_pyqmckl.sh create mode 100755 python/pip_install_pyqmckl.sh diff --git a/python/README.md b/python/README.md index 006eb8d..9d468ef 100644 --- a/python/README.md +++ b/python/README.md @@ -1,22 +1,42 @@ # Python API of the QMCkl library + ## Requirements +- `setuptools` - `numpy` -- `SWIG` (>= 4.0) +- `swig` (>= 4.0) + ## Manual installation -1. Install the QMCkl as usual -2. Get the latest `qmckl.h` file -3. `python process.py` to generate `pyqmckl_include.i` list of SWIG patterns -4. `swig -python -py3 -o pyqmckl_wrap.c pyqmckl.i` to generate the SWIG wrapper code in C and `pyqmckl.py` module in Python. +1. Install the QMCkl library (see upstream instructions) +2. `./manual_install_pyqmckl.sh` which should do the following +3. Copy the produced `_pyqmckl.so` and `pyqmckl.py` files into your working directory and do not forget to `import pyqmckl` in your Python scripts + +The second step executes the following under the hood: + +1. `./build_pyqmckl.sh` +2. ` -I/usr/include/python3.8 -c -fPIC pyqmckl_wrap.c` to compile the wrapper code into an object file using the `` (replace with your C compiler, e.g. `gcc`) on your machine +3. ` -shared pyqmckl_wrap.o -lqmckl -o _pyqmckl.so` to produce the final C extension (this requires the `qmckl` library to be installed and present in the linking paths together with all its dependencies like `trexio`) + + +## Python-ic installation (recommended) + +1. Install the QMCkl library (see upstream instructions) +2. `./pip_install_pyqmckl.sh` + +The last step runs `./build_pyqmckl.sh`, copies the result into the `pyqmckl/` directory and +then runs `pip install .` to install the `pyqmckl` Python package in your environment. + + +## SWIG pre-processing + +Both aforementioned steps call `build_pyqmckl.sh` script which does the following pre-processing for SWIG + +1. Copy the latest `qmckl.h` file fron `include/` into the `src/` directory +2. `python process_header.py` to generate `pyqmckl_include.i` list of SWIG patterns +3. `swig -python -py3 -builtin -threads -o pyqmckl_wrap.c pyqmckl.i` to generate the SWIG wrapper code in C and `pyqmckl.py` module in Python. **Note:** for this to work three files have to be present in the working directory: `pyqmckl.i`, `pyqmckl_include.i` and `numpy.i`. -5. ` -I/usr/include/python3.8 -c -fPIC pyqmckl_wrap.c` to compile the wrapper code into an object file using the `` (replace with your C compiler, e.g. `gcc`) on your machine -6. ` -shared pyqmckl_wrap.o -lqmckl -o _pyqmckl.so` to produce the final C extension (this requires the `qmckl` library to be installed and present in the linking paths together with all its dependencies like `trexio`) -7. Put the produced `_pyqmckl.so` and `pyqmckl.py` files in the working directory and then run `import pyqmckl` - -## Python-ic installation - diff --git a/python/build_pyqmckl.sh b/python/build_pyqmckl.sh index 5af864f..b85aed3 100755 --- a/python/build_pyqmckl.sh +++ b/python/build_pyqmckl.sh @@ -3,7 +3,7 @@ set -e set -x -cp ../include/qmckl.h . +cp ../include/qmckl.h src/ cd src/ @@ -26,18 +26,6 @@ for file in $SWIG_LIST; do done # run SWIG interface file to produce the Python wrappers -swig -python -py3 -o pyqmckl_wrap.c pyqmckl.i - -# compile the wrapper code -cc -c -fPIC `pkg-config --cflags qmckl` -I/usr/include/python3.8 pyqmckl_wrap.c -o pyqmckl_wrap.o - -# link against the previously installed QMCkl library (as detected by pkg-config) -cc -shared pyqmckl_wrap.o `pkg-config --libs qmckl` -o _pyqmckl.so +swig -python -py3 -builtin -threads -o pyqmckl_wrap.c pyqmckl.i cd .. - -# test -cp src/_pyqmckl.so src/pyqmckl.py -- test/ -cd test -python test_api.py - diff --git a/python/manual_install_pyqmckl.sh b/python/manual_install_pyqmckl.sh new file mode 100644 index 0000000..41a53ac --- /dev/null +++ b/python/manual_install_pyqmckl.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -x +set -e + +./build_pyqmckl.sh + +cd src/ + +# compile the wrapper code +cc -c -fPIC `pkg-config --cflags qmckl` -I/usr/include/python3.8 pyqmckl_wrap.c -o pyqmckl_wrap.o + +# link against the previously installed QMCkl library (as detected by pkg-config) +cc -shared pyqmckl_wrap.o `pkg-config --libs qmckl` -o _pyqmckl.so + +cd .. + +# test +cp src/_pyqmckl.so src/pyqmckl.py test/ + +cd test/ +python test_api.py +cd .. diff --git a/python/pip_install_pyqmckl.sh b/python/pip_install_pyqmckl.sh new file mode 100755 index 0000000..5559d65 --- /dev/null +++ b/python/pip_install_pyqmckl.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -x +set -e + +./build_pyqmckl.sh + +# copy swig-produced pyqmckl.py module into the pyqmckl/ folder +cp src/pyqmckl.py pyqmckl/ + +# install using pip +pip install . +