指定安装“tests_require”的位置分发/安装工具包的依赖项
当我运行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法指定测试需求的安装位置。 test_require 参数的全部要点是指定安装包不需要的依赖项,而仅用于运行测试(正如您可以想象的那样,许多使用者可能想要安装包但不运行测试)。如果您希望在安装过程中包含测试要求,我会将它们包含在 install_requires 参数中。例如:
据我所知,没有任何参数可以在不更改安装脚本的情况下传递来强制执行此行为。
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:
As far as I know, there's no parameter you can pass to force this behavior without changing the setup script.
您可以使用 virtualenv 来避免这种情况,并将额外的软件包安装到其默认位置,即 lib/pythonX/site-packages 内。首先,您应该在 setup.py 中将您的测试要求定义为额外的:
然后安装具有测试要求的软件包,如下所示:
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:
Then install your package with test requirements like this:
我正在使用 pip 来实现类似的目标。我没有在 setup.py 中添加 tests_requires 或 extras ,而是创建了一个 pip 要求文件。
以我的 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:
Then to install it run: