|
9 | 9 | from tempfile import TemporaryDirectory |
10 | 10 | from unittest import mock |
11 | 11 | from unittest.mock import PropertyMock |
| 12 | +import os |
| 13 | +import shutil |
12 | 14 |
|
13 | 15 | import duckdb |
14 | 16 | import pandas as pd |
|
39 | 41 | ) |
40 | 42 | from sqlmesh.utils import random_id |
41 | 43 | from sqlmesh.utils.date import TimeLike, to_date |
| 44 | +from sqlmesh.utils.windows import IS_WINDOWS, fix_windows_path |
42 | 45 | from sqlmesh.core.engine_adapter.shared import CatalogSupport |
43 | 46 |
|
44 | 47 | T = t.TypeVar("T", bound=EngineAdapter) |
@@ -480,10 +483,27 @@ def _make_function( |
480 | 483 | paths: t.Union[t.Union[str, Path], t.Collection[t.Union[str, Path]]], |
481 | 484 | ) -> t.List[Path]: |
482 | 485 | paths = ensure_list(paths) |
| 486 | + all_paths = [Path(p) for p in paths] |
483 | 487 | temp_dirs = [] |
484 | | - for path in paths: |
| 488 | + for path in all_paths: |
485 | 489 | temp_dir = Path(tmp_path) / uuid.uuid4().hex |
486 | | - copytree(path, temp_dir, symlinks=True, ignore=ignore) |
| 490 | + |
| 491 | + if IS_WINDOWS: |
| 492 | + # shutil.copytree just doesnt work properly with the symlinks on Windows, regardless of the `symlinks` setting |
| 493 | + src = str(path.absolute()) |
| 494 | + dst = str(temp_dir.absolute()) |
| 495 | + os.system(f"robocopy {src} {dst} /E /COPYALL") |
| 496 | + |
| 497 | + # after copying, delete the files that would have been ignored |
| 498 | + for root, dirs, _ in os.walk(temp_dir): |
| 499 | + for dir in dirs: |
| 500 | + full_dir = fix_windows_path(Path(root) / dir) |
| 501 | + for ignored in ignore(full_dir, [full_dir]): |
| 502 | + shutil.rmtree(ignored) |
| 503 | + |
| 504 | + else: |
| 505 | + copytree(path, temp_dir, symlinks=True, ignore=ignore) |
| 506 | + |
487 | 507 | temp_dirs.append(temp_dir) |
488 | 508 | return temp_dirs |
489 | 509 |
|
|
0 commit comments