英文:
Specifying test dependencies in pyproject.toml and getting them installed with pip install -e
问题
我有一个Python项目,其中有一个类似于下面的pyproject.toml
文件。我使用python build
来生成一个包,我在生产环境中安装使用。对于开发环境,我使用pip install -e .
。
我正在尝试弄清楚如何确保在开发环境中安装测试依赖项,但不包括在生产环境中。
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[tool.setuptools]
package-dir = {"" = "src"}
packages = [
"package-a",
"package-b",
]
[tool.setuptools.package-data]
"*" = [
"path/to/*.txt",
]
[project]
name = "my-project"
version = "0.0.1"
authors = [
{ name="devnectar", email="a@b.com" },
]
description = "description goes here"
readme = "README.md"
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
"dep",
"another-dep",
"yet-another-dep",
]
[project.optional-dependencies]
dev = [
"tox",
]
[project.urls]
"Homepage" = "https://some_url.com"
"Bug Tracker" = "https://some_url.com"
[project.scripts]
nectarserver = "entry-point-script"
[tool.tox]
legacy_tox_ini = """
[tox]
min_version = 4.0
env_list = test_env
[testenv]
deps = pytest
commands = pytest -s
"""
我还尝试过在尝试使其工作时使用test
和tests
代替dev
。
我遇到了两个问题:
- 当我运行
pip install -e .
时,tox
未安装。 install
命令生成的requires.txt
文件最终会有一个[dev]
部分,这会导致pip install -r mypackage/mypackage.egg-info/requires.txt
出错。这在我的构建链中的后续步骤中引发了其他问题,因为它依赖于在构建期间生成的requirements.txt文件,以生成包含项目依赖项的Docker层。
我应该如何在我的pyproject.toml
中捕获仅用于开发的依赖项tox
?
英文:
I have a Python project with a pyproject.toml
similar to the one below. I use python build
to generate an package I use to install in production environments. For development environments, I use pip install -e .
I'm trying to figure out how to make sure test dependencies are installed for development environments, but not as part of a production environment.
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[tool.setuptools]
package-dir = {"" = "src"}
packages = [
"package-a",
"package-b",
]
[tool.setuptools.package-data]
"*" = [
"path/to/*.txt"
]
[project]
name = "my-project"
version = "0.0.1"
authors = [
{ name="devnectar", email="a@b.com" },
]
description = "description goes here"
readme = "README.md"
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
"dep",
"another-dep",
"yet-another-dep"
]
[project.optional-dependencies]
dev = [
"tox"
]
[project.urls]
"Homepage" = "https://some_url.com"
"Bug Tracker" = "https://some_url.com"
[project.scripts]
nectarserver = "entry-point-script"
[tool.tox]
legacy_tox_ini = """
[tox]
min_version = 4.0
env_list = test_env
[testenv]
deps = pytest
commands = pytest -s
"""
I also tried test
and tests
instead of dev
when trying to get this to work.
I'm running into two issues:
- When I run
pip install -e .
,tox
is not installed - The
requires.txt
generated by theinstall
command ends up having a[dev]
section in it, which causespip install -r mypackage/mypackage.egg-info/requires.txt
to error out. This causes other issues down the road in my build chain, which relies on requirements.txt files generated during the build to generate a Docker layer with project dependencies in it.
How should I capture the dev only dependency on tox
in my pyproject.toml
?
答案1
得分: 10
额外依赖 对于本地包与 PyPI 上的包的工作方式相同;请尝试
pip install -e .[dev]
英文:
Extra dependencies work the same for local packages as they do for packages on PyPI; try
pip install -e .[dev]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论