Skip to content

Commit 0298213

Browse files
committed
check dist dir
1 parent ea10b59 commit 0298213

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

plux/build/hatchling.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,24 @@ def path(self) -> str:
157157
"""
158158
root = self.builder_config.root
159159

160+
# If no sources are configured, we assume the sources root is the project root
160161
if not self.builder_config.sources:
161162
return root
162163

163-
# No "" key. The keys themselves are source directories (e.g. "localstack-core/").
164-
# Filter out any empty-string key that slipped through, strip trailing separators.
165-
source_dirs = [k.rstrip("/") for k in self.builder_config.sources.keys() if k]
164+
# The keys themselves are source directories (e.g. "localstack-core/").
165+
# Filter out any empty-string keys, strip trailing separators.
166+
source_dirs = {k.rstrip("/"): v for k, v in self.builder_config.sources.items() if k}
166167
if len(source_dirs) == 1:
167-
return os.path.join(root, str(source_dirs[0]))
168+
source_dir, dest_dir = next(iter(source_dirs.items()))
169+
if dest_dir:
170+
LOG.warning(
171+
f"plux doesn't know how to resolve sources with non-empty destination directories, using root dir."
172+
)
173+
else:
174+
return os.path.join(root, str(source_dir))
168175

169176
if source_dirs:
170-
LOG.warning("plux doesn't know how to resolve multiple sources directories")
177+
LOG.warning("plux doesn't know how to resolve multiple sources directories, using root dir.")
171178
return root
172179

173180
def filter_packages(self, packages: t.Iterable[str]) -> t.Iterable[str]:

tests/build/test_hatchling.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,17 @@ def test_path_with_packages_in_root(self, tmp_path):
419419
"""When packages are in the project root (sources = {'': ''}), path returns root."""
420420
finder = self._make_finder(sources={"": ""}, root=str(tmp_path))
421421

422-
assert finder.path == str(tmp_path)
422+
assert finder.path == str(tmp_path)
423+
424+
def test_path_single_source_non_empty_dest_dir_falls_back_to_root(self, tmp_path):
425+
"""When a single source has a non-empty dest dir, fall back to project root.
426+
427+
A mapping like ``{"src/": "lib/"}`` means the wheel destination is remapped,
428+
which plux cannot reason about — so it must return the project root and warn.
429+
"""
430+
import os
431+
finder = self._make_finder(sources={"src/": "lib/"}, root=str(tmp_path))
432+
433+
path = finder.path
434+
435+
assert path == str(tmp_path)

0 commit comments

Comments
 (0)