Skip to content

_noxfile

nox-poetry configuration file.

Useful snippets from docs

poetry run nox -l
poetry run nox --list-sessions

poetry run nox -s build_check-3.8 build_dist-3.8 tests-3.8
poetry run nox --session tests-3.11

poetry run nox --python 3.8

poetry run nox -k "not build_check and not build_dist"

Useful nox snippets

# Example conditionally skipping a session
if not session.interactive:
    session.skip('Cannot run detect-secrets audit in non-interactive shell')

# Install pinned version
session.install('detect-secrets==1.0.3')

# Example capturing STDOUT into a file (could do the same for stderr)
path_stdout = Path('.stdout.txt').resolve()
with open(path_stdout, 'w') as out:
    session.run(*shlex.split('echo Hello World!'), stdout=out)

Functions⚓︎

build_check ⚓︎

build_check(session)

Check that the built output meets all checks.

Source code in calcipy/noxfile/_noxfile.py
@nox_poetry_session(python=_get_pythons()[-1:], reuse_venv=True)
def build_check(session: NPSession) -> None:  # pragma: no cover
    """Check that the built output meets all checks."""
    # Build sdist and fix return URI, which will have file://...#egg=calcipy
    sdist_uri = session.poetry.build_package(distribution_format=DistributionFormat.SDIST)
    path_sdist = Path(url2pathname(urlparse(sdist_uri).path))
    logger.text_debug('Fixed sdist URI', sdist_uri=sdist_uri, path_sdist=path_sdist)
    # Check with pyroma
    session.install('pyroma>=4.0', '--upgrade')
    # required for "poetry.core.masonry.api" build backend
    session.run('python', '-m', 'pip', 'install', 'poetry>=1.3', stdout=True)
    session.run('pyroma', '--file', path_sdist.as_posix(), '--min=9', stdout=True)

build_dist ⚓︎

build_dist(session)

Build and test the project files within a controlled environment for repeatability.

Source code in calcipy/noxfile/_noxfile.py
@nox_session(python=_get_pythons()[-1:], reuse_venv=False)
def build_dist(session: Union[NoxSession, NPSession]) -> None:  # pragma: no cover
    """Build and test the project files within a controlled environment for repeatability."""
    dist_path = Path('dist')
    if_found_unlink(dist_path)

    # Support 'corallium' by re-implementing "session.poetry.build_package()", from:
    # https://github.com/cjolowicz/nox-poetry/blob/5772b66ebff8d5a3351a08ed402d3d31e48be5f8/src/nox_poetry/sessions.py#L233-L255
    # https://github.com/cjolowicz/nox-poetry/blob/5772b66ebff8d5a3351a08ed402d3d31e48be5f8/src/nox_poetry/poetry.py#L111-L154
    output = session.run(*shlex.split('poetry build --format=wheel --no-ansi'),
                         external=True, silent=True)
    output = cast(str, output)
    wheel = dist_path / output.split()[-1]
    path_wheel = wheel.resolve().as_uri()

    logger.text('Created wheel', path_wheel=path_wheel)
    # Install the wheel and check that imports without any of the optional dependencies
    session.install(path_wheel)
    session.run(*shlex.split('python scripts/check_imports.py'), stdout=True)

tests ⚓︎

tests(session)

Run doit test task for specified python versions.

Source code in calcipy/noxfile/_noxfile.py
@nox_session(python=_get_pythons(), reuse_venv=True)
def tests(session: Union[NoxSession, NPSession]) -> None:  # pragma: no cover
    """Run doit test task for specified python versions."""
    _install_local(session, ['ddict', 'doc', 'lint', 'nox', 'stale', 'tags', 'test'])
    session.run(*shlex.split('pytest ./tests'), stdout=True, env={'RUNTIME_TYPE_CHECKING_MODE': 'WARNING'})