[英]Specifying test dependencies in pyproject.toml and getting them installed with pip install -e
我有一個 Python 項目,其中的pyproject.toml
類似於下面的項目。 我使用python build
生成一個 package 我用來在生產環境中安裝。 對於開發環境,我使用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
的開發唯一依賴?
額外的依賴關系對本地包的作用與對 PyPI 上的包的作用相同; 嘗試
pip install -e .[dev]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.