Skip to content

Commit

Permalink
Merge pull request #449 from zestsoftware/maurits-isolated-build
Browse files Browse the repository at this point in the history
Build distributions in an isolated environment.
  • Loading branch information
reinout authored Jun 16, 2024
2 parents f357c41 + 934ffb7 commit a1455cf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 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
25 changes: 18 additions & 7 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,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
Expand Down
4 changes: 2 additions & 2 deletions zest/releaser/tests/functional-git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions zest/releaser/tests/functional-with-hooks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions zest/releaser/tests/pyproject-toml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit a1455cf

Please sign in to comment.