66from __future__ import annotations
77
88import datetime
9+ import inspect
910import logging
10- import oci
1111import os
1212import time
1313import traceback
1717from typing import Any , Dict , List , Optional , Union
1818
1919import fsspec
20+ import oci
2021import oci .data_science
2122import oci .util as oci_util
22- import yaml
2323from oci .data_science .models import JobInfrastructureConfigurationDetails
2424from oci .exceptions import ServiceError
25+ import yaml
2526from ads .common import utils
2627from ads .common .oci_datascience import DSCNotebookSession , OCIDataScienceMixin
2728from ads .common .oci_logging import OCILog
@@ -782,7 +783,7 @@ def to_yaml(self) -> str:
782783 # Update runtime from job run
783784 from ads .jobs import Job
784785
785- job = Job .from_dict (job_dict )
786+ job = Job ( ** self . auth ) .from_dict (job_dict )
786787 envs = job .runtime .envs
787788 run_config_override = run_dict .get ("jobConfigurationOverrideDetails" , {})
788789 envs .update (run_config_override .get ("environmentVariables" , {}))
@@ -811,7 +812,7 @@ def job(self):
811812 """
812813 from ads .jobs import Job
813814
814- return Job .from_datascience_job (self .job_id )
815+ return Job ( ** self . auth ) .from_datascience_job (self .job_id )
815816
816817 def download (self , to_dir ):
817818 """Downloads files from job run output URI to local.
@@ -953,9 +954,9 @@ def standardize_spec(spec):
953954 if key not in attribute_map and key .lower () in snake_to_camel_map :
954955 value = spec .pop (key )
955956 if isinstance (value , dict ):
956- spec [
957- snake_to_camel_map [ key . lower ()]
958- ] = DataScienceJob . standardize_spec ( value )
957+ spec [snake_to_camel_map [ key . lower ()]] = (
958+ DataScienceJob . standardize_spec ( value )
959+ )
959960 else :
960961 spec [snake_to_camel_map [key .lower ()]] = value
961962 return spec
@@ -971,6 +972,9 @@ def __init__(self, spec: Dict = None, **kwargs) -> None:
971972 Specification as keyword arguments.
972973 If spec contains the same key as the one in kwargs, the value from kwargs will be used.
973974 """
975+ # Saves a copy of the auth object from the class to the instance.
976+ # Future changes to the class level Job.auth will not affect the auth of existing instances.
977+ self .auth = self .auth .copy ()
974978 for key in ["config" , "signer" , "client_kwargs" ]:
975979 if kwargs .get (key ):
976980 self .auth [key ] = kwargs .pop (key )
@@ -1710,6 +1714,15 @@ def from_id(cls, job_id: str) -> DataScienceJob:
17101714 """
17111715 return cls .from_dsc_job (DSCJob (** cls .auth ).from_ocid (job_id ))
17121716
1717+ @class_or_instance_method
1718+ def from_dict (cls , obj_dict : dict ):
1719+ """Initialize the object from a Python dictionary"""
1720+ if inspect .isclass (cls ):
1721+ job_cls = cls
1722+ else :
1723+ job_cls = cls .__class__
1724+ return job_cls (spec = obj_dict .get ("spec" ), ** cls .auth )
1725+
17131726 @class_or_instance_method
17141727 def list_jobs (cls , compartment_id : str = None , ** kwargs ) -> List [DataScienceJob ]:
17151728 """Lists all jobs in a compartment.
0 commit comments