From 449517c5111273011081dced4fef5cb4932730cf Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 7 Apr 2017 17:44:25 -0700 Subject: [PATCH] Windows symlink --- dvc/__init__.py | 28 ++++++++++++++++++++++++++++ tests/test_repro.py | 1 + 2 files changed, 29 insertions(+) diff --git a/dvc/__init__.py b/dvc/__init__.py index e69de29bb..d9cfe8679 100644 --- a/dvc/__init__.py +++ b/dvc/__init__.py @@ -0,0 +1,28 @@ +import os + +__CSL = None + + +def win_symlink(source, link_name): + '''symlink(source, link_name) - DVC override for Windows + Creates a symbolic link pointing to source named link_name''' + + flags = 0 + if source is not None and os.path.isdir(source): + flags = 1 + if __CSL(link_name, source, flags) == 0: + raise ctypes.WinError() + + +def setup(): + if os.name == 'nt': + global __CSL + if __CSL is None: + import ctypes + csl = ctypes.windll.kernel32.CreateSymbolicLinkW + csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32) + csl.restype = ctypes.c_ubyte + __CSL = csl + + os.symlink = win_symlink + pass diff --git a/tests/test_repro.py b/tests/test_repro.py index bc05a9740..072955710 100644 --- a/tests/test_repro.py +++ b/tests/test_repro.py @@ -89,3 +89,4 @@ class ReproChangedDeepDependency(ReproChangedDependency): CmdRepro(self.settings).run() self.assertEqual(open(self.file_name_res).read(), 'Goodbye\nBobby') + self.assertEqual(1, 2)