Skip to content

Commit

Permalink
fix: copytree handle existing dirs (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored Sep 12, 2023
1 parent 07cb46d commit 8a64b0a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/pdm/backend/hooks/setuptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def _format_dict_list(data: dict[str, list[str]], indent: int = 4) -> str:
return "\n".join(result)


def _recursive_copy_files(src: Path, dest: Path) -> None:
if src.is_file():
shutil.copy2(src, dest)
else:
dest.mkdir(exist_ok=True)
for child in src.iterdir():
_recursive_copy_files(child, dest / child.name)


class SetuptoolsBuildHook:
"""A build hook to run setuptools build command."""

Expand All @@ -84,11 +93,7 @@ def _build_lib(self, context: Context) -> None:
if not lib_dir:
return
# copy the files under temp_dir/lib.* to context.build_dir
for file in lib_dir.iterdir():
if file.is_dir():
shutil.copytree(file, build_dir / file.name)
else:
shutil.copy2(file, build_dir)
_recursive_copy_files(lib_dir, build_dir)

def _build_inplace(self, context: Context) -> None:
setup_py = self.ensure_setup_py(context)
Expand Down

0 comments on commit 8a64b0a

Please sign in to comment.