Skip to content

Commit 9466c66

Browse files
committed
fix: detect src layout only if it exists and included by build config
Resolve #249 Signed-off-by: Frost Ming <me@frostming.com>
1 parent fd5eff3 commit 9466c66

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/pdm/backend/config.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,24 @@ def run_setuptools(self) -> bool:
252252
"""Whether to run setuptools"""
253253
return self.get("run-setuptools", False)
254254

255+
def _get_default_package_dir(self) -> str:
256+
if (
257+
self.root.joinpath("src").is_dir()
258+
and not self.includes
259+
# the first path part must not be a wildcard
260+
or any(Path(p).is_relative_to("src") for p in self.includes)
261+
and "src" not in self.excludes
262+
and "src/" not in self.excludes
263+
):
264+
return "src"
265+
return ""
266+
255267
@property
256268
def package_dir(self) -> str:
257269
"""A directory that will be used to looking for packages."""
258-
default = "src" if self.root.joinpath("src").exists() else ""
259-
return self.get("package-dir", default)
270+
if "package-dir" in self:
271+
return self["package-dir"]
272+
return self._get_default_package_dir()
260273

261274
@property
262275
def is_purelib(self) -> bool:

0 commit comments

Comments
 (0)