mirror of
https://github.com/certbot/certbot.git
synced 2026-06-05 06:42:10 -04:00
Fixes #8425 This PR upgrades mypy to the latest version available, 0.812. Given the advanced type inference capabilities provided by this newer version, this PRs also fixes various type inconsistencies that are now detected. Here are the non obvious changes done to fix types: * typing in mixins has been solved using `Protocol` classes, as recommended by mypy (https://mypy.readthedocs.io/en/latest/more_types.html#mixin-classes, https://mypy.readthedocs.io/en/stable/protocols.html) * `cast` when we are playing with `Union` types This PR also disables the strict optional checks that have been enable by default in recent versions of mypy. Once this PR is merged, I will create an issue to study how these checks can be enabled. `typing.Protocol` is available only since Python 3.8. To keep compatibility with Python 3.6, I try to import the class `Protocol` from `typing`, and fallback to assign `object` to `Protocol` if that fails. This way the code is working with all versions of Python, but the mypy check can be run only with Python 3.8+ because it needs the protocol feature. As a consequence, tox runs mypy under Python 3.8. Alternatives are: * importing `typing_extensions`, that proposes backport of newest typing features to Python 3.6, but this implies to add a dependency to Certbot just to run mypy * redesign the concerned classes to not use mixins, or use them differently, but this implies to modify the code itself even if there is nothing wrong with it and it is just a matter of instructing mypy to understand in which context the mixins can be used * ignoring type for these classes with `# type: ignore` but we loose the benefit of mypy for them * Upgrade mypy * First step for acme * Cast for the rescue * Fixing types for certbot * Fix typing for certbot-nginx * Finalize type fixes, configure no optional strict check for mypy in tox * Align requirements * Isort * Pylint * Protocol for python 3.6 * Use Python 3.9 for mypy, make code compatible with Python 3.8< * Pylint and mypy * Pragma no cover * Pythonic NotImplemented constant * More type definitions * Add comments * Simplify typing logic * Use vararg tuple * Relax constraints on mypy * Add more type * Do not silence error if target is not defined * Conditionally import Protocol for type checking only * Clean up imports * Add comments * Align python version linting with mypy and coverage * Just ignore types in an unused module * Add comments * Fix lint
315 lines
11 KiB
INI
315 lines
11 KiB
INI
# Tox (https://tox.readthedocs.io/) is a tool for running tests in
|
|
# multiple virtualenvs. To use it, "pip install tox" and then run
|
|
# "tox" from this directory.
|
|
|
|
[tox]
|
|
skipsdist = true
|
|
envlist = modification,py3-cover,lint,mypy
|
|
|
|
[base]
|
|
# pip installs the requested packages in editable mode
|
|
pip_install = python {toxinidir}/tools/pip_install_editable.py
|
|
# pip installs the requested packages in editable mode and runs unit tests on
|
|
# them. Each package is installed and tested in the order they are provided
|
|
# before the script moves on to the next package. All dependencies are pinned
|
|
# to a specific version for increased stability for developers.
|
|
install_and_test = python {toxinidir}/tools/install_and_test.py
|
|
dns_packages =
|
|
certbot-dns-cloudflare \
|
|
certbot-dns-cloudxns \
|
|
certbot-dns-digitalocean \
|
|
certbot-dns-dnsimple \
|
|
certbot-dns-dnsmadeeasy \
|
|
certbot-dns-gehirn \
|
|
certbot-dns-google \
|
|
certbot-dns-linode \
|
|
certbot-dns-luadns \
|
|
certbot-dns-nsone \
|
|
certbot-dns-ovh \
|
|
certbot-dns-rfc2136 \
|
|
certbot-dns-route53 \
|
|
certbot-dns-sakuracloud
|
|
all_packages =
|
|
acme[dev] \
|
|
certbot[dev] \
|
|
certbot-apache \
|
|
{[base]dns_packages} \
|
|
certbot-nginx
|
|
install_packages =
|
|
python {toxinidir}/tools/pip_install_editable.py {[base]all_packages}
|
|
source_paths =
|
|
acme/acme
|
|
certbot/certbot
|
|
certbot-ci/certbot_integration_tests
|
|
certbot-apache/certbot_apache
|
|
certbot-compatibility-test/certbot_compatibility_test
|
|
certbot-dns-cloudflare/certbot_dns_cloudflare
|
|
certbot-dns-cloudxns/certbot_dns_cloudxns
|
|
certbot-dns-digitalocean/certbot_dns_digitalocean
|
|
certbot-dns-dnsimple/certbot_dns_dnsimple
|
|
certbot-dns-dnsmadeeasy/certbot_dns_dnsmadeeasy
|
|
certbot-dns-gehirn/certbot_dns_gehirn
|
|
certbot-dns-google/certbot_dns_google
|
|
certbot-dns-linode/certbot_dns_linode
|
|
certbot-dns-luadns/certbot_dns_luadns
|
|
certbot-dns-nsone/certbot_dns_nsone
|
|
certbot-dns-ovh/certbot_dns_ovh
|
|
certbot-dns-rfc2136/certbot_dns_rfc2136
|
|
certbot-dns-route53/certbot_dns_route53
|
|
certbot-dns-sakuracloud/certbot_dns_sakuracloud
|
|
certbot-nginx/certbot_nginx
|
|
tests/lock_test.py
|
|
|
|
[testenv]
|
|
passenv =
|
|
CERTBOT_NO_PIN
|
|
commands_pre = python {toxinidir}/tools/pipstrap.py
|
|
commands =
|
|
!cover: {[base]install_and_test} {[base]all_packages}
|
|
!cover: python tests/lock_test.py
|
|
cover: {[base]install_packages}
|
|
cover: {[base]pip_install} certbot-apache[dev]
|
|
cover: python tox.cover.py
|
|
# We always recreate the virtual environment to avoid problems like
|
|
# https://github.com/certbot/certbot/issues/7745.
|
|
recreate = true
|
|
setenv =
|
|
PYTEST_ADDOPTS = {env:PYTEST_ADDOPTS:--numprocesses auto}
|
|
PYTHONHASHSEED = 0
|
|
|
|
[testenv:oldest]
|
|
# Setting basepython allows the tests to fail fast if that version of Python
|
|
# isn't available instead of potentially trying to use a newer version of
|
|
# Python which is unlikely to work.
|
|
basepython = python3.6
|
|
commands =
|
|
{[testenv]commands}
|
|
setenv =
|
|
{[testenv]setenv}
|
|
CERTBOT_OLDEST=1
|
|
|
|
[testenv:acme-oldest]
|
|
basepython =
|
|
{[testenv:oldest]basepython}
|
|
commands =
|
|
{[base]install_and_test} acme[dev]
|
|
setenv =
|
|
{[testenv:oldest]setenv}
|
|
|
|
[testenv:apache-oldest]
|
|
basepython =
|
|
{[testenv:oldest]basepython}
|
|
commands =
|
|
{[base]install_and_test} certbot-apache
|
|
setenv =
|
|
{[testenv:oldest]setenv}
|
|
|
|
[testenv:apache-v2-oldest]
|
|
basepython =
|
|
{[testenv:oldest]basepython}
|
|
commands =
|
|
{[base]install_and_test} certbot-apache[dev]
|
|
setenv =
|
|
{[testenv:oldest]setenv}
|
|
|
|
[testenv:certbot-oldest]
|
|
basepython =
|
|
{[testenv:oldest]basepython}
|
|
commands =
|
|
{[base]install_and_test} certbot[dev]
|
|
setenv =
|
|
{[testenv:oldest]setenv}
|
|
|
|
[testenv:dns-oldest]
|
|
basepython =
|
|
{[testenv:oldest]basepython}
|
|
commands =
|
|
{[base]install_and_test} {[base]dns_packages}
|
|
setenv =
|
|
{[testenv:oldest]setenv}
|
|
|
|
[testenv:nginx-oldest]
|
|
basepython =
|
|
{[testenv:oldest]basepython}
|
|
commands =
|
|
{[base]install_and_test} certbot-nginx
|
|
python tests/lock_test.py
|
|
setenv =
|
|
{[testenv:oldest]setenv}
|
|
|
|
[testenv:external-mock]
|
|
commands =
|
|
python {toxinidir}/tools/pip_install.py mock
|
|
{[base]install_and_test} {[base]all_packages}
|
|
|
|
[testenv:lint]
|
|
basepython = python3
|
|
# separating into multiple invocations disables cross package
|
|
# duplicate code checking; if one of the commands fails, others will
|
|
# continue, but tox return code will reflect previous error
|
|
commands =
|
|
{[base]install_packages}
|
|
python -m pylint --reports=n --rcfile=.pylintrc {[base]source_paths}
|
|
|
|
// TODO: Re-enable strict checks for optionals with appropriate type corrections or code redesign.
|
|
[testenv:mypy]
|
|
basepython = python3
|
|
commands =
|
|
{[base]install_packages}
|
|
mypy --no-strict-optional {[base]source_paths}
|
|
|
|
[testenv:apacheconftest]
|
|
commands =
|
|
{[base]pip_install} acme certbot certbot-apache
|
|
{toxinidir}/certbot-apache/tests/apache-conf-files/apache-conf-test --debian-modules
|
|
passenv =
|
|
SERVER
|
|
|
|
[testenv:apacheconftest-external-with-pebble]
|
|
# Run apacheconftest with pebble and Certbot outside of tox's virtual
|
|
# environment.
|
|
commands =
|
|
{[base]pip_install} certbot-ci
|
|
{toxinidir}/certbot-apache/tests/apache-conf-files/apache-conf-test-pebble.py --debian-modules
|
|
|
|
[testenv:apacheconftest-with-pebble]
|
|
commands =
|
|
{[base]pip_install} acme certbot certbot-apache
|
|
{[testenv:apacheconftest-external-with-pebble]commands}
|
|
|
|
[testenv:nginxroundtrip]
|
|
commands =
|
|
{[base]pip_install} acme certbot certbot-apache certbot-nginx
|
|
python certbot-compatibility-test/nginx/roundtrip.py certbot-compatibility-test/nginx/nginx-roundtrip-testdata
|
|
|
|
# This is a duplication of the command line in testenv:le_auto to
|
|
# allow users to run the modification check by running `tox`
|
|
[testenv:modification]
|
|
commands =
|
|
python {toxinidir}/tests/modification-check.py
|
|
passenv = TARGET_BRANCH
|
|
|
|
[testenv:apache_compat]
|
|
commands =
|
|
docker build -t certbot-compatibility-test -f certbot-compatibility-test/Dockerfile .
|
|
docker build -t apache-compat -f certbot-compatibility-test/Dockerfile-apache .
|
|
docker run --rm -t apache-compat -c apache.tar.gz -vvvv
|
|
whitelist_externals =
|
|
docker
|
|
passenv =
|
|
DOCKER_*
|
|
|
|
[testenv:nginx_compat]
|
|
commands =
|
|
docker build -t certbot-compatibility-test -f certbot-compatibility-test/Dockerfile .
|
|
docker build -t nginx-compat -f certbot-compatibility-test/Dockerfile-nginx .
|
|
docker run --rm -t nginx-compat -c nginx.tar.gz -vv -aie
|
|
whitelist_externals =
|
|
docker
|
|
passenv =
|
|
DOCKER_*
|
|
|
|
[testenv:docker_dev]
|
|
# tests the Dockerfile-dev file to ensure development with it works
|
|
# as expected
|
|
commands =
|
|
docker-compose run --rm --service-ports development bash -c 'tox -e lint'
|
|
whitelist_externals =
|
|
docker-compose
|
|
passenv = DOCKER_*
|
|
|
|
[testenv:integration]
|
|
commands =
|
|
{[base]pip_install} acme certbot certbot-nginx certbot-ci
|
|
pytest certbot-ci/certbot_integration_tests \
|
|
--acme-server={env:ACME_SERVER:pebble} \
|
|
--cov=acme --cov=certbot --cov=certbot_nginx --cov-report= \
|
|
--cov-config=certbot-ci/certbot_integration_tests/.coveragerc
|
|
coverage report --include 'certbot/*' --show-missing --fail-under=65
|
|
coverage report --include 'certbot-nginx/*' --show-missing --fail-under=74
|
|
passenv = DOCKER_*
|
|
|
|
[testenv:integration-certbot]
|
|
commands =
|
|
{[base]pip_install} acme certbot certbot-ci
|
|
pytest certbot-ci/certbot_integration_tests/certbot_tests \
|
|
--acme-server={env:ACME_SERVER:pebble} \
|
|
--cov=acme --cov=certbot --cov-report= \
|
|
--cov-config=certbot-ci/certbot_integration_tests/.coveragerc
|
|
coverage report --include 'certbot/*' --show-missing --fail-under=62
|
|
|
|
[testenv:integration-dns-rfc2136]
|
|
commands =
|
|
{[base]pip_install} acme certbot certbot-dns-rfc2136 certbot-ci
|
|
pytest certbot-ci/certbot_integration_tests/rfc2136_tests \
|
|
--acme-server=pebble --dns-server=bind \
|
|
--numprocesses=1 \
|
|
--cov=acme --cov=certbot --cov=certbot_dns_rfc2136 --cov-report= \
|
|
--cov-config=certbot-ci/certbot_integration_tests/.coveragerc
|
|
coverage report --include 'certbot/*' --show-missing --fail-under=45
|
|
coverage report --include 'certbot-dns-rfc2136/*' --show-missing --fail-under=87
|
|
|
|
[testenv:integration-external]
|
|
# Run integration tests with Certbot outside of tox's virtual environment.
|
|
commands =
|
|
{[base]pip_install} certbot-ci
|
|
pytest certbot-ci/certbot_integration_tests \
|
|
--acme-server={env:ACME_SERVER:pebble}
|
|
passenv = DOCKER_*
|
|
|
|
[testenv:integration-certbot-oldest]
|
|
basepython =
|
|
{[testenv:oldest]basepython}
|
|
commands =
|
|
{[base]pip_install} certbot
|
|
{[base]pip_install} certbot-ci
|
|
pytest certbot-ci/certbot_integration_tests/certbot_tests \
|
|
--acme-server={env:ACME_SERVER:pebble}
|
|
passenv = DOCKER_*
|
|
setenv = {[testenv:oldest]setenv}
|
|
|
|
[testenv:integration-nginx-oldest]
|
|
basepython =
|
|
{[testenv:oldest]basepython}
|
|
commands =
|
|
{[base]pip_install} certbot-nginx
|
|
{[base]pip_install} certbot-ci
|
|
pytest certbot-ci/certbot_integration_tests/nginx_tests \
|
|
--acme-server={env:ACME_SERVER:pebble}
|
|
passenv = DOCKER_*
|
|
setenv = {[testenv:oldest]setenv}
|
|
|
|
[testenv:test-farm-tests-base]
|
|
changedir = tests/letstest
|
|
deps = -rtests/letstest/requirements.txt
|
|
passenv =
|
|
AWS_*
|
|
setenv = AWS_DEFAULT_REGION=us-east-1
|
|
|
|
[testenv:test-farm-apache2]
|
|
changedir = {[testenv:test-farm-tests-base]changedir}
|
|
commands = {toxinidir}/tools/retry.sh python multitester.py apache2_targets.yaml {env:AWS_EC2_PEM_FILE} SET_BY_ENV scripts/test_apache2.sh --repo {toxinidir}
|
|
deps = {[testenv:test-farm-tests-base]deps}
|
|
passenv = {[testenv:test-farm-tests-base]passenv}
|
|
setenv = {[testenv:test-farm-tests-base]setenv}
|
|
|
|
[testenv:test-farm-leauto-upgrades]
|
|
changedir = {[testenv:test-farm-tests-base]changedir}
|
|
commands = {toxinidir}/tools/retry.sh python multitester.py auto_targets.yaml {env:AWS_EC2_PEM_FILE} SET_BY_ENV scripts/test_leauto_upgrades.sh --repo {toxinidir}
|
|
deps = {[testenv:test-farm-tests-base]deps}
|
|
passenv = {[testenv:test-farm-tests-base]passenv}
|
|
setenv = {[testenv:test-farm-tests-base]setenv}
|
|
|
|
[testenv:test-farm-certonly-standalone]
|
|
changedir = {[testenv:test-farm-tests-base]changedir}
|
|
commands = {toxinidir}/tools/retry.sh python multitester.py auto_targets.yaml {env:AWS_EC2_PEM_FILE} SET_BY_ENV scripts/test_letsencrypt_auto_certonly_standalone.sh --repo {toxinidir}
|
|
deps = {[testenv:test-farm-tests-base]deps}
|
|
passenv = {[testenv:test-farm-tests-base]passenv}
|
|
setenv = {[testenv:test-farm-tests-base]setenv}
|
|
|
|
[testenv:test-farm-sdists]
|
|
changedir = {[testenv:test-farm-tests-base]changedir}
|
|
commands = {toxinidir}/tools/retry.sh python multitester.py targets.yaml {env:AWS_EC2_PEM_FILE} SET_BY_ENV scripts/test_sdists.sh --repo {toxinidir}
|
|
deps = {[testenv:test-farm-tests-base]deps}
|
|
passenv = {[testenv:test-farm-tests-base]passenv}
|
|
setenv = {[testenv:test-farm-tests-base]setenv}
|