【问题标题】:Call another setup.py in setup.py在 setup.py 中调用另一个 setup.py
【发布时间】:2017-04-11 10:29:17
【问题描述】:

我的存储库包含我自己的 python 模块和其依赖项之一的子模块,该依赖项具有自己的 setup.py。

我想在安装自己的lib时调用依赖的setupy.py,怎么可能?

我的第一次尝试:

 $ tree
.
├── dependency
│   └── setup.py
└── mylib
    └── setup.py


 $ cat mylib/setup.py 
from setuptools import setup

setup(
    name='mylib',
    install_requires= ["../dependency"]
    # ...
)

$ cd mylib && python setup.py install
error in arbalet_core setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'../depen'"

但是install_requires 不接受路径。

我的第二次尝试是使用 dependency_links=["../dependency"]install_requires=["dependency"] 但是 Pypi 中已经存在同名的依赖项,因此 setuptools 尝试使用该版本而不是我的版本。

什么是正确/最干净的方式?

【问题讨论】:

标签: python dependencies setuptools setup.py install-requires


【解决方案1】:

一种可能的解决方案是在安装过程之前/之后运行自定义命令。

一个例子:

from setuptools import setup
from setuptools.command.install import install

import subprocess

class InstallLocalPackage(install):
    def run(self):
        install.run(self)
        subprocess.call(
            "python path_to/local_pkg/setup.py install", shell=True
        )

setup(
    ...,
    cmdclass={ 'install': InstallLocalPackage }
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-18
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    相关资源
    最近更新 更多