Skip to content

Commit

Permalink
Build distributions in an isolated environment.
Browse files Browse the repository at this point in the history
Otherwise `build` cannot install packages needed for the build system, for example `hatchling`.
Fixes issue #448.
  • Loading branch information
mauritsvanrees committed Jun 16, 2024
1 parent f357c41 commit f3bf2e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/zestsoftware/zest.releaser/issues/448>`_.
[maurits]


9.1.3 (2024-02-07)
Expand Down
23 changes: 17 additions & 6 deletions zest/releaser/release.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -147,13 +148,23 @@ 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,
)
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.")
Expand Down

0 comments on commit f3bf2e7

Please sign in to comment.