简体   繁体   English

在setup.py中调用另一个setup.py

[英]Call another setup.py in setup.py

My repository contains my own python module and a submodule to one of its dependencies which has its own setup.py. 我的存储库包含我自己的python模块和一个具有自己的setup.py的依赖项的子模块。

I'd like to call the dependency's setupy.py when installing my own lib, how is it possible? 我想在安装自己的lib时调用依赖项的setupy.py,怎么可能?

My first attempt: 我的第一次尝试:

 $ 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'"

However install_requires does not accept paths. 但是install_requires不接受路径。

My second attempt was to use dependency_links=["../dependency"] with install_requires=["dependency"] however a dependency of the same name already exists in Pypi so setuptools tries to use that version instead of mine. 我的第二次尝试是将dependency_links=["../dependency"]install_requires=["dependency"]但是Pypi中已存在同名的依赖项,因此setuptools尝试使用该版本而不是我的版本。

What's the correct/cleanest way? 什么是正确/最干净的方式?

A possible solution is to run a custom command before/after the install process. 可能的解决方案是在安装过程之前/之后运行自定义命令。

An example: 一个例子:

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 }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM