diff --git a/backend/src/hatchling/builders/hooks/custom.py b/backend/src/hatchling/builders/hooks/custom.py index a561f993f..7d3fbbd30 100644 --- a/backend/src/hatchling/builders/hooks/custom.py +++ b/backend/src/hatchling/builders/hooks/custom.py @@ -29,7 +29,8 @@ def __new__( # type: ignore[misc] path = os.path.normpath(os.path.join(root, build_script)) if not os.path.isfile(path): - message = f"Build script does not exist: {build_script}" + relative_to_root = " (relative to project root)" if not os.path.isabs(build_script) else "" + message = f"Build script does not exist: {build_script}{relative_to_root}" raise OSError(message) hook_class = load_plugin_from_script(path, build_script, BuildHookInterface, "build_hook") diff --git a/tests/backend/builders/hooks/test_custom.py b/tests/backend/builders/hooks/test_custom.py index 48c1b1616..c068edbc5 100644 --- a/tests/backend/builders/hooks/test_custom.py +++ b/tests/backend/builders/hooks/test_custom.py @@ -22,8 +22,18 @@ def test_path_not_string(isolation): def test_nonexistent(isolation): config = {"path": "test.py"} + expected_message = "Build script does not exist: test.py (relative to project root)" - with pytest.raises(OSError, match="Build script does not exist: test.py"): + with pytest.raises(OSError, match=f"^{re.escape(expected_message)}$"): + CustomBuildHook(str(isolation), config, None, None, "", "") + + +def test_nonexistent_absolute_path(isolation): + build_script = str(isolation / "test.py") + config = {"path": build_script} + expected_message = f"Build script does not exist: {build_script}" + + with pytest.raises(OSError, match=f"^{re.escape(expected_message)}$"): CustomBuildHook(str(isolation), config, None, None, "", "")