From 9466c66d94336cd7aafae478af295f68980fc7ff Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Fri, 5 Jul 2024 17:54:11 +0800 Subject: [PATCH] fix: detect src layout only if it exists and included by build config Resolve #249 Signed-off-by: Frost Ming --- src/pdm/backend/config.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pdm/backend/config.py b/src/pdm/backend/config.py index 6af2130..3fd6cd4 100644 --- a/src/pdm/backend/config.py +++ b/src/pdm/backend/config.py @@ -252,11 +252,24 @@ def run_setuptools(self) -> bool: """Whether to run setuptools""" return self.get("run-setuptools", False) + def _get_default_package_dir(self) -> str: + if ( + self.root.joinpath("src").is_dir() + and not self.includes + # the first path part must not be a wildcard + or any(Path(p).is_relative_to("src") for p in self.includes) + and "src" not in self.excludes + and "src/" not in self.excludes + ): + return "src" + return "" + @property def package_dir(self) -> str: """A directory that will be used to looking for packages.""" - default = "src" if self.root.joinpath("src").exists() else "" - return self.get("package-dir", default) + if "package-dir" in self: + return self["package-dir"] + return self._get_default_package_dir() @property def is_purelib(self) -> bool: