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
?