How to include a git repo in the setup.py setup function that compiles from source, only if the package is not already installed?
I have shell commands from this instalation manual). I could run these with the OS module
, though how do I make the pip3 install command robust? What if a user renamed pip3 --> pip? Then my implementation would no longer work.
FENICS_VERSION=$(python3 -c"import ffc; print(ffc.__version__)")
git clone --branch=$FENICS_VERSION https://bitbucket.org/fenics-project/dolfin
git clone --branch=$FENICS_VERSION https://bitbucket.org/fenics-project/mshr
mkdir dolfin/build && cd dolfin/build && cmake .. && make install && cd ../..
mkdir mshr/build && cd mshr/build && cmake .. && make install && cd ../..
cd dolfin/python && pip3 install . && cd ../..
cd mshr/python && pip3 install . && cd ../..
Background
This and this Question/Answer pose a way to introduce a custom install commands to the setup function in setup.py through a class with a run method. I assume that in the code below the custom install script is run AFTER it checks the dependencies in install_requires
.
from setuptools import setup
from setuptools.command.install import install as _install
import subprocess
class install(_install):
def run(self):
install.run(self)
## do the magic for the installation of mshr and dolfin
setup(name='myProject',
.......
install_requires=['fenics-ffc >= 2018.1.0'],
setup(cmdclass={'install': install}))