Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Build distributions in an isolated environment. #449

Merged
merged 3 commits into from
Jun 16, 2024
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
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