简体   繁体   中英

Specifying test dependencies in pyproject.toml and getting them installed with pip install -e

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 the install command ends up having a [dev] section in it, which causes pip 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 ?

Extra dependencies work the same for local packages as they do for packages on PyPI; try

pip install -e .[dev]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM