22
22
class BasePath :
23
23
@staticmethod
24
24
def from_str (path : str ) -> BasePath :
25
+ from .path_registry import try_get_cloud_path_type
26
+
25
27
url = urllib .parse .urlparse (path )
26
- if url .scheme == "gs" :
27
- return GooglePath .from_str (path )
28
- if url .scheme == "az" or (
29
- url .scheme == "https" and url .netloc .endswith (".blob.core.windows.net" )
30
- ):
31
- return AzurePath .from_str (path )
28
+ cloud_path_type = try_get_cloud_path_type (url )
29
+ if cloud_path_type :
30
+ return cloud_path_type .from_str (path )
31
+
32
32
if url .scheme :
33
33
raise ValueError (f"Invalid path '{ path } '" )
34
34
return LocalPath (path )
35
35
36
36
@property
37
37
def name (self ) -> str :
38
38
"""Returns the name of path, normalised to exclude any trailing slash."""
39
- raise NotImplementedError
39
+ raise NotImplementedError ( f"Name not implemented for { type ( self ) } " )
40
40
41
41
@property
42
42
def parent (self : T ) -> T :
43
- raise NotImplementedError
43
+ raise NotImplementedError ( f"Parent not implemented for { type ( self ) } " )
44
44
45
45
def relative_to (self : T , other : T ) -> str :
46
- raise NotImplementedError
46
+ raise NotImplementedError ( f"relative_to not implemented for { type ( self ) } " )
47
47
48
48
def is_relative_to (self : T , other : T ) -> bool :
49
49
try :
@@ -53,13 +53,13 @@ def is_relative_to(self: T, other: T) -> bool:
53
53
return False
54
54
55
55
def is_directory_like (self ) -> bool :
56
- raise NotImplementedError
56
+ raise NotImplementedError ( f"is_directory_like not implemented for { type ( self ) } " )
57
57
58
58
def ensure_directory_like (self : T ) -> T :
59
- raise NotImplementedError
59
+ raise NotImplementedError ( f"ensure_directory_like not implemented for { type ( self ) } " )
60
60
61
61
def __truediv__ (self : T , relative_path : str ) -> T :
62
- raise NotImplementedError
62
+ raise NotImplementedError ( f"__truediv__ not implemented for { type ( self ) } " )
63
63
64
64
65
65
@dataclass (frozen = True )
@@ -115,7 +115,12 @@ def __fspath__(self) -> str:
115
115
116
116
117
117
class CloudPath (BasePath ):
118
- pass
118
+ @staticmethod
119
+ def is_cloud_path (url : urllib .parse .ParseResult ) -> bool :
120
+ """
121
+ Returns True if the URL is a cloud path for this cloud provider
122
+ """
123
+ raise NotImplementedError
119
124
120
125
121
126
@dataclass (frozen = True )
@@ -124,6 +129,12 @@ class AzurePath(CloudPath):
124
129
container : str
125
130
blob : str
126
131
132
+ @staticmethod
133
+ def is_cloud_path (url : urllib .parse .ParseResult ) -> bool :
134
+ return url .scheme == "az" or (
135
+ url .scheme == "https" and url .netloc .endswith (".blob.core.windows.net" )
136
+ )
137
+
127
138
@staticmethod
128
139
def from_str (url : str ) -> AzurePath :
129
140
parsed_url = urllib .parse .urlparse (url )
@@ -196,6 +207,10 @@ class GooglePath(CloudPath):
196
207
bucket : str
197
208
blob : str
198
209
210
+ @staticmethod
211
+ def is_cloud_path (url : urllib .parse .ParseResult ) -> bool :
212
+ return url .scheme == "gs"
213
+
199
214
@staticmethod
200
215
def from_str (url : str ) -> GooglePath :
201
216
parsed_url = urllib .parse .urlparse (url )
0 commit comments