指定安装“tests_require”的位置分发/安装工具包的依赖项

发布于 2024-10-12 22:16:59 字数 287 浏览 3 评论 0原文

当我运行 python setup.py test 时,setup.py 中 tests_require 中列出的依赖项将下载到当前目录。当我运行 python setup.py install 时,requires 中列出的依赖项会安装到 site-packages 中。

如何将这些 tests_require 依赖项安装在 site-packages 中?

When I run python setup.py test the dependencies listed in tests_require in setup.py are downloaded to the current directory. When I run python setup.py install, the dependencies listed in requires are instead installed to site-packages.

How can I have those tests_require dependencies instead installed in site-packages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

十级心震 2024-10-19 22:16:59

您无法指定测试需求的安装位置。 test_require 参数的全部要点是指定安装包不需要的依赖项,而仅用于运行测试(正如您可以想象的那样,许多使用者可能想要安装包但不运行测试)。如果您希望在安装过程中包含测试要求,我会将它们包含在 install_requires 参数中。例如:

test_requirements = ['pytest>=2.1', 'dingus']
setup(
    # ...
    tests_require = test_requirements,
    install_requires = [
        # ... (your usual install requirements)
    ] + test_requirements,
)

据我所知,没有任何参数可以在不更改安装脚本的情况下传递来强制执行此行为。

You cannot specify where the test requirements are installed. The whole point of the tests_require parameter is to specify dependencies that are not required for the installation of the package but only for running the tests (as you can imagine many consumers might want to install the package but not run the tests). If you want the test requirements to be included during installation, I would include them in the install_requires parameter. For example:

test_requirements = ['pytest>=2.1', 'dingus']
setup(
    # ...
    tests_require = test_requirements,
    install_requires = [
        # ... (your usual install requirements)
    ] + test_requirements,
)

As far as I know, there's no parameter you can pass to force this behavior without changing the setup script.

鸢与 2024-10-19 22:16:59

您可以使用 virtualenv 来避免这种情况,并将额外的软件包安装到其默认位置,即 lib/pythonX/site-packages 内。首先,您应该在 setup.py 中将您的测试要求定义为额外的:

setup(
    # ...
    install_requires=[
        # ... (your usual install requirements)
    ],
    extras_require={
        'testing': [
            # ... (your test requirements)
        ]
    },
)

然后安装具有测试要求的软件包,如下所示:

pip install -e ".[testing]"

You can use a virtualenv to avoid this and install the extra packages to their default locations, inside lib/pythonX/site-packages. First, you should define your testing requirements as extras, in setup.py:

setup(
    # ...
    install_requires=[
        # ... (your usual install requirements)
    ],
    extras_require={
        'testing': [
            # ... (your test requirements)
        ]
    },
)

Then install your package with test requirements like this:

pip install -e ".[testing]"
我为君王 2024-10-19 22:16:59

我正在使用 pip 来实现类似的目标。我没有在 setup.py 中添加 tests_requires 或 extras ,而是创建了一个 pip 要求文件

以我的 dev_requirements.txt 文件为例:

pytest
webtest

然后安装它,运行:

$ pip install -r dev_requirements.txt

I am using pip to achieve something like that. Instead of adding tests_requires or extras to my setup.py I have created a pip requirements file.

Example my dev_requirements.txt file:

pytest
webtest

Then to install it run:

$ pip install -r dev_requirements.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文