Hyunji

internally replaced utils

1 +import importlib.machinery
2 +import os
3 +
4 +
5 +def _download_file_from_remote_location(fpath: str, url: str) -> None:
6 + pass
7 +
8 +
9 +def _is_remote_location_available() -> bool:
10 + return False
11 +
12 +
13 +try:
14 + from torch.hub import load_state_dict_from_url # noqa: 401
15 +except ImportError:
16 + from torch.utils.model_zoo import load_url as load_state_dict_from_url # noqa: 401
17 +
18 +
19 +def _get_extension_path(lib_name):
20 +
21 + lib_dir = os.path.dirname(__file__)
22 + if os.name == "nt":
23 + # Register the main torchvision library location on the default DLL path
24 + import ctypes
25 + import sys
26 +
27 + kernel32 = ctypes.WinDLL("kernel32.dll", use_last_error=True)
28 + with_load_library_flags = hasattr(kernel32, "AddDllDirectory")
29 + prev_error_mode = kernel32.SetErrorMode(0x0001)
30 +
31 + if with_load_library_flags:
32 + kernel32.AddDllDirectory.restype = ctypes.c_void_p
33 +
34 + if sys.version_info >= (3, 8):
35 + os.add_dll_directory(lib_dir)
36 + elif with_load_library_flags:
37 + res = kernel32.AddDllDirectory(lib_dir)
38 + if res is None:
39 + err = ctypes.WinError(ctypes.get_last_error())
40 + err.strerror += f' Error adding "{lib_dir}" to the DLL directories.'
41 + raise err
42 +
43 + kernel32.SetErrorMode(prev_error_mode)
44 +
45 + loader_details = (importlib.machinery.ExtensionFileLoader, importlib.machinery.EXTENSION_SUFFIXES)
46 +
47 + extfinder = importlib.machinery.FileFinder(lib_dir, loader_details)
48 + ext_specs = extfinder.find_spec(lib_name)
49 + if ext_specs is None:
50 + raise ImportError
51 +
52 + return ext_specs.origin
...\ No newline at end of file ...\ No newline at end of file