在setup.py中声明我包的可选组件 [英] Declaring optional components of my package in setup.py

查看:51
本文介绍了在setup.py中声明我包的可选组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整理了一个具有以下结构的库:

I've put together a library with the following structure:

filters/
  __init__.py

  core/
    __init__.py
    base.py
    complex.py
    number.py
    string.py

  extra/
    __init__.py
    django.py
    iso.py

当开发人员执行 pip安装过滤器时,应始终安装

filters.core .

filters.core should always be installed when a developer does a pip install filters.

但是,我希望 filters.extra 是可选的.默认情况下不会安装.相反,开发人员需要执行 pip install filter [extra] 之类的操作,以便与核心一起安装额外的软件包.

However, I'd like filters.extra to be optional. It would not be installed by default; instead, the developer would need to do something like pip install filters[extra] in order to install the extra package along with the core.

是否可以使用setuptools来做到这一点?

Is it possible to do this using setuptools?

推荐答案

使用默认的setuptools工具是不可能的.您可以从以下两个选项中进行选择:

No this is not possible with the default means of setuptools. There are two options you can chose from:

  1. 用多余的东西创建第二个项目,例如 filters-extra .这是许多项目完成的工作.看例如在在pypi上烧瓶.
  2. 使用可选功能" 安装程序工具的机制.这将始终安装您的代码,但是只有在明确要求的情况下,才会安装您对其他功能的依赖性.
  1. Create a second project with the extra stuff, e.g. filters-extra. This is what is done by many projects. Look e.g. at flask on pypi.
  2. Use the "optional features" mechanism of setuptools. This will always install your code, but dependencies of you additional feature will only be installed if requested explicitly.

如果这些附加功能确实与您的核心功能分离开了,或者在代码中也没有互连,那么我通常会选择选项1,因为它更直接地使用和编写文档.

In case the extras are really separated from your core functionality and nor interconnected in the code, I would usually go for option 1 as it is more straight forward to use and document.

这篇关于在setup.py中声明我包的可选组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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