Skip to content

Commit ca892b1

Browse files
committed
check dist dir
1 parent ea10b59 commit ca892b1

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

plux/build/hatchling.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ def find_packages(self) -> t.Iterable[str]:
117117

118118
# Package paths in hatchling are always relative to the project root, so we join
119119
# with the project root (not self.path, which is the sources root).
120-
package_path = str(os.path.join(
121-
self.builder_config.root, relative_package_path
122-
))
120+
package_path = str(os.path.join(self.builder_config.root, relative_package_path))
123121
if not os.path.isdir(package_path):
124122
continue
125123

@@ -157,17 +155,24 @@ def path(self) -> str:
157155
"""
158156
root = self.builder_config.root
159157

158+
# If no sources are configured, we assume the sources root is the project root
160159
if not self.builder_config.sources:
161160
return root
162161

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]
162+
# The keys themselves are source directories (e.g. "localstack-core/").
163+
# Filter out any empty-string keys, strip trailing separators.
164+
source_dirs = {k.rstrip("/"): v for k, v in self.builder_config.sources.items() if k}
166165
if len(source_dirs) == 1:
167-
return os.path.join(root, str(source_dirs[0]))
166+
source_dir, dest_dir = next(iter(source_dirs.items()))
167+
if dest_dir:
168+
LOG.warning(
169+
"plux doesn't know how to resolve sources with non-empty destination directories, using root dir."
170+
)
171+
else:
172+
return os.path.join(root, str(source_dir))
168173

169174
if source_dirs:
170-
LOG.warning("plux doesn't know how to resolve multiple sources directories")
175+
LOG.warning("plux doesn't know how to resolve multiple sources directories, using root dir.")
171176
return root
172177

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

tests/build/test_hatchling.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ def test_path_with_packages_in_subdirectory(self, tmp_path):
407407
# Must not raise KeyError, and must return the sources root directory
408408
path = finder.path
409409
import os
410+
410411
assert path == os.path.join(str(tmp_path), "localstack-core")
411412

412413
def test_path_with_empty_sources(self, tmp_path):
@@ -419,4 +420,17 @@ def test_path_with_packages_in_root(self, tmp_path):
419420
"""When packages are in the project root (sources = {'': ''}), path returns root."""
420421
finder = self._make_finder(sources={"": ""}, root=str(tmp_path))
421422

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

0 commit comments

Comments
 (0)