Skip to content
Snippets Groups Projects
Commit 20786bbd authored by Hannes Feldt's avatar Hannes Feldt
Browse files

migrate tox.ini to toml

parent 1e2f45fa
No related branches found
No related tags found
1 merge request!33Add pre-commit hook and improve with better linting
Pipeline #101368 failed
Pipeline: Python Package

#101369

    This commit is part of merge request !33. Comments created here will be created in the context of that merge request.
    ...@@ -25,7 +25,7 @@ build-template: ...@@ -25,7 +25,7 @@ build-template:
    - git add . - git add .
    - git commit -m 'Test' - git commit -m 'Test'
    - git remote add origin git@git.astron.nl:templates/python-package-test - git remote add origin git@git.astron.nl:templates/python-package-test
    - git push --dry-run -u origin test - git push --dry-run -u origin main
    - rm -r .venv - rm -r .venv
    - rm -r .git - rm -r .git
    # cannot use needs, for artifacts on child pipeline so must regenerate template! # cannot use needs, for artifacts on child pipeline so must regenerate template!
    ......
    ...@@ -12,11 +12,6 @@ repos: ...@@ -12,11 +12,6 @@ repos:
    - id: check-yaml - id: check-yaml
    - id: check-toml - id: check-toml
    - id: detect-private-key - id: detect-private-key
    - repo: https://github.com/tox-dev/tox-ini-fmt
    rev: "1.4.1"
    hooks:
    - id: tox-ini-fmt
    args: ["-p", "fix"]
    - repo: local - repo: local
    hooks: hooks:
    - id: tox-black - id: tox-black
    ......
    ...@@ -11,3 +11,69 @@ version_file = "{{cookiecutter.project_slug}}/_version.py" ...@@ -11,3 +11,69 @@ version_file = "{{cookiecutter.project_slug}}/_version.py"
    [tool.pylint] [tool.pylint]
    ignore = "_version.py" ignore = "_version.py"
    [tool.tox]
    # Generative environment list to test all supported Python versions
    requires = ["tox>=4.21"]
    env_list = ["fix", "pep8", "black", "pylint", "py{13, 12, 11, 10, 9}"]
    [tool.tox.env_run_base]
    package = "editable"
    deps = [
    "-r{toxinidir}/requirements.txt",
    "-r{toxinidir}/tests/requirements.txt"]
    set_env = { LANGUAGE = "en_US", LC_ALL = "en_US.UTF-8", PYTHONWARNINGS = "default::DeprecationWarning" }
    commands = [["python", "--version"], ["python", "-m", "pytest"]]
    [tool.tox.env.fix]
    description = "format the code base to adhere to our styles, and complain about what we cannot do automatically"
    skip_install = true
    deps = ["pre-commit-uv>=4.1.1"]
    commands = [["pre-commit", "run", "--all-files", "--show-diff-on-failure"]]
    [tool.tox.env.coverage]
    commands = [
    ["python", "--version"],
    ["python", "-m", "pytest", "--cov-report", "term", "--cov-report", "xml", "--cov-report", "html", "--cov={{cookiecutter.project_slug}}"]]
    # Command prefixes to reuse the same virtualenv for all linting jobs.
    [tool.tox.env.pep8]
    commands = [
    ["python", "-m", "flake8", "--version"],
    ["python", "-m", "flake8", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }]
    ]
    [tool.tox.env.black]
    commands = [
    ["python", "-m", "black", "--version"],
    ["python", "-m", "black", "--check", "--diff", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }]
    ]
    [tool.tox.env.pylint]
    commands = [
    ["python", "-m", "pylint", "--version"],
    ["python", "-m", "pylint", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }]
    ]
    [tool.tox.env.format]
    commands = [
    ["python", "-m", "autopep8", "-v", "-aa", "--in-place", "--recursive", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }],
    ["python", "-m", "black", "-v", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }]
    ]
    [tool.tox.env.docs]
    deps = [
    "-r{toxinidir}/requirements.txt",
    "-r{toxinidir}/docs/requirements.txt"]
    # unset LC_ALL / LANGUAGE from testenv, would fail sphinx otherwise
    set_env = ""
    changedir = "{tox_root}"
    commands = [
    ["python", "docs/cleanup.py"],
    ["sphinx-build", "-b", "html", "docs/source", "docs/build/html"]
    ]
    [tool.tox.env.build]
    package = "wheel"
    deps = ["build"]
    commands = [["python", "-m", "build"]]
    # Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy)
    # SPDX-License-Identifier: Apache-2.0
    """ Setuptools entry point """
    import setuptools import setuptools
    setuptools.setup() setuptools.setup()
    [tox]
    # Generative environment list to test all supported Python versions
    requires =
    tox>=4.21
    env_list =
    fix
    pep8
    black
    pylint
    py3{13, 12, 11, 10, 9}
    [testenv]
    package = editable
    wheel_build_env = .pkg
    deps =
    -r{toxinidir}/requirements.txt
    -r{toxinidir}/tests/requirements.txt
    setenv =
    LANGUAGE = en_US
    LC_ALL = en_US.UTF-8
    PYTHONWARNINGS = default::DeprecationWarning
    commands =
    {envpython} --version
    {envpython} -m pytest
    [testenv:fix]
    description = format the code base to adhere to our styles, and complain about what we cannot do automatically
    skip_install = true
    deps =
    pre-commit-uv>=4.1.1
    commands =
    pre-commit run --all-files --show-diff-on-failure
    [testenv:coverage]
    commands =
    {envpython} --version
    {envpython} -m pytest --cov-report term --cov-report xml --cov-report html --cov={{cookiecutter.project_slug}}
    # Use generative name and command prefixes to reuse the same virtualenv
    # for all linting jobs.
    [testenv:{pep8,black,pylint,format}]
    commands =
    pep8: {envpython} -m flake8 --version
    pep8: {envpython} -m flake8 {posargs:{{cookiecutter.project_slug}} tests}
    black: {envpython} -m black --version
    black: {envpython} -m black --check --diff {posargs:{{cookiecutter.project_slug}} tests}
    pylint: {envpython} -m pylint --version
    pylint: {envpython} -m pylint {posargs:{{cookiecutter.project_slug}} tests}
    format: {envpython} -m autopep8 -v -aa --in-place --recursive {posargs:{{cookiecutter.project_slug}}}
    format: {envpython} -m autopep8 -v -aa --in-place --recursive {posargs:tests}
    format: {envpython} -m black -v {posargs:{{cookiecutter.project_slug}} tests}
    envdir = {toxworkdir}/linting
    [testenv:docs]
    deps =
    -r{toxinidir}/requirements.txt
    -r{toxinidir}/docs/requirements.txt
    ; unset LC_ALL / LANGUAGE from testenv, would fail sphinx otherwise
    setenv =
    changedir = {toxinidir}
    commands =
    {envpython} docs/cleanup.py
    sphinx-build -b html docs/source docs/build/html
    [testenv:build]
    deps =
    build
    commands =
    {envpython} -m build
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment