33from pathlib import Path
44from typing import List , Set , Union
55
6+ from polylith import repo
7+
68default_patterns = {
79 "*.pyc" ,
810 "__pycache__" ,
@@ -27,7 +29,9 @@ def any_match(root: Path, patterns: set, name: str, current: Path) -> bool:
2729 return any (is_match (root , pattern , name , current ) for pattern in patterns )
2830
2931
30- def ignore_paths (root : Path , patterns : Set [str ]):
32+ def ignore_paths (patterns : Set [str ]):
33+ root = repo .get_workspace_root (Path .cwd ())
34+
3135 def fn (current_path : str , names : List [str ]):
3236 current = Path (current_path ).resolve ()
3337
@@ -36,22 +40,9 @@ def fn(current_path: str, names: List[str]):
3640 return fn
3741
3842
39- def calculate_root (current_path : str ) -> Path :
40- relative = Path (current_path )
41-
42- parts = [p for p in relative .parts if p != ".." ]
43- relative_path = "/" .join (parts )
44-
45- root = relative .resolve ().as_posix ().replace (relative_path , "" )
46-
47- return Path (root )
48-
49-
5043def copy_tree (source : str , destination : str , patterns : Set [str ]) -> Path :
51- root = calculate_root (source )
52-
5344 is_paths = any ("/" in p for p in patterns )
54- fn = ignore_paths (root , patterns ) if is_paths else shutil .ignore_patterns (* patterns )
45+ fn = ignore_paths (patterns ) if is_paths else shutil .ignore_patterns (* patterns )
5546
5647 res = shutil .copytree (source , destination , ignore = fn , dirs_exist_ok = True )
5748
0 commit comments