From f3bf2e79197a76ef0cddc0d4f764c4d03c99790b Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Sun, 16 Jun 2024 16:24:10 +0200 Subject: [PATCH 1/3] Build distributions in an isolated environment. Otherwise `build` cannot install packages needed for the build system, for example `hatchling`. Fixes issue #448. --- CHANGES.rst | 5 ++++- zest/releaser/release.py | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) 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..fb1e8cce 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,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.") From a53d2c479a7cefdcd290d5d8afff112aed14f614 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Sun, 16 Jun 2024 16:38:27 +0200 Subject: [PATCH 2/3] Fixed wrong indentation. --- zest/releaser/release.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zest/releaser/release.py b/zest/releaser/release.py index fb1e8cce..d39c91dd 100644 --- a/zest/releaser/release.py +++ b/zest/releaser/release.py @@ -164,8 +164,8 @@ def _upload_distributions(self, package): "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/") + 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 From 934ffb7a09e7db999a4220c90e9320d505cda1ac Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Sun, 16 Jun 2024 17:57:32 +0200 Subject: [PATCH 3/3] Fix tests: with setuptools>=69.3 sdists get an underscore. Instead of `tha.example-0.1.tar.gz` you get `tha_example-0.1.tar.gz`. Wheels currently still have dots there, but those might become underscores at some point as well. This is actually a problem for Buildout: https://github.com/buildout/buildout/issues/647 The change in this PR does have a bit of an effect: - Previously when we were running `build`, it would run in non-isolated mode. So if you make sure you have an older `setuptools` version in the venv of `zest.releaser`, you get dots, like was always the case. - Now with this PR, we run in isolated mode, which means that `build` will most likely install the latest setuptools version. Well, it does that if setuptools is the chosen build-system, and I think this is still the default, at least if there is a `setup.py`. You can influence this in the `pyproject.toml` of the package you are releasing. In Plone we have this in most packages: ``` [build-system] requires = ["setuptools>=68.2"] ``` I think we want it like this now: ``` [build-system] requires = ["setuptools>=68.2,<=69.2"] ``` I am mostly writing this as note to myself. :-) --- zest/releaser/tests/functional-git.txt | 4 ++-- zest/releaser/tests/functional-with-hooks.txt | 4 ++-- zest/releaser/tests/pyproject-toml.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) 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: