From 95b37b6d0b76c81b29c39d96dc7908a92faf5811 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Wed, 2 Oct 2024 11:03:57 -0400 Subject: [PATCH] MAINT: Tox --- .github/workflows/pytest.yml | 65 +++++++++++++------- pyproject.toml | 31 +++++++++- tox.ini | 113 +++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+), 24 deletions(-) create mode 100644 tox.ini diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index f54f3074..2c38f1dc 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -2,15 +2,18 @@ name: Pytest on: push: - branches: [ '*' ] - tags: [ '*' ] + branches: ['*'] + tags: ['*'] pull_request: - branches: [ master, 'maint/*' ] + branches: [master, 'maint/*'] defaults: run: shell: bash +env: + FORCE_COLOR: true + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true @@ -19,32 +22,50 @@ permissions: contents: read jobs: - build: - if: "!contains(github.event.head_commit.message, '[skip ci]')" - runs-on: ubuntu-latest + test: + runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ['3.10', '3.11'] + os: ['ubuntu-latest'] + python-version: ['3.10', '3.11', '3.12'] + dependencies: ['latest', 'pre'] + include: + - os: ubuntu-latest + python-version: '3.10' + dependencies: 'min' + + env: + DEPENDS: ${{ matrix.dependencies }} steps: - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - uses: actions/checkout@v4 with: + submodules: recursive fetch-depth: 0 - - name: Install nibabies + - uses: actions/cache@v4 + with: + path: ~/.cache/templateflow + key: templateflow-v1 + - name: Install dependencies run: | - python -m venv /tmp/venv - source /tmp/venv/bin/activate - python -m pip install -U pip - python -m pip install ".[test]" - - name: Run Pytest + sudo apt update + sudo apt install -y --no-install-recommends graphviz + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Display Python version + run: python -c "import sys; print(sys.version)" + - name: Install tox run: | - source /tmp/venv/bin/activate - pytest -sv --doctest-modules --cov nibabies --cov-report xml nibabies - - name: Submit coverage - uses: codecov/codecov-action@v3 + python -m pip install --upgrade pip + python -m pip install tox tox-gh-actions + - name: Show tox config + run: tox c + - name: Run tox + run: tox -v --exit-and-dump-after 1200 + - uses: codecov/codecov-action@v4 with: - files: coverage.xml + file: coverage.xml + token: ${{ secrets.CODECOV_TOKEN }} + if: ${{ always() }} diff --git a/pyproject.toml b/pyproject.toml index 79dabaf6..741cd0d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,10 +71,11 @@ maint = [ "python-Levenshtein", ] test = [ - "coverage", + "coverage[toml]", "pytest", "pytest-cov", "pytest-env", + "pytest-xdist", ] telemetry = ["migas >= 0.4.0"] # Aliases @@ -120,8 +121,22 @@ per-file-ignores = [ ] [tool.pytest.ini_options] +minversion = "6" +testpaths = ["nibabies"] +log_cli_level = "INFO" +xfail_strict = true norecursedirs = [".git"] -addopts = "-svx --doctest-modules" +addopts = [ + "-svx", + "-ra", + "--strict-config", + "--strict-markers", + "--doctest-modules", + # Config pytest-cov + "--cov=nibabies", + "--cov-report=xml", + "--cov-config=pyproject.toml", +] doctest_optionflags = "ALLOW_UNICODE NORMALIZE_WHITESPACE ELLIPSIS" env = "PYTHONHASHSEED=0" filterwarnings = ["ignore::DeprecationWarning"] @@ -177,3 +192,15 @@ inline-quotes = "single" [tool.ruff.format] quote-style = "single" + +[tool.coverage.run] +branch = true +omit = [ + "*/_version.py" +] + +[tool.coverage.paths] +source = [ + "nibabies", + "**/site-packages/nibabies" +] diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..7b9fb682 --- /dev/null +++ b/tox.ini @@ -0,0 +1,113 @@ +[tox] +requires = + tox>=4 +envlist = + py3{10,11,12}-latest + py310-min + py3{10,11,12}-pre +skip_missing_interpreters = true + +# Configuration that allows us to split tests across GitHub runners effectively +[gh-actions] +python = + 3.10: py310 + 3.11: py311 + 3.12: py312 + +[gh-actions:env] +DEPENDS = + min: min + latest: latest + pre: pre + +[testenv] +description = Pytest with coverage +labels = test +pip_pre = + pre: true +pass_env = + # getpass.getuser() sources for Windows: + LOGNAME + USER + LNAME + USERNAME + # Pass user color preferences through + PY_COLORS + FORCE_COLOR + NO_COLOR + CLICOLOR + CLICOLOR_FORCE + PYTHON_GIL +extras = test +setenv = + pre: PIP_EXTRA_INDEX_URL=https://pypi.anaconda.org/scientific-python-nightly-wheels/simple +deps = + min: nibabel == 4.0.1 + min: nipype == 1.8.5 + min: nitransforms == 21.0.0 + min: numpy == 1.22 + min: psutil == 5.4 + min: pybids == 0.15.2 + min: tedana == 23.0.2 + min: templateflow == 24.1.0 + +commands_pre = + python scripts/fetch_templates.py +commands = + pytest --cov-report term-missing --durations=20 --durations-min=1.0 {posargs:-n auto} + +[testenv:style] +description = Check our style guide +labels = check +deps = + ruff +skip_install = true +commands = + ruff check --diff + ruff format --diff + +[testenv:style-fix] +description = Auto-apply style guide to the extent possible +labels = pre-release +deps = + ruff +skip_install = true +commands = + ruff check --fix + ruff format + ruff check --select ISC001 + +[testenv:spellcheck] +description = Check spelling +labels = check +deps = + codespell[toml] +skip_install = true +commands = + codespell . {posargs} + +[testenv:build{,-strict}] +labels = + check + pre-release +deps = + build + twine +skip_install = true +set_env = + # Ignore specific known warnings: + # https://github.com/pypa/pip/issues/11684 + # https://github.com/pypa/pip/issues/12243 + strict: PYTHONWARNINGS=error,once:pkg_resources is deprecated as an API.:DeprecationWarning:pip._internal.metadata.importlib._envs,once:Unimplemented abstract methods {'locate_file'}:DeprecationWarning:pip._internal.metadata.importlib._dists +commands = + python -m build + python -m twine check dist/* + +[testenv:publish] +depends = build +labels = release +deps = + twine +skip_install = true +commands = + python -m twine upload dist/*