@@ -61,7 +61,7 @@ def get_ds_path_uri(t: Tapis, path: str, verify_exists: bool = False) -> str:
6161 current_username = getattr (t , "username" , None )
6262 # ---
6363
64- input_uri = None # Initialize variable
64+ input_uri = None # Initialize variable
6565
6666 # 1. Handle MyData variations
6767 mydata_patterns = [
@@ -83,13 +83,17 @@ def get_ds_path_uri(t: Tapis, path: str, verify_exists: bool = False) -> str:
8383 )
8484 path_remainder = path .split (pattern , 1 )[1 ].lstrip ("/" )
8585 if use_username :
86- tapis_path = f"{ current_username } /{ path_remainder } " if path_remainder else current_username
86+ tapis_path = (
87+ f"{ current_username } /{ path_remainder } "
88+ if path_remainder
89+ else current_username
90+ )
8791 else :
8892 tapis_path = path_remainder
8993 encoded_path = urllib .parse .quote (tapis_path )
9094 input_uri = f"tapis://{ storage_system_id } /{ encoded_path } "
9195 print (f"Translated '{ path } ' to '{ input_uri } ' using t.username" )
92- break # Found match, exit loop
96+ break # Found match, exit loop
9397
9498 # 2. Handle Community variations (if not already matched)
9599 if input_uri is None :
@@ -105,7 +109,7 @@ def get_ds_path_uri(t: Tapis, path: str, verify_exists: bool = False) -> str:
105109 encoded_path = urllib .parse .quote (tapis_path )
106110 input_uri = f"tapis://{ storage_system_id } /{ encoded_path } "
107111 print (f"Translated '{ path } ' to '{ input_uri } '" )
108- break # Found match, exit loop
112+ break # Found match, exit loop
109113
110114 # 3. Handle Project variations (if not already matched)
111115 if input_uri is None :
@@ -120,51 +124,81 @@ def get_ds_path_uri(t: Tapis, path: str, verify_exists: bool = False) -> str:
120124 if pattern in path :
121125 path_remainder_full = path .split (pattern , 1 )[1 ].lstrip ("/" )
122126 if not path_remainder_full :
123- raise ValueError (f"Project path '{ path } ' is incomplete. Missing project ID." )
127+ raise ValueError (
128+ f"Project path '{ path } ' is incomplete. Missing project ID."
129+ )
124130 parts = path_remainder_full .split ("/" , 1 )
125131 project_id_part = parts [0 ]
126132 path_within_project = parts [1 ] if len (parts ) > 1 else ""
127133
128134 print (f"Searching Tapis systems for project ID '{ project_id_part } '..." )
129135 found_system_id = None
130136 try :
131- search_query = f"description.like.%{ project_id_part } %&id.like.{ system_prefix } *"
132- systems = t .systems .getSystems (search = search_query , listType = "ALL" , select = "id,owner,description" , limit = 10 )
137+ search_query = (
138+ f"description.like.%{ project_id_part } %&id.like.{ system_prefix } *"
139+ )
140+ systems = t .systems .getSystems (
141+ search = search_query ,
142+ listType = "ALL" ,
143+ select = "id,owner,description" ,
144+ limit = 10 ,
145+ )
133146 matches = []
134147 if systems :
135148 for sys in systems :
136- if project_id_part .lower () in getattr (sys , "description" , "" ).lower ():
149+ if (
150+ project_id_part .lower ()
151+ in getattr (sys , "description" , "" ).lower ()
152+ ):
137153 matches .append (sys .id )
138154 if len (matches ) == 1 :
139155 found_system_id = matches [0 ]
140156 print (f"Found unique matching system: { found_system_id } " )
141157 elif len (matches ) == 0 :
142158 if "-" in project_id_part and len (project_id_part ) > 30 :
143159 potential_sys_id = f"{ system_prefix } { project_id_part } "
144- print (f"Search failed, attempting direct lookup for system ID: { potential_sys_id } " )
160+ print (
161+ f"Search failed, attempting direct lookup for system ID: { potential_sys_id } "
162+ )
145163 try :
146- t .systems .getSystem (systemId = potential_sys_id , select = "id" ) # Select minimal field
164+ t .systems .getSystem (
165+ systemId = potential_sys_id , select = "id"
166+ ) # Select minimal field
147167 found_system_id = potential_sys_id
148168 print (f"Direct lookup successful: { found_system_id } " )
149169 except BaseTapyException :
150- print (f"Direct lookup for { potential_sys_id } also failed." )
151- raise FileOperationError (f"No project system found matching ID '{ project_id_part } ' via Tapis v3 search or direct UUID lookup." )
170+ print (
171+ f"Direct lookup for { potential_sys_id } also failed."
172+ )
173+ raise FileOperationError (
174+ f"No project system found matching ID '{ project_id_part } ' via Tapis v3 search or direct UUID lookup."
175+ )
152176 else :
153- raise FileOperationError (f"No project system found matching ID '{ project_id_part } ' via Tapis v3 search." )
177+ raise FileOperationError (
178+ f"No project system found matching ID '{ project_id_part } ' via Tapis v3 search."
179+ )
154180 else :
155- raise FileOperationError (f"Multiple project systems found potentially matching ID '{ project_id_part } ': { matches } . Cannot determine unique system." )
181+ raise FileOperationError (
182+ f"Multiple project systems found potentially matching ID '{ project_id_part } ': { matches } . Cannot determine unique system."
183+ )
156184 except BaseTapyException as e :
157- raise FileOperationError (f"Tapis API error searching for project system '{ project_id_part } ': { e } " ) from e
185+ raise FileOperationError (
186+ f"Tapis API error searching for project system '{ project_id_part } ': { e } "
187+ ) from e
158188 except Exception as e :
159- raise FileOperationError (f"Unexpected error searching for project system '{ project_id_part } ': { e } " ) from e
189+ raise FileOperationError (
190+ f"Unexpected error searching for project system '{ project_id_part } ': { e } "
191+ ) from e
160192
161193 if not found_system_id :
162- raise FileOperationError (f"Could not resolve project ID '{ project_id_part } ' to a Tapis system ID." )
194+ raise FileOperationError (
195+ f"Could not resolve project ID '{ project_id_part } ' to a Tapis system ID."
196+ )
163197
164198 encoded_path_within_project = urllib .parse .quote (path_within_project )
165199 input_uri = f"tapis://{ found_system_id } /{ encoded_path_within_project } "
166200 print (f"Translated '{ path } ' to '{ input_uri } ' using Tapis v3 lookup" )
167- break # Found match, exit loop
201+ break # Found match, exit loop
168202
169203 # 4. Handle direct tapis:// URI input (if not already matched)
170204 if input_uri is None and path .startswith ("tapis://" ):
@@ -194,16 +228,26 @@ def get_ds_path_uri(t: Tapis, path: str, verify_exists: bool = False) -> str:
194228 print (f"Verification successful: Path exists." )
195229 except BaseTapyException as e :
196230 # Specifically check for 404 on the listFiles call
197- if hasattr (e , 'response' ) and e .response and e .response .status_code == 404 :
198- raise FileOperationError (f"Verification failed: Path '{ decoded_remote_path } ' does not exist on system '{ system_id } '. Translated URI: { input_uri } " ) from e
231+ if hasattr (e , "response" ) and e .response and e .response .status_code == 404 :
232+ raise FileOperationError (
233+ f"Verification failed: Path '{ decoded_remote_path } ' does not exist on system '{ system_id } '. Translated URI: { input_uri } "
234+ ) from e
199235 else :
200236 # Re-raise other Tapis errors encountered during verification
201- raise FileOperationError (f"Verification error for path '{ decoded_remote_path } ' on system '{ system_id } ': { e } " ) from e
202- except ValueError as e : # Catch errors from _parse_tapis_uri if input_uri was bad
203- raise FileOperationError (f"Verification failed: Could not parse translated URI '{ input_uri } ' for verification. Error: { e } " ) from e
237+ raise FileOperationError (
238+ f"Verification error for path '{ decoded_remote_path } ' on system '{ system_id } ': { e } "
239+ ) from e
240+ except (
241+ ValueError
242+ ) as e : # Catch errors from _parse_tapis_uri if input_uri was bad
243+ raise FileOperationError (
244+ f"Verification failed: Could not parse translated URI '{ input_uri } ' for verification. Error: { e } "
245+ ) from e
204246 except Exception as e :
205- # Catch other unexpected errors during verification
206- raise FileOperationError (f"Unexpected verification error for path at '{ input_uri } ': { e } " ) from e
247+ # Catch other unexpected errors during verification
248+ raise FileOperationError (
249+ f"Unexpected verification error for path at '{ input_uri } ': { e } "
250+ ) from e
207251
208252 return input_uri
209253
0 commit comments