Skip to content

Commit

Permalink
chore: add build & test-dist nox sessions
Browse files Browse the repository at this point in the history
The `build` session does what you'd expect: it builds SDist & wheel using pypa/build.
The `test-dist` session builds SDist & wheel then runs unit tests on those with all
supported python versions.
  • Loading branch information
mayeut committed Sep 18, 2021
1 parent a4b9251 commit c70f39c
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 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,57 @@ 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)
for version in PYTHON_ALL_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"))

0 comments on commit c70f39c

Please sign in to comment.