def docs_linkcheck(session: Session) -> None: """Check there are no dead links in the docs.""" session.install(".[docs]") with tempfile.TemporaryDirectory() as tmp_dir: session.run( "sphinx-build", "-d", f"{tmp_dir}/docs_doctree", "docs", f"{tmp_dir}/docs_out", "--color", "-W", "-blinkcheck", )
def docs(session: Session) -> None: """Check that the docs build properly.""" session.install(".[docs]") with tempfile.TemporaryDirectory() as tmp_dir: session.run( "sphinx-build", "-d", f"{tmp_dir}/docs_doctree", "docs", f"{tmp_dir}/docs_out", "--color", "-W", "-bhtml", )
def safety(session: Session) -> None: """Run safety against the installed environment.""" session.install(".") # Update what comes packaged in the venv session.run_always("pip", "install", "-U", "pip", "setuptools", "wheel") session.install("safety") session.run("python", "-m", "safety", "check")
def install(session: nox.sessions.Session, *args: str, **kwargs: Any) -> None: """Install packages into a Nox session using Poetry. .. deprecated:: 0.8 Use :func:`session` instead. """ # noqa: D _deprecate("install", "session.install") Session(session).install(*args, **kwargs)
def export_requirements(session: nox.sessions.Session) -> Path: """Export a requirements file from Poetry. .. deprecated:: 0.8 Use :func:`session` instead. """ # noqa: D _deprecate("export_requirements", "session.poetry.export_requirements") return Session(session).poetry.export_requirements()
def build_package(session: nox.sessions.Session, *, distribution_format: str) -> str: """Build a distribution archive for the package. # noqa: DAR .. deprecated:: 0.8 Use :func:`session` instead. """ _deprecate("build_package", "session.poetry.build_package") return Session(session).poetry.build_package( distribution_format=distribution_format)
def pylint(session: Session) -> None: """Run pylint.""" session.install(".[docs,tests]") session.install("pylint") session.install(*IMPORTED_DEV_REQUIREMENTS) session.run( "python", "-m", "pylint", "src/", "tests/", "tasks.py", "noxfile.py", )
def installroot( session: nox.sessions.Session, *, # noqa: DAR distribution_format: str, extras: Iterable[str] = (), ) -> None: """Install the root package into a Nox session using Poetry. .. deprecated:: 0.8 Use :func:`session` instead. """ _deprecate("installroot", "session.poetry.installroot") Session(session).poetry.installroot( distribution_format=distribution_format, extras=extras)
def test(session: Session) -> None: """Run the unit tests.""" # Remove the coverage file if it exists coverage_file = Path(".coverage") if coverage_file.exists(): coverage_file.unlink() session.install(".[tests]") session.run("coverage", "run", "-p", "--branch", "-m", "pytest") session.notify("coverage")
def mypy(session: Session) -> None: """Run mypy.""" session.install(".[docs,tests]", *IMPORTED_DEV_REQUIREMENTS) # Can't typecheck tasks.py until the following is fixed: # https://github.com/pyinvoke/invoke/issues/357 session.install("mypy") session.run( "python", "-m", "mypy", "--non-interactive", "--install-types", "--scripts-are-modules", "src/", "tests/", "noxfile.py", )
def lint(session: Session): session.install("flake8", "black", "isort", "safety", "pytest", ".") session.run("flake8") session.run("black", ".", "--check") session.run("isort", ".", "--check-only") requirements_file = session.poetry.export_requirements() session.run("safety", "check", "-r", str(requirements_file)) session.run("pytest")
def pre_commit(session: Session) -> None: """Run pre-commit against all files.""" session.install("pre-commit") session.run("python", "-m", "pre_commit", "run", "--all-files", "--show-diff-on-failure")
def coverage(session: Session) -> None: """Generate combined coverage metrics.""" session.install("coverage[toml]") session.run("coverage", "combine") session.run("coverage", "report")
def build(session: Session) -> None: """Check that the package builds properly.""" session.install("build", "twine") with TemporaryDirectory() as tmp_dir: session.run("python", "-m", "build", "--outdir", tmp_dir, ".") session.run("python", "-m", "twine", "check", tmp_dir + "/*")