diff --git a/dvc/__init__.py b/dvc/__init__.py index d9cfe8679..f0de0e442 100644 --- a/dvc/__init__.py +++ b/dvc/__init__.py @@ -1,28 +1,30 @@ import os - -__CSL = None +import ctypes -def win_symlink(source, link_name): - '''symlink(source, link_name) - DVC override for Windows - Creates a symbolic link pointing to source named link_name''' +class WindowsSymlinkOverride(object): + FUNC = None - 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 __index__(self): + func = ctypes.windll.kernel32.CreateSymbolicLinkW + func.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32) + func.restype = ctypes.c_ubyte + + WindowsSymlinkOverride.FUNC = func + + @staticmethod + def 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 WindowsSymlinkOverride.FUNC(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 + os.symlink = WindowsSymlinkOverride().symlink pass diff --git a/tests/test_repro.py b/tests/test_repro.py index 072955710..bc05a9740 100644 --- a/tests/test_repro.py +++ b/tests/test_repro.py @@ -89,4 +89,3 @@ class ReproChangedDeepDependency(ReproChangedDependency): CmdRepro(self.settings).run() self.assertEqual(open(self.file_name_res).read(), 'Goodbye\nBobby') - self.assertEqual(1, 2)