0

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}))
DennisLi
  • 3,915
  • 6
  • 30
  • 66
simon
  • 77
  • 7
  • I think it would be cleaner to document your shell setup as a prerequisite for running `pip install myProject`, rather than embedding it. Alternatively, you could publish wheels that include the pre-built dependencies. – chepner Mar 31 '20 at 12:27
  • 1
    This sounds a bit like an [XY Problem](https://en.wikipedia.org/wiki/XY_problem). Can you give us more details and tell us why you need to do this? – Dustin Ingram Mar 31 '20 at 19:04

0 Answers0