Skip to content
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
3 changes: 2 additions & 1 deletion src/hatch_nativelib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ def _write_libinit_py(
# TODO: should this be a fatal error
if r.returncode == 0:
module = r.stdout.decode("utf-8").strip() # type: ignore[arg-type, union-attr]
contents.append(f"import {module}")
if module:
contents.append(f"import {module}")

if contents[-1] != "":
contents.append("")
Expand Down
22 changes: 22 additions & 0 deletions tests/packages/demo-empty-init-dependency/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[build-system]
requires = ["hatchling", "hatch-nativelib"]
build-backend = "hatchling.build"

[project]
name = "demo-empty-init-dependency"
version = "1.2.3"
description = "Demo empty initializer dependency"

[tool.hatch.build.targets.wheel]
packages = ["src/demo_pkg"]

[[tool.hatch.build.hooks.nativelib.pcfile]]
pcfile = "src/demo_pkg/virtual.pc"
name = "virtual"

[[tool.hatch.build.hooks.nativelib.pcfile]]
pcfile = "src/demo_pkg/consumer.pc"
name = "consumer"
libdir = "src/demo_pkg/lib"
shared_libraries = ["consumer"]
requires = ["virtual"]
Empty file.
14 changes: 14 additions & 0 deletions tests/test_integration_build_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,17 @@ def test_build_resolves_intra_project_requires_on_first_run(project_factory) ->
assert result.returncode == 0, result.stdout + result.stderr
init_module = project_factory.read("src/demo_pkg/_init_consumer.py")
assert "import demo_pkg._init_provider" in init_module


def test_build_skips_requirement_without_init_module(project_factory) -> None:
project_factory.copy_package_fixture("demo-empty-init-dependency")
project_factory.write(
f"src/demo_pkg/lib/{shared_library_filename('consumer')}",
"not-a-real-library",
)

result = project_factory.build_wheel()

assert result.returncode == 0, result.stdout + result.stderr
init_module = project_factory.read("src/demo_pkg/_init_consumer.py")
compile(init_module, "_init_consumer.py", "exec")