Skip to content

Commit

Permalink
refactor: nox.project.load_toml
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Apr 8, 2024
1 parent 4aaa947 commit 6ca7088
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ Loading dependencies from pyproject.toml or scripts
One common need is loading a dependency list from a ``pyproject.toml`` file
(say to prepare an environment without installing the package) or supporting
`PEP 723 <https://peps.python.org/pep-0723>`_ scripts. Nox provides a helper to
load these with ``nox.toml.load``. It can be passed a filepath to a toml file
or to a script file following PEP 723. For example, if you have the following
``peps.py``:
load these with ``nox.project.load_toml``. It can be passed a filepath to a toml
file or to a script file following PEP 723. For example, if you have the
following ``peps.py``:


.. code-block:: python
Expand All @@ -204,7 +204,7 @@ You can make a session for it like this:
@nox.session
def peps(session):
requirements = nox.toml.load("peps.py")["dependencies"]
requirements = nox.project.load_toml("peps.py")["dependencies"]
session.install(*requirements)
session.run("peps.py")
Expand Down
4 changes: 2 additions & 2 deletions nox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from __future__ import annotations

from nox import toml
from nox import project
from nox._options import noxfile_options as options
from nox._parametrize import Param as param
from nox._parametrize import parametrize_decorator as parametrize
Expand All @@ -30,5 +30,5 @@
"session",
"options",
"Session",
"toml",
"project",
]
4 changes: 2 additions & 2 deletions nox/toml.py → nox/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import tomllib


__all__ = ["load"]
__all__ = ["load_toml"]


def __dir__() -> list[str]:
Expand All @@ -30,7 +30,7 @@ def __dir__() -> list[str]:
)


def load(filename: os.PathLike[str] | str) -> dict[str, Any]:
def load_toml(filename: os.PathLike[str] | str) -> dict[str, Any]:
"""
Load a toml file or a script with a PEP 723 script block.
Expand Down
10 changes: 5 additions & 5 deletions tests/test_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_load_pyproject(tmp_path: Path) -> None:
"""
)

toml = nox.toml.load(filepath)
toml = nox.project.load_toml(filepath)
assert toml["project"]["dependencies"] == ["numpy", "requests"]


Expand Down Expand Up @@ -46,7 +46,7 @@ def test_load_script_block(tmp_path: Path, example: str) -> None:
)
)

toml = nox.toml.load(filepath)
toml = nox.project.load_toml(filepath)
assert toml["dependencies"] == ["requests<3", "rich"]


Expand All @@ -68,7 +68,7 @@ def test_load_no_script_block(tmp_path: Path) -> None:
)

with pytest.raises(ValueError, match="No script block found"):
nox.toml.load(filepath)
nox.project.load_toml(filepath)


def test_load_multiple_script_block(tmp_path: Path) -> None:
Expand Down Expand Up @@ -98,10 +98,10 @@ def test_load_multiple_script_block(tmp_path: Path) -> None:
)

with pytest.raises(ValueError, match="Multiple script blocks found"):
nox.toml.load(filepath)
nox.project.load_toml(filepath)


def test_load_non_recongnised_extension():
msg = "Extension must be .py or .toml, got .txt"
with pytest.raises(ValueError, match=msg):
nox.toml.load("some.txt")
nox.project.load_toml("some.txt")

0 comments on commit 6ca7088

Please sign in to comment.