Python - setuptools - 处理两个依赖包(在单个 repo 中?) [英] Python - setuptools - working on two dependent packages (in a single repo?)

查看:39
本文介绍了Python - setuptools - 处理两个依赖包(在单个 repo 中?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个包含两个模块的 python 项目.这些模块非常相关,因此我希望它们位于同一个 git 存储库中,并且能够在我的 IDE 中一起开发它们:

I am working on a python project which contains two modules. The modules are very closely related and hence I want them to be in the same git repo, and to be able to develop them together in my IDE:

  • module1 依赖于 module2
  • module1 有很多其他重度依赖,module2 没有
  • module1module2 将用于不同的运行时环境
  • module2 应该可以单独安装,以便它可以在例如一个 AWS Lambda
  • module1 depends on module2
  • module1 has lots of other heavy dependencies, module2 does not
  • module1 and module2 will be used in different runtime environments
  • module2 should be installable separately so it can run in e.g. an AWS Lambda

因此,我尝试建立一个项目结构,其中包含一个 repo 内两个文件夹中的两个模块,每个文件夹都有一个 setup.py 以便可以打包.这是一个合理的方法吗?

Consequently I have tried to set up a project structure which contains the two modules in two folders within one repo, each folder having a setup.py so it can packaged. Is this a reasonable approach?

\module1
  setup.py
  \module1
    __init__.py
    [scripts].py
\module2
  setup.py
  \module2
    __init__.py
    [scripts].py

上述结构应该允许我在本地处理项目,将 module2 视为常规模块,但 setup.py 文件意味着它可以按原样分发自己的包,对吗?

The above structure should allow me to work on the project locally treating module2 as a regular module, but the setup.py file means that it can be distributed as it's own package, right?

问题是我不能在 module1setup.py 中包含 module2 依赖:

The problem is that I can't include the module2 dependency in module1's setup.py:

from setuptools import setup

setup(
    name="module1",
    version="0.1",
    packages=['module1'], # I really need to include module2 scripts here, right?...
    install_requires=['pandas', 'numpy', ...]
)

有人对如何解决这个问题有任何建议吗?我能猜到的两个解决方案是:

Does anyone have any advice on how to approach this problem? The two solutions I can guess are:

  • 在依赖于 module1 之前,它自己打包和发布 module2.这使得开发更加不灵活
  • module1 中嵌套 module2 以便我可以将它包含在 setup(...)packages 参数中代码>功能.这打破了 module1 应该将 module2 视为本质上是外部依赖项的清晰度...
  • Packaging and publishing module2 on it's own before depending on it from module1. This makes development much more infleixble
  • Nesting module2 within module1 so I can include it in the packages argument to the setup(...) function. This breaks the clarity that module1 should be treating module2 as if it were essentially an external dependency...

推荐答案

将它们保存在同一个存储库中的主要原因是在 IDE 中的两个模块上启用并行工作.我建议将模块保存在单独的存储库中并使用 editable 模式用于 pipdevelop模式为setuptools实现并行"开发.

Your main reason to keep them in the same repository is to enable parallel work on both the modules in your IDE. I would suggest to keep the modules in separate repositories and use the editable mode for pip or develop mode for setuptools to achieve the "parallel" development.

本质上,当您在 module1 中使用它时,您将在 develop/editable 模式下安装 module2.此后,您将在开发 module1

Essentially, you would be installing module2 in a develop/editable mode when you use it in module1. Thereafter, you will see all the changes made to module2 immediately while developing module1

这样做还可以确保 pip install git+ 之类的东西不会中断,您可以直接从 git

Doing the same will also make sure that things like pip install git+<git_directory> do not break and you can install directly from git

这篇关于Python - setuptools - 处理两个依赖包(在单个 repo 中?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆