Skip to content

Commit

Permalink
refactor: python_list -> python_versions
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 19853f9 commit 3d793e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ class.
:members:
:undoc-members:

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

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

Expand Down
8 changes: 4 additions & 4 deletions nox/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import tomllib


__all__ = ["load_toml", "python_list"]
__all__ = ["load_toml", "python_versions"]


def __dir__() -> list[str]:
Expand Down Expand Up @@ -80,7 +80,7 @@ def _load_script_block(filepath: Path) -> dict[str, Any]:
return tomllib.loads(content)


def python_list(
def python_versions(
pyproject: dict[str, Any], *, max_version: str | None = None
) -> list[str]:
"""
Expand All @@ -98,9 +98,9 @@ def python_list(
PYPROJECT = nox.project.load_toml("pyproject.toml")
# From classifiers
PYTHON_VERSIONS = nox.project.python_list(PYPROJECT)
PYTHON_VERSIONS = nox.project.python_versions(PYPROJECT)
# Or from requires-python
PYTHON_VERSIONS = nox.project.python_list(PYPROJECT, max_version="3.13")
PYTHON_VERSIONS = nox.project.python_versions(PYPROJECT, max_version="3.13")
"""
if max_version is None:
# Classifiers are a list of every Python version
Expand Down
16 changes: 8 additions & 8 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from nox.project import python_list
from nox.project import python_versions


def test_classifiers():
Expand All @@ -18,19 +18,19 @@ def test_classifiers():
}
}

assert python_list(pyproject) == ["3.7", "3.9", "3.12"]
assert python_versions(pyproject) == ["3.7", "3.9", "3.12"]


def test_no_classifiers():
pyproject = {"project": {"requires-python": ">=3.9"}}
with pytest.raises(ValueError, match="No Python version classifiers"):
python_list(pyproject)
python_versions(pyproject)


def test_no_requires_python():
pyproject = {"project": {"classifiers": ["Programming Language :: Python :: 3.12"]}}
with pytest.raises(ValueError, match='No "project.requires-python" value set'):
python_list(pyproject, max_version="3.13")
python_versions(pyproject, max_version="3.13")


def test_python_range():
Expand All @@ -48,18 +48,18 @@ def test_python_range():
}
}

assert python_list(pyproject, max_version="3.12") == ["3.10", "3.11", "3.12"]
assert python_list(pyproject, max_version="3.11") == ["3.10", "3.11"]
assert python_versions(pyproject, max_version="3.12") == ["3.10", "3.11", "3.12"]
assert python_versions(pyproject, max_version="3.11") == ["3.10", "3.11"]


def test_python_range_gt():
pyproject = {"project": {"requires-python": ">3.2.1,<3.3"}}

assert python_list(pyproject, max_version="3.4") == ["3.2", "3.3", "3.4"]
assert python_versions(pyproject, max_version="3.4") == ["3.2", "3.3", "3.4"]


def test_python_range_no_min():
pyproject = {"project": {"requires-python": "==3.3.1"}}

with pytest.raises(ValueError, match="No minimum version found"):
python_list(pyproject, max_version="3.5")
python_versions(pyproject, max_version="3.5")

0 comments on commit 3d793e0

Please sign in to comment.