diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index d9098adb..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Lint - -on: - push: - pull_request: - -jobs: - lint: - name: Lint - 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ea30cc0c..49aebd95 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 }} diff --git a/noxfile.py b/noxfile.py index 515d6c8c..c0be46a2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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 @@ -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. @@ -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"))