Skip to content

Commit

Permalink
migrate from tox to nox
Browse files Browse the repository at this point in the history
  • Loading branch information
bretello committed Apr 17, 2024
1 parent 307fb1b commit edff98b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 63 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ jobs:
- name: Cache .tox
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/.tox/checkqa
key: "tox-lint|${{ matrix.os }}|${{ env.PY_CACHE_KEY }}|${{ hashFiles('tox.ini', 'setup.*') }}"
path: ${{ github.workspace }}/.nox/lint
key: "nox-lint|${{ matrix.os }}|${{ env.PY_CACHE_KEY }}|${{ hashFiles('tox.ini', 'setup.*') }}"

- name: Update pip/setuptools
run: |
pip install -U pip setuptools
- name: Install tox
run: python -m pip install tox
- name: Install nox
run: pip install nox

- name: Version information
run: python -m pip list
run: pip list

- name: Lint
run: tox -v -e checkqa
run: nox -s lint
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ jobs:
python-version: "3.9"
- name: Install requirements
run: |
pip install -U pip twine build
pip install nox
- name: Build
run: python -m build
- run: check-manifest
run: nox -s build
- run: twine check dist/*
- name: Publish to PyPI
env:
Expand Down
33 changes: 10 additions & 23 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,10 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-latest, macos-latest]
python: ["3.8"]
tox_env: ["coverage"]
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
include:
- tox_env: "py39-coverage"
os: ubuntu-20.04
python: "3.9"
- tox_env: "py310-coverage"
python: "3.10"
os: ubuntu-20.04
- tox_env: "py311-coverage"
python: "3.11"
os: ubuntu-20.04
- { os: ubuntu-latest, python: "pypy3.9" }
- { os: ubuntu-latest, python: "pypy3.10" }

steps:
- uses: actions/checkout@v4
Expand All @@ -51,35 +43,30 @@ jobs:

- name: set PY_CACHE_KEY
run: echo "PY_CACHE_KEY=$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV

- name: Cache .tox
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/.tox/${{ matrix.tox_env }}
key: "tox|${{ matrix.os }}|${{ matrix.tox_env }}|${{ env.PY_CACHE_KEY }}|${{ hashFiles('tox.ini', 'setup.*') }}"
path: ${{ github.workspace }}/.nox/tests-${{ matrix.python }}
key: "tox-tests|${{ matrix.os }}|${{ matrix.python }}|${{ env.PY_CACHE_KEY }}|${{ hashFiles('noxfile.py', 'setup.py', 'pyproject.toml') }}"

- name: Update tools and print info
run: |
pip install -U pip setuptools virtualenv
pip list
- name: Install tox
run: pip install tox

- name: Setup tox environment
id: setup_tox
run: tox --notest -v -e ${{ matrix.tox_env }}
- name: Install nox
run: pip install nox==2023.4.22

- name: Run tests
run: |
python -m tox -v -e ${{ matrix.tox_env }}
nox -s "tests-${{ matrix.python }}" -- --cov-report=xml
- name: Report coverage
if: always() && (contains(matrix.tox_env, 'coverage') && (steps.setup_tox.outcome == 'success'))
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: ./coverage-ci.xml
flags: ${{ runner.os }}
name: ${{ matrix.tox_env }}
name: ${{ matrix.python }}
fail_ci_if_error: true
60 changes: 60 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import glob
import os

import nox

nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = "lint", "tests"


@nox.session(
python=[
"3.8",
"3.9",
"3.10",
"3.11",
"3.12",
"pypy3.8",
"pypy3.9",
"pypy3.10",
]
)
def tests(session: nox.Session) -> None:
session.install(".[tests]")
session.run(
"pytest",
"--cov-config=pyproject.toml",
*session.posargs,
env={"COVERAGE_FILE": f".coverage.{session.python}"},
)


@nox.session
def lint(session: nox.Session) -> None:
session.install("ruff", "mypy")
session.install("-e", ".[tests]")

session.run("ruff", "check", "setup.py", "fancycompleter", "tests")
# session.run("python", "-m", "mypy")


@nox.session
def build(session: nox.Session) -> None:
session.install("build", "setuptools", "twine")
session.run("python", "-m", "build")
dists = glob.glob("dist/*")
session.run("twine", "check", *dists, silent=True)


@nox.session
def dev(session: nox.Session) -> None:
"""Sets up a python development environment for the project."""
args = session.posargs or ("venv",)
venv_dir = os.fsdecode(os.path.abspath(args[0]))

session.log(f"Setting up virtual environment in {venv_dir}")
session.install("virtualenv")
session.run("virtualenv", venv_dir, silent=True)

python = os.path.join(venv_dir, "bin/python")
session.run(python, "-m", "pip", "install", "-e", ".[tests]", external=True)
32 changes: 31 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,35 @@ select = [
]
ignore = ["F401"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/**" = ["B011"]

[tool.pytest.ini_options]
addopts = "--cov --cov-branch --no-cov-on-fail -ra --tb short -p pytester"
testpaths = ["tests"]


[tool.coverage.run]
branch = true
source = ["fancycompleter", "tests"]

[tool.coverage.paths]
source = ["tests", "*/site-packages"]


[tool.mypy]
# Error output
show_column_numbers = true
show_error_codes = true
show_error_context = true
show_traceback = true
pretty = true
check_untyped_defs = true
# Warnings
warn_no_return = true
warn_redundant_casts = true
warn_unreachable = true
strict_equality = true
no_implicit_optional = true
warn_unused_configs = true
files = ["fancycompleter", "tests"]
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@
"pyrepl @ git+https://github.com/bretello/[email protected]",
"pyreadline;platform_system=='Windows'",
],
extras_require={
"tests": [
"pytest",
"pytest-cov",
],
},
)
30 changes: 0 additions & 30 deletions tox.ini

This file was deleted.

0 comments on commit edff98b

Please sign in to comment.