From 6a02fc175a3e3c500dbd29ec230a077c304cf86c Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 7 Oct 2024 12:44:12 -0400 Subject: [PATCH] docs: add uv sync example Signed-off-by: Henry Schreiner --- docs/cookbook.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/cookbook.rst b/docs/cookbook.rst index eb93fdd7..4774be03 100644 --- a/docs/cookbook.rst +++ b/docs/cookbook.rst @@ -135,6 +135,30 @@ Even more so with a sprinkling of Nox: Now a simple ``nox -s release -- patch`` will automate your release (provided you have Bump2Version set up to change your files). This is especially powerful if you have a CI/CD pipeline set up! +Using a lockfile +^^^^^^^^^^^^^^^^ + +If you use a tool like ``uv`` to lock your dependencies, you can use that inside a nox session. Here's an example: + +.. code-block:: python + + @nox.session(venv_backend="uv") + def tests(session: nox.Session) -> None: + """ + Run the unit and regular tests. + """ + session.run_install( + "uv", + "sync", + "--extra=test", + env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location}, + ) + session.run("pytest", *session.posargs) + + +Here we run ``uv sync`` on the nox virtual environment. Other useful flags might include ``--frozen`` (won't touch the lockfile) and ``--inexact`` (will allow you to install other packages as well). + + Generating a matrix with GitHub Actions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^