Skip to content

Commit

Permalink
Support Poetry projects that use PEP 621
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jun 25, 2024
1 parent fb20b69 commit d02a69e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
8 changes: 6 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ def mypy(session: Session) -> None:
@session
@nox.parametrize(
"python,poetry",
[(python_versions[0], "1.0.10"), *((python, None) for python in python_versions)],
[
(python_versions[0], "poetry==1.0.10"),
(python_versions[0], "poetry @ git+https://github.com/radoering/poetry.git@pep621-support"),
*((python, None) for python in python_versions),
],
)
def tests(session: Session, poetry: Optional[str]) -> None:
"""Run the test suite."""
Expand All @@ -184,7 +188,7 @@ def tests(session: Session, poetry: Optional[str]) -> None:

if poetry is not None:
session.run_always(
"python", "-m", "pip", "install", f"poetry=={poetry}", silent=True
"python", "-m", "pip", "install", poetry, silent=True
)

try:
Expand Down
3 changes: 2 additions & 1 deletion src/nox_poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ def __init__(self, project: Path) -> None:
text = path.read_text(encoding="utf-8")
data: Any = tomlkit.parse(text)
self._config = data["tool"]["poetry"]
self._pyproject = data.get("project", {})

@property
def name(self) -> str:
"""Return the package name."""
name = self._config["name"]
name = self._config.get("name", self._pyproject.get("name"))
assert isinstance(name, str) # noqa: S101
return name

Expand Down
11 changes: 11 additions & 0 deletions tests/functional/data/pep-621/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
name = "pep-621-pyproject"
version = "0.1.0"
description = ""
authors = [{ name = "Your Name", email = "<you@example.com>" }]
requires-python = ">=3.7"
dependencies = ["pyflakes>=2.1.1"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
21 changes: 21 additions & 0 deletions tests/functional/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,24 @@ def test(session: nox_poetry.Session) -> None:
packages = list_packages(project, test)

assert set(expected) == set(packages)


@pytest.mark.skipif(
Version(version("poetry")) < Version("1.9"),
reason="Poetry < 1.9 does not support dependency groups",
)
def test_pep621_pyproject_support(shared_datadir: Path) -> None:
"""It installs packages from PEP 621 pyproject.toml."""
project = Project(shared_datadir / "pep621-pyproject")

@nox_poetry.session
def test(session: nox_poetry.Session) -> None:
"""Install the dependencies."""
session.install(".")

run_nox_with_noxfile(project, [test], [nox_poetry])

expected = [project.package, *project.locked_packages]
packages = list_packages(project, test)

assert set(expected) == set(packages)

0 comments on commit d02a69e

Please sign in to comment.