diff --git a/copier/main.py b/copier/main.py index 46650e647..40be276c5 100644 --- a/copier/main.py +++ b/copier/main.py @@ -6,11 +6,12 @@ import sys from contextlib import suppress from dataclasses import asdict, field, replace +from distutils.dir_util import copy_tree from functools import partial from itertools import chain from pathlib import Path -from shutil import copyfile, copytree, rmtree -from typing import Callable, Iterable, List, Mapping, Optional, Sequence +from shutil import copyfile, rmtree +from typing import Callable, Iterable, List, Mapping, Optional, Sequence, Set from unicodedata import normalize import pathspec @@ -40,9 +41,23 @@ # HACK https://github.com/python/mypy/issues/8520#issuecomment-772081075 if sys.version_info >= (3, 8): from functools import cached_property + else: from backports.cached_property import cached_property +# Backport of `shutil.copytree` for python 3.7 to accept `dirs_exist_ok` argument +if sys.version_info <= (3, 8): + from shutil import copytree +else: + from distutils.dir_util import copy_tree + + def copytree(src: Path, dst: Path, dirs_exist_ok: bool = False): + """Backport of `shutil.copytree` with `dirs_exist_ok` argument. + + Can be remove once python 3.7 dropped. + """ + copy_tree(str(src), str(dst)) + @dataclass class Worker: @@ -694,7 +709,7 @@ def run_update(self) -> None: self.run_copy() # Extract the list of files to merge - participating_files: set[Path] = set() + participating_files: Set[Path] = set() for src_dir in (original_dst_temp, reference_dst_temp): for root, dirs, files in os.walk(src_dir, topdown=True): if root == src_dir and ".git" in dirs: diff --git a/docs/updating.md b/docs/updating.md index 7df9b14c6..a48ebedc4 100644 --- a/docs/updating.md +++ b/docs/updating.md @@ -30,9 +30,9 @@ equivalent) hook that detects them, just like this: ```yaml title=".pre-commit-config.yaml" repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 - hooks: - - id: check-merge-conflict + rev: v4.0.1 + hooks: + - id: check-merge-conflict args: [--assume-in-merge] ``` diff --git a/tests/test_updatediff.py b/tests/test_updatediff.py index e1e8edfde..bc2544274 100644 --- a/tests/test_updatediff.py +++ b/tests/test_updatediff.py @@ -220,6 +220,7 @@ def test_updatediff(tmp_path_factory): _src_path: {bundle} author_name: Guybrush project_name: to become a pirate\n + >>>>>>> new upstream """ ) assert readme.read_text() == dedent(