首页 > 解决方案 > 在 setup.py 中包含 git repo(使用 pip 编译和安装)

问题描述

仅当尚未安装软件包时,如何在从源代码编译的 setup.py 设置函数中包含 git 存储库?

我有这个安装手册中的 shell 命令)。我可以用 运行这些OS module,但如何使 pip3 install 命令健壮?如果用户重命名 pip3 --> pip 怎么办?然后我的实施将不再有效。

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 ../..

背景

这个这个问题/答案提出了一种通过具有运行方法的类向 setup.py 中的设置函数引入自定义安装命令的方法。我假设在下面的代码中,自定义安装脚本是在检查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}))

标签: pythonsetuptoolssetup.pypypi

解决方案


推荐阅读