diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index e649636316..1e42453e4a 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -30,7 +30,6 @@ jobs: docs pkg eco - py311-devel build: name: ${{ matrix.name }} @@ -155,7 +154,7 @@ jobs: - name: Check for expected number of coverage.xml reports run: | - JOBS_PRODUCING_COVERAGE=4 + JOBS_PRODUCING_COVERAGE=3 if [ "$(find . -name coverage.xml | wc -l | bc)" -ne "${JOBS_PRODUCING_COVERAGE}" ]; then echo "::error::Number of coverage.xml files was not the expected one (${JOBS_PRODUCING_COVERAGE}): $(find . -name coverage.xml |xargs echo)" exit 1 diff --git a/.gitignore b/.gitignore index bebe48b307..6df1471c9d 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ site src/molecule/_version.py .vscode test/resources/.extensions/ +venv diff --git a/pyproject.toml b/pyproject.toml index 89414d0cf4..295b1fe2a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,19 +54,20 @@ default = "molecule.driver.delegated:Delegated" testinfra = "molecule.verifier.testinfra:Testinfra" ansible = "molecule.verifier.ansible:Ansible" -[tool.coverage.run] -source = ["src"] -# branch = true -parallel = true -concurrency = ["multiprocessing", "thread"] -data_file = ".tox/.coverage" -relative_files = true - [tool.coverage.report] -exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"] -omit = ["test/*"] +exclude_also = ["if TYPE_CHECKING:", "pragma: no cover"] fail_under = 88 +ignore_errors = true +show_missing = true skip_covered = true +skip_empty = true +sort = "Cover" + +[tool.coverage.run] +branch = false # https://github.com/nedbat/coveragepy/issues/605 +concurrency = ["multiprocessing", "thread"] +parallel = true +source_pkgs = ["molecule"] [tool.black] skip-string-normalization = false diff --git a/tox.ini b/tox.ini index 57e863b6e4..13357249bd 100644 --- a/tox.ini +++ b/tox.ini @@ -1,145 +1,113 @@ [tox] -minversion = 4.2.2 -envlist = - lint +requires = + tox>=4.11.3 +env_list = + py + deps docs + lint + milestone pkg - # do not put specific python versions here, but use them when calling tox - py - py-{devel} - -# do not enable skip missing to avoid CI false positives -skip_missing_interpreters = False -isolated_build = True + eco +skip_missing_interpreters = true [testenv] -# both options needed to workaround https://github.com/tox-dev/tox/issues/2197 -usedevelop = true -skip_install = false - -commands_pre = - sh -c "rm -f {envdir}/.coverage.* 2>/dev/null || true" -commands = - ansibledevel: ansible-galaxy install git+https://github.com/ansible-collections/community.general.git - # failsafe as pip may install incompatible dependencies - pip check - # failsafe for preventing changes that may break pytest collection - sh -c "PYTEST_ADDOPTS= python3 -m pytest -p no:cov --collect-only >>/dev/null" - # html report is used by Zuul CI to display reports - coverage run -m pytest {env:_EXTRAS} {env:PYTEST_ADDOPTS:} {posargs} - sh -c "coverage combine -a -q --data-file={envdir}/.coverage {toxworkdir}/*/.coverage.* && coverage xml --data-file={envdir}/.coverage -o {envdir}/coverage.xml --fail-under=0" -passenv = +description = Run pytest under {basepython} +package = editable +extras = + test +pass_env = CI CONTAINER_* - DISPLAY DOCKER_* GITHUB_* HOME - PIP_* - PODMAN_* - PUBLISH PYTEST_* SSH_AUTH_SOCK TERM -setenv = - ANSIBLE_CONFIG={toxinidir}/.ansible.cfg - ANSIBLE_DISPLAY_FAILED_STDERR=1 - ANSIBLE_NOCOWS=1 - ANSIBLE_VERBOSITY=1 - COVERAGE_FILE = {env:COVERAGE_FILE:{envdir}/.coverage.{envname}} - COVERAGE_PROCESS_START={toxinidir}/pyproject.toml - MOLECULE_NO_LOG=0 - PIP_CONSTRAINT = {toxinidir}/.config/constraints.txt - lint,devel,deps,pkg,pre,ansibledevel: PIP_CONSTRAINT = /dev/null - PIP_DISABLE_PIP_VERSION_CHECK=1 - PYTHONDONTWRITEBYTECODE=1 - PYTHONUNBUFFERED=1 - # Temporare remove "-n auto" as it seems to break coverage on this project. - _EXTRAS=-l -deps = - devel: git+https://github.com/ansible/ansible#egg=ansible-core - # pytest-molecule not used but we want to check that it does not conflict - devel: git+https://github.com/ansible-community/pytest-molecule#egg=pytest-molecule -extras = - test + USER +set_env = + !milestone: PIP_CONSTRAINT = {toxinidir}/.config/constraints.txt + COVERAGE_COMBINED = {envdir}/.coverage + COVERAGE_FILE = {env:COVERAGE_FILE:{envdir}/.coverage.{envname}} + COVERAGE_PROCESS_START = {toxinidir}/pyproject.toml + FORCE_COLOR = 1 + PRE_COMMIT_COLOR = always + TERM = xterm-256color +commands_pre = + sh -c "rm -f {envdir}/.coverage* 2>/dev/null || true" +commands = + python -c 'import pathlib; pathlib.Path("{env_site_packages_dir}/cov.pth").write_text("import coverage; coverage.process_startup()")' + coverage run -m pytest {posargs:-n auto} + coverage combine -q --data-file={env:COVERAGE_COMBINED} + coverage xml --data-file={env:COVERAGE_COMBINED} -o {envdir}/coverage.xml --fail-under=0 + coverage lcov --data-file={env:COVERAGE_COMBINED} -o {toxinidir}/.coverage/lcov.info --fail-under=0 + coverage report --data-file={env:COVERAGE_COMBINED} allowlist_externals = - bash - find + git rm sh [testenv:deps] -description = Bump all test dependencies -# we reuse the lint environment -envdir = {toxworkdir}/lint +description = Bump all dependencies +base_python = python3.10 skip_install = true -basepython = python3.10 deps = - {[testenv:lint]deps} -setenv = - # without his upgrade would likely not do anything - PIP_CONSTRAINT = /dev/null + {[testenv:lint]deps} +extras = +set_env = + PIP_CONSTRAINT = /dev/null commands_pre = commands = - -pre-commit run --all-files --show-diff-on-failure --hook-stage manual lock - -pre-commit run --all-files --show-diff-on-failure --hook-stage manual up - # Update pre-commit hooks - -pre-commit autoupdate - # We fail if files are modified at the end - git diff --exit-code - -[testenv:lint] -description = Runs all linting tasks -# python pinned in order to have pip-compile output reproducible -basepython = python3.10 -commands = - # to run a single linter you can do "pre-commit run flake8" - python3 -m pre_commit run {posargs:--all --show-diff-on-failure} -deps = - pre-commit>=2.21.0 - check-jsonschema>=0.20.0 - jsonschema>=4.17.3 -setenv = - {[testenv]setenv} -skip_install = true -usedevelop = false + -pre-commit run --all-files --show-diff-on-failure --hook-stage manual deps + -pre-commit autoupdate + git diff --exit-code +env_dir = {toxworkdir}/lint [testenv:docs] -description = Build documentation -passenv = * -usedevelop = true -commands = - linkchecker -q -f linkcheckerrc docs - mkdocs {posargs:build -c --strict} +description = Builds docs +package = editable +skip_install = false extras = docs +set_env = + NO_COLOR = 1 + TERM = dump +commands = + mkdocs build {posargs:} + +[testenv:lint] +description = Enforce quality standards under {basepython} +skip_install = true +deps = + pre-commit +set_env = + PIP_CONSTRAINT = /dev/null +commands = + pre-commit run --show-diff-on-failure --all-files + +[testenv:milestone] +description = + Run tests with ansible-core milestone branch and without dependencies constraints +deps = + ansible-core@ https://github.com/ansible/ansible/archive/milestone.tar.gz +set_env = + {[testenv]set_env} + PIP_CONSTRAINT = /dev/null [testenv:pkg] description = - Do packaging/distribution. If tag is not present or PEP440 compliant upload to - PYPI could fail -# `usedevelop = true` overrides `skip_install` instruction, it's unwanted -usedevelop = false -# don't install molecule itself in this env + Do packaging/distribution skip_install = true deps = - build >= 0.9.0 + build>=0.9 twine >= 4.0.2 # pyup: ignore -setenv = +set_env = commands = rm -rfv {toxinidir}/dist/ - python3 -m build \ - --outdir {toxinidir}/dist/ \ - {toxinidir} - # metadata validation - sh -c "python3 -m twine check --strict {toxinidir}/dist/*" + python -m build --outdir {toxinidir}/dist/ {toxinidir} + sh -c "python -m twine check --strict {toxinidir}/dist/*" -[testenv:snap] -description = Builds a snap package -usedevelop = false -skip_install = true -commands = - sh -c "type snapcraft && snapcraft build" [testenv:eco] description = Smoketest of combining all known to be maintained plugins (ecosystem) @@ -162,15 +130,4 @@ commands = pipdeptree --reverse -e pip,pbr,six,setuptools,toml,urllib3 molecule --version molecule drivers - bash ./tools/smoketest.sh - -[testenv:coverage] -description = Combines and displays coverage results -commands = - -sh -c "coverage combine --append .tox/.coverage.*" - # needed by codecov github actions: - coverage xml -i - # just for humans running it: - coverage report -i -deps = - coverage[toml] + sh -c ./tools/smoketest.sh