Skip to content

Commit

Permalink
docs: clean up dev recipe (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Oct 8, 2024
1 parent 40d6b49 commit 57a65d8
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions docs/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,24 @@ Enter the ``dev`` nox session:

.. code-block:: python
import os
import pathlib
import nox
# It's a good idea to keep your dev session out of the default list
# so it's not run twice accidentally
nox.options.sessions = [...] # Sessions other than 'dev'
# this VENV_DIR constant specifies the name of the dir that the `dev`
# session will create, containing the virtualenv;
# the `resolve()` makes it portable
VENV_DIR = pathlib.Path('./.venv').resolve()
@nox.session
@nox.session(default=False)
def dev(session: nox.Session) -> None:
"""
Sets up a python development environment for the project.
This session will:
- Create a python virtualenv for the session
- Install the `virtualenv` cli tool into this environment
- Use `virtualenv` to create a global project virtual environment
- Invoke the python interpreter from the global project environment to install
the project and all it's development dependencies.
Set up a python development environment for the project at ".venv".
"""
session.install("virtualenv")
# the VENV_DIR constant is explained above
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
session.run("virtualenv", ".venv", silent=True)
# Use the venv's interpreter to install the project along with
# all it's dev dependencies, this ensures it's installed in the right way
session.run(python, "-m", "pip", "install", "-e", ".[dev]", external=True)
session.run(".venv/bin/pip", "install", "-e", ".[dev]", external=True)
With this, a user can simply run ``nox -s dev`` and have their entire environment set up automatically!

Expand Down

0 comments on commit 57a65d8

Please sign in to comment.