From d6189e06bdd6e3d70b0bc5a1236a1471ddc8158a Mon Sep 17 00:00:00 2001 From: Noemi <45180344+unflxw@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:53:41 +0100 Subject: [PATCH] Specify `requests` dependency in hook I am not sure exactly why this change is needed now. I think Hatch [added support for specifying custom build hook dependencies][oops] directly in the custom build hook in the last release, and this might have accidentally broken the way in which we used to specify this dependency. It might also be that the breakage is intentional, in which case they [forgot to update the docs][whoopsie] [oops]: https://github.com/pypa/hatch/commit/c04877c183e850200231ed1501033a21db044d30 [whoopsie]: https://hatch.pypa.io/1.9/config/build/#dependencies_1 --- pyproject.toml | 6 ++++-- src/scripts/build_hook.py | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d69035f..c5effbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,8 @@ [build-system] -requires = ["hatchling"] +requires = [ + "hatchling", + "requests" +] build-backend = "hatchling.build" [project] @@ -144,7 +147,6 @@ for = "_APPSIGNAL_BUILD_TRIPLE=\"{args}\" hatch build -t wheel" [tool.hatch.build.targets.wheel.hooks.custom] path = "src/scripts/build_hook.py" -dependencies = ["requests"] [tool.hatch.build.targets.sdist.hooks.custom] path = "src/scripts/sdist_hook.py" diff --git a/src/scripts/build_hook.py b/src/scripts/build_hook.py index 5f05b88..98fef58 100644 --- a/src/scripts/build_hook.py +++ b/src/scripts/build_hook.py @@ -10,7 +10,6 @@ from runpy import run_path from typing import Any -import requests from hatchling.builders.hooks.plugin.interface import BuildHookInterface @@ -79,7 +78,12 @@ class DownloadError(Exception): class CustomBuildHook(BuildHookInterface): + def dependencies(self) -> list[str]: + return ["requests"] + def initialize(self, _version: str, build_data: dict[str, Any]) -> None: + import requests + """ This occurs immediately before each build.