Skip to content

Commit

Permalink
docs: set up docs
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 29, 2024
1 parent 2b34d76 commit 4dd622a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,13 @@ class.
:members:
:undoc-members:

The pyproject.toml helpers
--------------------------

Nox provides helpers for ``pyproject.toml`` projects in the ``nox.project`` namespace.

.. automodule:: nox.project
:members:

Modifying Nox's behavior in the Noxfile
---------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ is provided:
session.install_and_run_script("peps.py")
Other helpers for ``pyproject.toml`` based projects are also available in
``nox.project``.

Running commands
----------------

Expand Down
21 changes: 21 additions & 0 deletions nox/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ def load_toml(filename: os.PathLike[str] | str) -> dict[str, Any]:
The file must have a ``.toml`` extension to be considered a toml file or a
``.py`` extension / no extension to be considered a script. Other file
extensions are not valid in this function.
Example:
.. code-block:: python
@nox.session
def myscript(session):
myscript_options = nox.project.load_toml("myscript.py")
session.install(*myscript_options["dependencies"])
"""
filepath = Path(filename)
if filepath.suffix == ".toml":
Expand Down Expand Up @@ -74,5 +83,17 @@ def _load_script_block(filepath: Path) -> dict[str, Any]:


def dependency_groups(pyproject: dict[str, Any], *groups: str) -> list[str]:
"""
Get a list of dependencies from a ``[dependency-groups]`` section(s).
Example:
.. code-block:: python
@nox.session
def test(session):
pyproject = nox.project.load_toml("pyproject.toml")
session.install(*nox.project.dependency_groups(pyproject, "dev"))
"""
dep_groups = pyproject["dependency-groups"]
return [item for g in groups for item in resolve(dep_groups, g)]

0 comments on commit 4dd622a

Please sign in to comment.