@@ -78,6 +78,7 @@ def create_channel(
7878 uds_service : str | None = None ,
7979 uds_dir : str | Path | None = None ,
8080 uds_id : str | None = None ,
81+ uds_fullpath : str | Path | None = None ,
8182 certs_dir : str | Path | None = None ,
8283 cert_files : CertificateFiles | None = None ,
8384 grpc_options : list [tuple [str , object ]] | None = None ,
@@ -108,6 +109,9 @@ def create_channel(
108109 Optional ID to use for the UDS socket filename.
109110 By default `None` and thus it will use "<uds_service>.sock".
110111 Otherwise, the socket filename will be "<uds_service>-<uds_id>.sock".
112+ uds_fullpath : str | Path | None
113+ Full path to the UDS socket file.
114+ By default `None` and thus it will use the `uds_service`, `uds_dir` and `uds_id` parameters.
111115 certs_dir : str | Path | None
112116 Directory to use for TLS certificates.
113117 By default `None` and thus search for the "ANSYS_GRPC_CERTIFICATES" environment variable.
@@ -141,7 +145,7 @@ def check_host_port(transport_mode, host, port) -> tuple[str, str, str]:
141145 transport_mode , host , port = check_host_port (transport_mode , host , port )
142146 return create_insecure_channel (host , port , grpc_options )
143147 case "uds" :
144- return create_uds_channel (uds_service , uds_dir , uds_id , grpc_options )
148+ return create_uds_channel (uds_service , uds_dir , uds_id , grpc_options , uds_fullpath )
145149 case "wnua" :
146150 transport_mode , host , port = check_host_port (transport_mode , host , port )
147151 return create_wnua_channel (host , port , grpc_options )
@@ -186,16 +190,17 @@ def create_insecure_channel(
186190
187191
188192def create_uds_channel (
189- uds_service : str | None ,
193+ uds_service : str | None = None ,
190194 uds_dir : str | Path | None = None ,
191195 uds_id : str | None = None ,
192196 grpc_options : list [tuple [str , object ]] | None = None ,
197+ uds_fullpath : str | Path | None = None ,
193198) -> grpc .Channel :
194199 """Create a gRPC channel using Unix Domain Sockets (UDS).
195200
196201 Parameters
197202 ----------
198- uds_service : str
203+ uds_service : str | None
199204 Service name for the UDS socket.
200205 uds_dir : str | Path | None
201206 Directory to use for Unix Domain Sockets (UDS) transport mode.
@@ -208,6 +213,9 @@ def create_uds_channel(
208213 gRPC channel options to pass when creating the channel.
209214 Each option is a tuple of the form ("option_name", value).
210215 By default `None` and thus only the default authority option is added.
216+ uds_fullpath : str | Path | None
217+ Full path to the UDS socket file.
218+ By default `None` and thus it will use the `uds_service`, `uds_dir` and `uds_id` parameters.
211219
212220 Returns
213221 -------
@@ -218,18 +226,24 @@ def create_uds_channel(
218226 if not is_uds_supported ():
219227 raise RuntimeError ("Unix Domain Sockets are not supported on this platform or gRPC version." )
220228
221- if not uds_service :
222- raise ValueError ("When using UDS transport mode, 'uds_service' must be provided." )
229+ if uds_fullpath :
230+ # Ensure the parent directory exists
231+ Path (uds_fullpath ).parent .mkdir (parents = True , exist_ok = True )
232+ target = f"unix:{ uds_fullpath } "
233+ else :
234+ if uds_service is None :
235+ raise ValueError ("When using UDS transport mode, 'uds_service' must be provided." )
223236
224- # Determine UDS folder
225- uds_folder = determine_uds_folder (uds_dir )
237+ # Determine UDS folder
238+ uds_folder = determine_uds_folder (uds_dir )
226239
227- # Make sure the folder exists
228- uds_folder .mkdir (parents = True , exist_ok = True )
240+ # Make sure the folder exists
241+ uds_folder .mkdir (parents = True , exist_ok = True )
242+
243+ # Generate socket filename with optional ID
244+ socket_filename = f"{ uds_service } -{ uds_id } .sock" if uds_id else f"{ uds_service } .sock"
245+ target = f"unix:{ uds_folder / socket_filename } "
229246
230- # Generate socket filename with optional ID
231- socket_filename = f"{ uds_service } -{ uds_id } .sock" if uds_id else f"{ uds_service } .sock"
232- target = f"unix:{ uds_folder / socket_filename } "
233247 # Set default authority to "localhost" for UDS connection
234248 # This is needed to avoid issues with some gRPC implementations,
235249 # see https://github.com/grpc/grpc/issues/34305
@@ -476,12 +490,17 @@ def verify_transport_mode(transport_mode: str, mode: str | None = None) -> None:
476490 raise ValueError (f"Invalid transport mode: { transport_mode } . Valid options are: { ', ' .join (valid_modes )} ." )
477491
478492
479- def verify_uds_socket (uds_service : str , uds_dir : Path | None = None , uds_id : str | None = None ) -> bool :
493+ def verify_uds_socket (
494+ uds_service : str | None = None ,
495+ uds_dir : Path | None = None ,
496+ uds_id : str | None = None ,
497+ uds_fullpath : str | Path | None = None ,
498+ ) -> bool :
480499 """Verify that the UDS socket file has been created.
481500
482501 Parameters
483502 ----------
484- uds_service : str
503+ uds_service : str | None
485504 Service name for the UDS socket.
486505 uds_dir : Path | None
487506 Directory where the UDS socket file is expected to be (optional).
@@ -490,17 +509,26 @@ def verify_uds_socket(uds_service: str, uds_dir: Path | None = None, uds_id: str
490509 Unique identifier for the UDS socket (optional).
491510 By default `None` and thus it will use "<uds_service>.sock".
492511 Otherwise, the socket filename will be "<uds_service>-<uds_id>.sock".
512+ uds_fullpath : str | Path | None
513+ Full path to the UDS socket file.
514+ By default `None` and thus it will use the `uds_service`, `uds_dir` and `uds_id` parameters.
493515
494516 Returns
495517 -------
496518 bool
497519 True if the UDS socket file exists, False otherwise.
498520 """
499- # Generate socket filename with optional ID
500- uds_filename = f"{ uds_service } -{ uds_id } .sock" if uds_id else f"{ uds_service } .sock"
521+ if uds_fullpath :
522+ return Path (uds_fullpath ).exists ()
523+ else :
524+ if uds_service is None :
525+ raise ValueError ("When using UDS transport mode, 'uds_service' must be provided." )
526+
527+ # Generate socket filename with optional ID
528+ uds_filename = f"{ uds_service } -{ uds_id } .sock" if uds_id else f"{ uds_service } .sock"
501529
502- # Full path to the UDS socket file
503- uds_socket_path = determine_uds_folder (uds_dir ) / uds_filename
530+ # Full path to the UDS socket file
531+ uds_socket_path = determine_uds_folder (uds_dir ) / uds_filename
504532
505- # Check if the UDS socket file exists
506- return uds_socket_path .exists ()
533+ # Check if the UDS socket file exists
534+ return uds_socket_path .exists ()
0 commit comments