Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add build & test-dist nox sessions #336

Merged
merged 1 commit into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .github/workflows/lint.yml

This file was deleted.

30 changes: 26 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,34 @@ on:
pull_request:

jobs:
pre-commit:
name: Pre-commit checks (Black, Flake8, MyPy, ...)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.6
- uses: pre-commit/action@v2.0.3

test-dist:
name: Test SDist & wheel
needs: pre-commit
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install CPython 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
architecture: x64
- name: Run tests
run: pipx run nox -s test-dist -- 3.9

test:
name: CPython ${{ matrix.python }}
needs: test-dist
runs-on: ubuntu-20.04
strategy:
fail-fast: false
Expand All @@ -16,23 +42,19 @@ jobs:
- python: "3.7"
- python: "3.8"
- python: "3.9"

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup cache
uses: actions/cache@v2
with:
path: ~/.cache/auditwheel_tests
key: python${{ matrix.python }}-${{ hashFiles('**/test_manylinux.py') }}
restore-keys: python${{ matrix.python }}-

- name: Install CPython ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
architecture: x64

- name: Run tests
run: pipx run nox -s tests-${{ matrix.python }}
60 changes: 59 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import nox

nox.options.sessions = ["lint", "test-dist"]

PYTHON_ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"]
RUNNING_CI = "TRAVIS" in os.environ or "GITHUB_ACTIONS" in os.environ


Expand Down Expand Up @@ -51,7 +54,7 @@ def _docker_images(session: nox.Session) -> List[str]:
return images_file.read_text().splitlines()


@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
@nox.session(python=PYTHON_ALL_VERSIONS)
def tests(session: nox.Session) -> None:
"""
Run tests.
Expand All @@ -73,3 +76,58 @@ def tests(session: nox.Session) -> None:
session.run("codecov")
except nox.command.CommandFailed:
pass # Ignore failures from codecov tool


def _build(session: nox.Session, dist: Path) -> None:
session.install("build")
tmp_dir = Path(session.create_tmp()) / "build-output"
session.run("python", "-m", "build", "--outdir", str(tmp_dir))
(wheel_path,) = tmp_dir.glob("*.whl")
(sdist_path,) = tmp_dir.glob("*.tar.gz")
dist.mkdir(exist_ok=True)
wheel_path.rename(dist / wheel_path.name)
sdist_path.rename(dist / sdist_path.name)


@nox.session(name="test-dist")
def test_dist(session: nox.Session) -> None:
"""
Builds SDist & Wheels then run unit tests on those.
"""
tmp_dir = Path(session.create_tmp())
dist = tmp_dir / "dist"
_build(session, dist)
python_versions = session.posargs or PYTHON_ALL_VERSIONS
for version in python_versions:
session.notify(f"_test_sdist-{version}", [str(dist)])
session.notify(f"_test_wheel-{version}", [str(dist)])


def _test_dist(session: nox.Session, path: str, pattern: str) -> None:
(dist_path,) = Path(path).glob(pattern)
session.install("-r", "test-requirements.txt", str(dist_path))
session.run("pytest", "tests/unit")


@nox.session(python=PYTHON_ALL_VERSIONS)
def _test_sdist(session: nox.Session) -> None:
"""
Do not run explicitly.
"""
_test_dist(session, session.posargs[0], "*.tar.gz")


@nox.session(python=PYTHON_ALL_VERSIONS)
def _test_wheel(session: nox.Session) -> None:
"""
Do not run explicitly.
"""
_test_dist(session, session.posargs[0], "*.whl")


@nox.session
def build(session: nox.Session) -> None:
"""
Make an SDist and a wheel.
"""
_build(session, Path("dist"))