sqlmesh.utils.windows
1import platform 2from pathlib import Path 3 4IS_WINDOWS = platform.system() == "Windows" 5 6WINDOWS_LONGPATH_PREFIX = "\\\\?\\" 7 8 9def fix_windows_path(path: Path) -> Path: 10 """ 11 Windows paths are limited to 260 characters: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation 12 Users can change this by updating a registry entry but we cant rely on that. 13 14 SQLMesh quite commonly generates cache file paths that exceed 260 characters and thus cause a FileNotFound error. 15 If we prefix paths with "\\?\" then we can have paths up to 32,767 characters. 16 17 Note that this prefix also means that relative paths no longer work. From the above docs: 18 > Because you cannot use the "\\?\" prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters. 19 20 So we also call path.resolve() to resolve the relative sections so that operations like `path.read_text()` continue to work 21 """ 22 if path.parts and not path.parts[0].startswith(WINDOWS_LONGPATH_PREFIX): 23 path = Path(WINDOWS_LONGPATH_PREFIX + str(path.absolute())) 24 return path.resolve()
IS_WINDOWS =
False
WINDOWS_LONGPATH_PREFIX =
'\\\\?\\'
def
fix_windows_path(path: pathlib.Path) -> pathlib.Path:
10def fix_windows_path(path: Path) -> Path: 11 """ 12 Windows paths are limited to 260 characters: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation 13 Users can change this by updating a registry entry but we cant rely on that. 14 15 SQLMesh quite commonly generates cache file paths that exceed 260 characters and thus cause a FileNotFound error. 16 If we prefix paths with "\\?\" then we can have paths up to 32,767 characters. 17 18 Note that this prefix also means that relative paths no longer work. From the above docs: 19 > Because you cannot use the "\\?\" prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters. 20 21 So we also call path.resolve() to resolve the relative sections so that operations like `path.read_text()` continue to work 22 """ 23 if path.parts and not path.parts[0].startswith(WINDOWS_LONGPATH_PREFIX): 24 path = Path(WINDOWS_LONGPATH_PREFIX + str(path.absolute())) 25 return path.resolve()
Windows paths are limited to 260 characters: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Users can change this by updating a registry entry but we cant rely on that.
SQLMesh quite commonly generates cache file paths that exceed 260 characters and thus cause a FileNotFound error. If we prefix paths with "\?" then we can have paths up to 32,767 characters.
Note that this prefix also means that relative paths no longer work. From the above docs:
Because you cannot use the "\?" prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters.
So we also call path.resolve() to resolve the relative sections so that operations like path.read_text() continue to work