o
    bi&                     @   sr   d dl Z d dlmZmZmZmZmZmZ d dlm	Z
 d dlmZ d dlmZ er.d dlmZ eG dd dZdS )    N)TYPE_CHECKINGAnyDictListOptionalUnion)LoggingConfig)	PublicAPI
RuntimeEnvc                   @   s<  e Zd ZdZ								d-deee  deee  dee ded	ee d
ee dedeee  fddZ	dededdfddZ
defddZ	d.deeeeef df  deddfddZ	d/dee fddZd
eddfddZdeddfdd Zd!d" Zd#d$ Zd%d& Zdefd'd(Zdefd)d*Zed+d, ZdS )0	JobConfiga  A class used to store the configurations of a job.

    Examples:
        .. testcode::
            :hide:

            import ray
            ray.shutdown()

        .. testcode::

            import ray
            from ray.job_config import JobConfig

            ray.init(job_config=JobConfig(default_actor_lifetime="non_detached"))

    Args:
        jvm_options: The jvm options for java workers of the job.
        code_search_path: A list of directories or jar files that
            specify the search path for user code. This will be used as
            `CLASSPATH` in Java and `PYTHONPATH` in Python.
            See :ref:`Ray cross-language programming <cross_language>` for more details.
        runtime_env: A :ref:`runtime environment <runtime-environments>` dictionary.
        metadata: An opaque metadata dictionary.
        ray_namespace: A :ref:`namespace <namespaces-guide>`
            is a logical grouping of jobs and named actors.
        default_actor_lifetime: The default value of actor lifetime,
            can be "detached" or "non_detached".
            See :ref:`actor lifetimes <actor-lifetimes>` for more details.
    NFnon_detachedjvm_optionscode_search_pathruntime_env_client_jobmetadataray_namespacedefault_actor_lifetime_py_driver_sys_pathc	           	      C   st   |pg | _ |pg | _t| jttfsJ dt| || _|p!i | _|| _| 	| | 
| |p3g | _d | _d S )Nz+The type of code search path is incorrect: )r   r   
isinstancelisttupletyper   r   r   set_runtime_envset_default_actor_lifetimer   py_logging_config)	selfr   r   r   r   r   r   r   r    r   B/home/ubuntu/.local/lib/python3.10/site-packages/ray/job_config.py__init__-   s   






zJobConfig.__init__keyvaluereturnc                 C   s   || j |< dS )a  Add key-value pair to the metadata dictionary.

        If the key already exists, the value is overwritten to the new value.

        Examples:
            .. testcode::

                import ray
                from ray.job_config import JobConfig

                job_config = JobConfig()
                job_config.set_metadata("submitter", "foo")

        Args:
            key: The key of the metadata.
            value: The value of the metadata.
        N)r   )r   r!   r"   r   r   r   set_metadataN   s   zJobConfig.set_metadatac                 C      |    S )z)Serialize the struct into protobuf string)_get_proto_job_configSerializeToStringr   r   r   r   
_serializeb      zJobConfig._serializer   validatec                 C   s*   |dur|ni | _ |r|  | _ d| _dS )a  Modify the runtime_env of the JobConfig.

        We don't validate the runtime_env by default here because it may go
        through some translation before actually being passed to C++ (e.g.,
        working_dir translated from a local directory to a URI).

        Args:
            runtime_env: A :ref:`runtime environment <runtime-environments>` dictionary.
            validate: Whether to validate the runtime env.
        N)r   _validate_runtime_env
_cached_pb)r   r   r+   r   r   r   r   f   s   

zJobConfig.set_runtime_envlogging_configc                 C   s
   || _ dS )a  Set the logging configuration for the job.

        The logging configuration will be applied to the root loggers of
        all Ray task and actor processes that belong to this job.

        Args:
            logging_config: The logging configuration to set.
        N)r   )r   r.   r   r   r   set_py_logging_configz   s   
zJobConfig.set_py_logging_configc                 C   s   || j kr|| _ d| _dS dS )zuSet Ray :ref:`namespace <namespaces-guide>`.

        Args:
            ray_namespace: The namespace to set.
        N)r   r-   )r   r   r   r   r   set_ray_namespace   s   

zJobConfig.set_ray_namespacec                 C   sP   ddl m  m  m} |dkr|jjj| _dS |dkr$|jjj| _dS t	d)zSet the default actor lifetime, which can be "detached" or "non_detached".

        See :ref:`actor lifetimes <actor-lifetimes>` for more details.

        Args:
            default_actor_lifetime: The default actor lifetime to set.
        r   Ndetachedr   z@Default actor lifetime must be one of `detached`, `non_detached`)
ray.core.generated.common_pb2core	generated
common_pb2r   ActorLifetimeDETACHED_default_actor_lifetimeNON_DETACHED
ValueError)r   r   r5   r   r   r   r      s   z$JobConfig.set_default_actor_lifetimec                 C   sD   ddl m} ddlm} | j}t||s|di | j}|| |S )Nr   r
   )_validate_no_local_pathsr   )ray.runtime_envr   ray.runtime_env.runtime_envr;   r   r   )r   r   r;   r   r   r   r   r,      s   
zJobConfig._validate_runtime_envc                 C   s   ddl m  m  m} ddlm} | jdu ru| }| jdu r(t	t
 |_n| j|_|j| j |j| j |j| j | j D ]	\}}||j|< qF|  }|j||ddd | jdurh| j|_| jrrt| j|_|| _| jS )z+Return the protobuf structure of JobConfig.r   N)get_runtime_env_infoTF)is_job_runtime_env	serialize)r2   r3   r4   r5   ray._private.utilsr>   r-   r   r   struuiduuid4r   extendr   py_driver_sys_pathr   r   itemsr,   runtime_env_infoCopyFromr8   r   r   pickledumpsserialized_py_logging_config)r   r5   r>   pbkv
parsed_envr   r   r   r&      s4   


zJobConfig._get_proto_job_configc                 C   r%   N)r,   has_working_dirr(   r   r   r   _runtime_env_has_working_dir   s   z&JobConfig._runtime_env_has_working_dirc                 C   r%   )z2Return the JSON-serialized parsed runtime env dict)r,   r@   r(   r   r   r   _get_serialized_runtime_env   r*   z%JobConfig._get_serialized_runtime_envc                 C   s   |   jjS )z2Return the JSON-serialized parsed runtime env info)r&   rH   runtime_env_configr(   r   r   r   _get_proto_runtime_env_config   r*   z'JobConfig._get_proto_runtime_env_configc                 C   sN   | | dd| dd| dd| dd| dd| dd| d	dd
S )aU  Generates a JobConfig object from json.

        Examples:
            .. testcode::

                from ray.job_config import JobConfig

                job_config = JobConfig.from_json(
                    {"runtime_env": {"working_dir": "uri://abc"}})

        Args:
            job_config_json: The job config json dictionary.
        r   Nr   r   r   r   
client_jobFrF   )r   r   r   r   r   r   r   )get)clsjob_config_jsonr   r   r   	from_json   s   






zJobConfig.from_json)NNNFNNr   N)FrQ   )__name__
__module____qualname____doc__r   r   rB   dictboolr    r$   r)   r   r   r   r   r   r/   r0   r   r,   r&   rS   rT   rV   classmethodr[   r   r   r   r   r      sd    !


	
!

%r   )rC   typingr   r   r   r   r   r   ray.cloudpicklecloudpicklerJ   'ray._private.ray_logging.logging_configr   ray.util.annotationsr	   r<   r   r   r   r   r   r   <module>   s     