将git repo(使用pip编译和安装)包括到setup.py

2024-10-02 18:27:46 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在setup.py安装函数中包含git repo,该函数从源代码处编译,但前提是尚未安装包

我有来自这个instalation manual的shell命令。我可以使用OS module运行这些命令,但是如何使pip3安装命令健壮?如果用户重命名了pip3-->;皮普?那么我的实现就不再有效了

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

背景

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

Tags: install函数importgit命令buildversionsetup