Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use build PEP 517 build frontend to build the package #1303

Merged
merged 6 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ def mypy(session: Session) -> None:
"python,poetry",
[
(python_versions[0], "poetry==1.6.1"),
(python_versions[0], "poetry==1.7.1"),
(python_versions[0], "poetry==1.8.5"),
(python_versions[0], "poetry==2.0.1"),
(python_versions[0], "poetry==2.1.1"),
*((python, None) for python in python_versions),
],
)
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ Changelog = "https://github.com/cjolowicz/nox-poetry/releases"

[tool.poetry.dependencies]
python = ">=3.9"
build = ">=1.2"
nox = ">=2020.8.22"
tomlkit = ">=0.7"
packaging = ">=20.9"
tomlkit = ">=0.7"

[tool.poetry.group.dev.dependencies]
pytest = ">=6.2.5"
Expand Down
31 changes: 18 additions & 13 deletions src/nox_poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Poetry:
def __init__(self, session: Session) -> None:
"""Initialize."""
self.session = session
self.project = Path.cwd()
self._config: Optional[Config] = None
self._version: Optional[str] = None

Expand Down Expand Up @@ -116,7 +117,7 @@ def has_dependency_groups(self) -> bool:
def config(self) -> Config:
"""Return the package configuration."""
if self._config is None:
self._config = Config(Path.cwd())
self._config = Config(self.project)
return self._config

def export(self) -> str:
Expand Down Expand Up @@ -166,17 +167,17 @@ def _stripwarnings(lines: Iterable[str]) -> Iterator[str]:
def build(self, *, format: str) -> str:
"""Build the package.

The filename of the archive is extracted from the output Poetry writes
to standard output, which currently looks like this::
The filename of the archive is extracted from the output ``build`` writes
to standard output, which currently looks like this:

Building foobar (0.1.0)
- Building wheel
- Built foobar-0.1.0-py3-none-any.whl
.. code-block:: text

This is brittle, but it has the advantage that it does not rely on
assumptions such as having a clean ``dist`` directory, or
reconstructing the filename from the package metadata. (Poetry does not
use PEP 440 for version numbers, so this is non-trivial.)
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
- poetry-core>=1.0.0
* Getting build dependencies for sdist...
* Building sdist...
Successfully built nox_poetry-1.1.0.tar.gz

Args:
format: The distribution format, either wheel or sdist.
Expand All @@ -191,13 +192,17 @@ def build(self, *, format: str) -> str:
format = DistributionFormat(format)

output = self.session.run_always(
"poetry",
sys.executable,
"-m",
"build",
f"--format={format.value}",
"--no-ansi",
self.project,
"--outdir",
self.project / "dist",
f"--{format.value}",
external=True,
silent=True,
stderr=None,
env={"NO_COLOR": "1"},
)

if output is None:
Expand Down
Loading