diff --git a/dvc/__init__.py b/dvc/__init__.py index 0b03c7630..d509c8f0d 100644 --- a/dvc/__init__.py +++ b/dvc/__init__.py @@ -1,30 +1,5 @@ -import os -import ctypes - - -class WindowsSymlinkOverride(object): - FUNC = None - - def __init__(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() +from dvc.runtime import Runtime def setup(): - if os.name == 'nt': - os.symlink = WindowsSymlinkOverride().symlink - pass + Runtime.symlink_setup() diff --git a/dvc/runtime.py b/dvc/runtime.py index 3c04557a1..f30fe38a5 100644 --- a/dvc/runtime.py +++ b/dvc/runtime.py @@ -1,5 +1,6 @@ import os import sys +import ctypes from dvc.config import Config, ConfigI from dvc.exceptions import DvcException @@ -10,6 +11,31 @@ from dvc.settings import Settings class Runtime(object): CONFIG = 'dvc.conf' + SYMLINC_OVERRIDE = None + + @staticmethod + def symlink_setup(): + if os.name != 'nt': + return + + func = ctypes.windll.kernel32.CreateSymbolicLinkW + func.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32) + func.restype = ctypes.c_ubyte + + Runtime.SYMLINC_OVERRIDE = func + + os.symlink = Runtime.symlink + + @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 Runtime.SYMLINC_OVERRIDE(link_name, source, flags) == 0: + raise ctypes.WinError() @staticmethod def conf_file_path(git_dir): @@ -18,6 +44,7 @@ class Runtime(object): @staticmethod def run(cmd_class, parse_config=True): try: + Runtime.symlink_setup() runtime_git = GitWrapper() if parse_config: