Skip to content
Open
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
3 changes: 2 additions & 1 deletion backend/src/hatchling/builders/hooks/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 11 additions & 1 deletion tests/backend/builders/hooks/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "", "")


Expand Down