Skip to content

tox4: Support constraints.txt for package dependencies #1939

@loechel

Description

@loechel

if you have a python package to test with tox and using a constraints.txt to pin versions for specific dependencies tox4 will read the constraints.txt and add each line to the pip install command as a dependency.

Following https://tox.readthedocs.io/en/latest/example/basic.html#depending-on-requirements-txt-or-defining-constraints is misleading or wrong at that moment.

tox.ini

[tox]
envlist =
    py36,
    py37,
    py38,
    py39,
    docs,
    isort,
    lint,
    coverage,

skip_missing_interpreters = False

[testenv]
usedevelop = True
extras =
    test

commands =
    python -VV
    pip list
    pytest --cov=src --cov=tests --cov-report=xml --html=_build/pytest/report-{envname}.html --self-contained-html {posargs}

setenv =
  COVERAGE_FILE=.coverage.{envname}

deps =
    -cconstraints.txt
    pytest-cov
    pytest-html

constraints.txt

# Constraints for Python Packages
# -----------------------------------------------
# Pin Versions / Version Ranges if necessary.

pytest > 6

results in an output line:

py36: 14582 W install_deps> python -I -m pip install pytest-cov pytest-html 'pytest>6' [tox/tox_env/api.py:288]

For

deps =
    -requirements.txt
    -cconstraints.txt
    pytest-cov
    pytest-html

suggested or expected command should be:

python -I -m pip install -U -r requirements.txt -c constraints.txt listeded-dependencies

or even better to read:

python -I -m pip install --upgrade --requirement requirements.txt --constraint constraints.txt listeded-dependencies

Background:
Constraints files may specify version pins or ranges for packages that might be used in this context. Those packages could be optional. In contrast to requirement files, where all declared packages are dependencies and must be met / installed with the specified pinned version.

Constraints files may be used as a definition of known good version set that works with a specific major release of a package.

Example:

[tox]
envlist =
    py{36,37,38,39}-MyProduct{4.0,4.1,4.2,5.0},
    docs,
    isort,
    lint,
    coverage,

[testenv]
usedevelop = True
extras =
    test

commands =
    python -VV
    pip list
    pytest --cov=src --cov=tests --cov-report=xml --html=_build/pytest/report-{envname}.html --self-contained-html {posargs}

setenv =
  COVERAGE_FILE=.coverage.{envname}

deps =
    -chttps://myproduct-index-server/releases/{envname}/constraints.txt
    MyProduct

Metadata

Metadata

Assignees

Labels

bug:normalaffects many people or has quite an impactfeature:newsomething does not exist yet, but should

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions