diff --git a/CHANGES.rst b/CHANGES.rst index a4e63abe..3fbb5976 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,10 @@ Changelog for zest.releaser 9.1.4 (unreleased) ------------------ -- Nothing changed yet. +- Build distributions in an isolated environment. + Otherwise `build` cannot install packages needed for the build system, for example `hatchling`. + Fixes `issue 448 `_. + [maurits] 9.1.3 (2024-02-07) diff --git a/zest/releaser/release.py b/zest/releaser/release.py index 065424ff..d39c91dd 100644 --- a/zest/releaser/release.py +++ b/zest/releaser/release.py @@ -1,6 +1,7 @@ # GPL, (c) Reinout van Rees from build import ProjectBuilder +from build.env import DefaultIsolatedEnv from colorama import Fore from urllib import request from urllib.error import HTTPError @@ -147,14 +148,24 @@ def _upload_distributions(self, package): "Making a source distribution of a fresh tag checkout (in %s).", self.data["tagworkingdir"], ) - builder = ProjectBuilder(source_dir=".", runner=_project_builder_runner) - builder.build("sdist", "./dist/") - if self.zest_releaser_config.create_wheel(): - logger.info( - "Making a wheel of a fresh tag checkout (in %s).", - self.data["tagworkingdir"], + with DefaultIsolatedEnv() as env: + # We use an isolated env, otherwise `build` cannot install packages + # needed for the build system, for example `hatchling`. + # See https://github.com/zestsoftware/zest.releaser/issues/448 + builder = ProjectBuilder.from_isolated_env( + env, + source_dir=".", + runner=_project_builder_runner, ) - builder.build("wheel", "./dist/") + env.install(builder.build_system_requires) + builder.build("sdist", "./dist/") + if self.zest_releaser_config.create_wheel(): + logger.info( + "Making a wheel of a fresh tag checkout (in %s).", + self.data["tagworkingdir"], + ) + env.install(builder.get_requires_for_build("wheel")) + builder.build("wheel", "./dist/") if not self.zest_releaser_config.upload_pypi(): logger.info("Upload to PyPI was disabled in the configuration.") return diff --git a/zest/releaser/tests/functional-git.txt b/zest/releaser/tests/functional-git.txt index 6a6d6e3b..23f15dc5 100644 --- a/zest/releaser/tests/functional-git.txt +++ b/zest/releaser/tests/functional-git.txt @@ -100,10 +100,10 @@ known on PyPI: creating src/tha.example.egg-info ... Creating ... - removing 'tha.example-0.1' ... + removing 'tha_example-0.1' ... Question: Upload to pypi (y/N)? Our reply: yes - MOCK twine dispatch upload ... dist/tha.example-0.1.tar.gz + MOCK twine dispatch upload ... dist/tha_example-0.1.tar.gz There is now a tag: diff --git a/zest/releaser/tests/functional-with-hooks.txt b/zest/releaser/tests/functional-with-hooks.txt index 53dcc3c8..6700237e 100644 --- a/zest/releaser/tests/functional-with-hooks.txt +++ b/zest/releaser/tests/functional-with-hooks.txt @@ -107,11 +107,11 @@ The release script tags the release and uploads it: creating src/tha.example.egg-info ... Creating ... - removing 'tha.example-0.1' ... + removing 'tha_example-0.1' ... releaser_before_upload Question: Upload to pypi (Y/n)? Our reply: y - MOCK twine dispatch upload ... dist/tha.example-0.1.tar.gz + MOCK twine dispatch upload ... dist/tha_example-0.1.tar.gz releaser_after diff --git a/zest/releaser/tests/pyproject-toml.txt b/zest/releaser/tests/pyproject-toml.txt index 04ae33d1..d886194a 100644 --- a/zest/releaser/tests/pyproject-toml.txt +++ b/zest/releaser/tests/pyproject-toml.txt @@ -101,10 +101,10 @@ known on PyPI: creating src/tha.example.egg-info ... Creating ... - removing 'tha.example-0.1' ... + removing 'tha_example-0.1' ... Question: Upload to pypi (y/N)? Our reply: yes - MOCK twine dispatch upload ... dist/tha.example-0.1.tar.gz + MOCK twine dispatch upload ... dist/tha_example-0.1.tar.gz There is now a tag: