From 28875a6b37575d45c0edc0e9c74a3ed954083d6c Mon Sep 17 00:00:00 2001 From: Anju Tiwari Date: Mon, 24 Apr 2023 19:51:06 +0530 Subject: [PATCH 1/4] Copy dir if symlink fails --- core/dbt/deps/local.py | 8 ++------ test/unit/test_deps.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/dbt/deps/local.py b/core/dbt/deps/local.py index 93e2a3cc323..18c9af01de3 100644 --- a/core/dbt/deps/local.py +++ b/core/dbt/deps/local.py @@ -51,19 +51,15 @@ def install(self, project, renderer): src_path = self.resolve_path(project) dest_path = self.get_installation_path(project, renderer) - can_create_symlink = system.supports_symlinks() - if system.path_exists(dest_path): if not system.path_is_symlink(dest_path): system.rmdir(dest_path) else: system.remove_file(dest_path) - - if can_create_symlink: + try: fire_event(DepsCreatingLocalSymlink()) system.make_symlink(src_path, dest_path) - - else: + except OSError: fire_event(DepsSymlinkNotAvailable()) shutil.copytree(src_path, dest_path) diff --git a/test/unit/test_deps.py b/test/unit/test_deps.py index 5728cb703b6..39a799e638e 100644 --- a/test/unit/test_deps.py +++ b/test/unit/test_deps.py @@ -6,7 +6,7 @@ import dbt.deps import dbt.exceptions from dbt.deps.git import GitUnpinnedPackage -from dbt.deps.local import LocalUnpinnedPackage +from dbt.deps.local import LocalUnpinnedPackage, LocalPinnedPackage from dbt.deps.tarball import TarballUnpinnedPackage from dbt.deps.registry import RegistryUnpinnedPackage from dbt.clients.registry import is_compatible_version @@ -92,6 +92,21 @@ def test_init(self): self.assertEqual(a_pinned.source_type(), "git") self.assertIs(a_pinned.warn_unpinned, True) + @mock.patch("shutil.copytree") + @mock.patch("dbt.deps.local.system.make_symlink") + @mock.patch("dbt.deps.local.LocalPinnedPackage.get_installation_path") + @mock.patch("dbt.deps.local.LocalPinnedPackage.resolve_path") + def test_deps_install( + self, mock_resolve_path, mock_get_installation_path, mock_symlink, mock_shutil + ): + mock_resolve_path.return_value = "/tmp/source" + mock_get_installation_path.return_value = "/tmp/dest" + mock_symlink.side_effect = OSError("Install deps symlink error") + + LocalPinnedPackage("local").install("dummy", "dummy") + self.assertEqual(mock_shutil.call_count, 1) + mock_shutil.assert_called_once_with("/tmp/source", "/tmp/dest") + def test_invalid(self): with self.assertRaises(ValidationError): GitPackage.validate( From ffa6d010f26c722e1d45d07eac9bbb63ff19bd06 Mon Sep 17 00:00:00 2001 From: Anju Tiwari Date: Mon, 24 Apr 2023 21:11:00 +0530 Subject: [PATCH 2/4] Copy dir if symlink fails --- .changes/unreleased/Fixes-20230424-210734.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230424-210734.yaml diff --git a/.changes/unreleased/Fixes-20230424-210734.yaml b/.changes/unreleased/Fixes-20230424-210734.yaml new file mode 100644 index 00000000000..3c7c1c3d84a --- /dev/null +++ b/.changes/unreleased/Fixes-20230424-210734.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fixes dbt deps install +time: 2023-04-24T21:07:34.336797+05:30 +custom: + Author: anjutiwari + Issue: "7428" From a4d28cfe1570b7024f31ed679aadb2bfcc860399 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Tue, 8 Aug 2023 17:53:50 -0400 Subject: [PATCH 3/4] Update .changes/unreleased/Fixes-20230424-210734.yaml Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> --- .changes/unreleased/Fixes-20230424-210734.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changes/unreleased/Fixes-20230424-210734.yaml b/.changes/unreleased/Fixes-20230424-210734.yaml index 3c7c1c3d84a..03f9a0821dd 100644 --- a/.changes/unreleased/Fixes-20230424-210734.yaml +++ b/.changes/unreleased/Fixes-20230424-210734.yaml @@ -1,6 +1,6 @@ kind: Fixes -body: Fixes dbt deps install +body: Copy dir during `dbt deps` if symlink fails time: 2023-04-24T21:07:34.336797+05:30 custom: Author: anjutiwari - Issue: "7428" + Issue: "7428" "8223" From abb6c24df9b6b43fe869a81c84f6cfaf2e3291c7 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Tue, 8 Aug 2023 19:51:40 -0400 Subject: [PATCH 4/4] fix formatting of changelog --- .changes/unreleased/Fixes-20230424-210734.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/unreleased/Fixes-20230424-210734.yaml b/.changes/unreleased/Fixes-20230424-210734.yaml index 03f9a0821dd..3f70881eb90 100644 --- a/.changes/unreleased/Fixes-20230424-210734.yaml +++ b/.changes/unreleased/Fixes-20230424-210734.yaml @@ -3,4 +3,4 @@ body: Copy dir during `dbt deps` if symlink fails time: 2023-04-24T21:07:34.336797+05:30 custom: Author: anjutiwari - Issue: "7428" "8223" + Issue: "7428 8223"