[tox] minversion=4.4 toxworkdir=.tox skipsdist=True envlist = py{37,38,39,310}-{cov,nocov} code-linters # Default testenv. Used to run tests on all python versions. [testenv] passenv = CI GITHUB_* deps = -rtest/unit/requirements.txt py{37,38,39,310}: pytest-asyncio setenv = PYTHONPATH = \ {toxinidir}/cookbooks/aws-parallelcluster-platform/files/dcv:\ {toxinidir}/cookbooks/aws-parallelcluster-environment/files/cloudwatch:\ {toxinidir}/cookbooks/aws-parallelcluster-computefleet/files/compute_fleet_status:\ {toxinidir}/cookbooks/aws-parallelcluster-computefleet/files/clusterstatusmgtd:\ {toxinidir}/cookbooks/aws-parallelcluster-environment/files/custom_action_executor:\ {toxinidir}/cookbooks/aws-parallelcluster-environment/files/default/ec2_udev_rules:\ {toxinidir}/cookbooks/aws-parallelcluster-slurm/files/default/head_node_slurm/slurm:\ {toxinidir}/cookbooks/aws-parallelcluster-slurm/files/default/config_slurm/scripts commands = nocov: pytest -l -v --basetemp={envtmpdir} --html=report.html {[vars]test_dirs} cov: pytest -l -v --basetemp={envtmpdir} --html=report.html --cov-report=xml --cov={[vars]cov_dirs} --cov-append {[vars]test_dirs} # Section used to define common variables used by multiple testenvs. [vars] src_dirs = {toxinidir}/cookbooks/aws-parallelcluster-environment/files/cloudwatch \ {toxinidir}/cookbooks/aws-parallelcluster-platform/files/dcv \ {toxinidir}/cookbooks/aws-parallelcluster-computefleet/files/compute_fleet_status \ {toxinidir}/cookbooks/aws-parallelcluster-computefleet/files/clusterstatusmgtd \ {toxinidir}/cookbooks/aws-parallelcluster-environment/files/custom_action_executor \ {toxinidir}/cookbooks/aws-parallelcluster-environment/files/default/ec2_udev_rules \ {toxinidir}/cookbooks/aws-parallelcluster-slurm/files/default/head_node_slurm \ {toxinidir}/cookbooks/aws-parallelcluster-slurm/files/default/config_slurm/scripts cov_dirs = {toxinidir}/cookbooks/ test_dirs = {toxinidir}/test/unit/ code_dirs = {[vars]src_dirs} {[vars]test_dirs} ############################## ### AUTO-FORMATTER ### ############################## # black is a code formatter for python: https://github.com/ambv/black. # The following target formats python files with black formatter. [testenv:black] basepython = python3 skip_install = true deps = black commands = black -l 120 \ {[vars]code_dirs} \ {posargs} # Checks that python files are correctly formatted. [testenv:black-check] basepython = python3 skip_install = true deps = {[testenv:black]deps} commands = {[testenv:black]commands} --check --diff # isort is an imports sorter for python: https://github.com/timothycrosley/isort # The following target sorts the import according to .isort.cfg file. # Pin isort to the last release prior to 5.0.0, which resulted in import # statements being flagged as improperly sorted where previously they were # not. See https://timothycrosley.github.io/isort/docs/major_releases/introducing_isort_5/. [testenv:isort] basepython = python3 skip_install = true deps = isort seed-isort-config commands = isort -w 120 \ {[vars]code_dirs} \ {posargs} # Checks that python imports are correctly sorted. [testenv:isort-check] basepython = python3 skip_install = true deps = {[testenv:isort]deps} commands = {[testenv:isort]commands} --check --diff # Reformats code with black and isort. [testenv:autoformat] basepython = python3 skip_install = true deps = {[testenv:isort]deps} {[testenv:black]deps} commands = {[testenv:isort]commands} {[testenv:black]commands} ############################# ### LINTERS ### ############################# # flake8 python linter: https://github.com/PyCQA/flake8. # flake8 config is located in .flake8 file [testenv:flake8] basepython = python3 skip_install = true deps = flake8 flake8-docstrings flake8-bugbear flake8-mypy # flake8-import-order # delegated to isort flake8-colors pep8-naming commands = flake8 \ {[vars]code_dirs} \ {posargs} # bandit security linter for python: https://github.com/PyCQA/bandit [testenv:bandit] basepython = python3 skip_install = true deps = bandit commands = bandit -r \ -c .bandit.ini \ {[vars]code_dirs} \ {posargs} # Pylint linter for python: https://www.pylint.org/ # Pylint config is located in .pylintrc file. [testenv:pylint] basepython = python3 deps = pyflakes pylint commands = pylint \ --recursive=y \ {[vars]code_dirs} \ {posargs} # Vulture finds unused code in python: https://github.com/jendrikseipp/vulture [testenv:vulture] basepython = python3 skip_install = true deps = vulture commands = vulture \ {[vars]code_dirs} \ {posargs} # Static type checker for Python: http://mypy-lang.org/ [testenv:mypy] basepython = python3 deps = mypy commands = mypy \ {[vars]code_dirs} \ {posargs} # semgrep is used to check for security issues # https://semgrep.dev/ [testenv:semgrep] basepython = python3 deps = semgrep>=1.8.0 commands = semgrep \ --config p/r2c-security-audit \ --config p/secrets \ --exclude 'cookbooks/third-party/**' \ --exclude 'files/default/jq-*' \ --exclude 'files/default/*.tar.gz' \ --error # Target that groups all code linters to run in CI [testenv:code-linters] basepython = python3 skip_install = true deps = {[testenv:black-check]deps} {[testenv:isort-check]deps} {[testenv:flake8]deps} {[testenv:bandit]deps} {[testenv:semgrep]deps} {[testenv:pylint]deps} commands = {[testenv:black-check]commands} {[testenv:isort-check]commands} {[testenv:flake8]commands} {[testenv:bandit]commands} {[testenv:semgrep]commands} {[testenv:pylint]commands}