ads.jobs.templates package

Submodules

ads.jobs.templates.container module

ads.jobs.templates.driver_notebook module

This module runs a Jupyter Python notebook with nbconvert and print the outputs. This is a driver script auto-generated by Oracle ADS.

The following environment variables are used: JOB_RUN_NOTEBOOK:

The relative path of the jupyter Python notebook to be executed.

NOTEBOOK_EXCLUDE_TAGS:

Optional, a list of tags serialized to JSON string. Notebook cells with one of the tags will be excluded from running.

NOTEBOOK_ENCODING:

Optional, the encoding for opening the notebook.

OUTPUT_URI:

Optional, object storage URI for saving files from the output directory.

class ads.jobs.templates.driver_notebook.ADSExecutePreprocessor(**kwargs: Any)[source]

Bases: ExecutePreprocessor

Customized Execute Preprocessor for running notebook.

Initialize the preprocessor

Parameters:

exclude_tags (list, optional) – A list of cell tags, notebook cells with any of these cell tag will be skipped. Defaults to None.

preprocess_cell(cell, resources, *args, **kwargs)[source]

Runs the notebook cell and print out the outputs

ads.jobs.templates.driver_notebook.main() None[source]

Runs the driver to execute a notebook.

ads.jobs.templates.driver_notebook.run_notebook(notebook_path: str, working_dir: str | None = None, exclude_tags: list | None = None) CellExecutionError | None[source]

Runs a notebook

Parameters:
  • notebook_path (str) – The path of the notebook

  • working_dir (str, optional) – The working directory for running the notebook, by default None. If this is None, the same directory of the notebook_path will be used.

  • exclude_tags (list, optional) – Tags for excluding cells, by default None

Returns:

Exception object when there is an error in a notebook cell. Otherwise, None.

Return type:

CellExecutionError or None

ads.jobs.templates.driver_oci module

This is a driver script from Oracle ADS to run Python script in OCI Data Science Jobs. The following environment variables are used: GIT_URL:

URL to the Git repository.

GIT_BRANCH:

Optional, the Git branch to checkout.

GIT_COMMIT:

Optional, the Git commit to checkout. By default, the most recent git commit will be checked out.

CODE_DIR:

Optional, the directory for saving the user code from Git repository. Defaults to “~/Code”

GIT_ENTRYPOINT:

Relative path to the entry script/module file in the Git repository.

ENTRY_FUNCTION:

Optional, function name in the entry script/module to be invoked. If this is not specified, the entry script will be run as Python script.

PYTHON_PATH:

Optional, additional paths to be added to sys.path for looking up modules and packages. The root of the Git repository will be added by default. Multiple paths can be separated by os.pathsep, which is colon(:) for Linux and Mac, semicolon(;) for Windows.

OUTPUT_DIR:

Optional, output directory to be copied to object storage.

OUTPUT_URI:

Optional, object storage URI for saving files from the output directory.

GIT_SECRET_OCID:

The OCID of the OCI vault secret storing the SSH key for Git commands.

SKIP_METADATA_UPDATE:

If this variable exists, the update metadata step will be skipped.

OCI_IAM_TYPE:

Authentication method for OCI services. OCI API key will be used if this is set to api_key. Otherwise resource principal will be used.

OCI_CONFIG_LOCATION:

The location of OCI API key when OCI_IAM_TYPE is set to api_key. If this is not set, oci.config.DEFAULT_LOCATION will be used.

OCI_CONFIG_PROFILE:

The profile name to be used for API key authentication. If this is not set, oci.config.DEFAULT_PROFILE will be used.

OCI__GIT_SSH_KEY_PATH:

The location to save the SSH Key for accessing the git repository.

JOB_RUN_OCID:

The OCID of the job run. This is set by the job run.

This module requires the following packages: oci requests GitPython git openssh

class ads.jobs.templates.driver_oci.CredentialManager[source]

Bases: object

static read_secret(secret_id)[source]

Reads and decode the value of of a secret from OCI vault.

Parameters:

secret_id (str) – OCID of the secret

Returns:

The value of the secret decoded with ASCII.

Return type:

str

class ads.jobs.templates.driver_oci.GitJobRunner(git_manager: GitManager, job_run_ocid: str | None = None)[source]

Bases: JobRunner

Contains methods for running the job.

Initialize the job runner

Parameters:
  • job_run_ocid (str, optional) – Job run OCID, by default “”.

  • purpose (For local testing)

  • string (job run OCID can be set to empty)

run(entrypoint: str | None = None, entry_function: str | None = None)[source]

Runs the job

Parameters:

argv (list, optional) – A list of arguments for the entry script/function, by default None

save_metadata() None[source]

Saves the metadata to job run

update_job_run_metadata_with_rest_api(client: DataScienceClient, metadata: dict) None[source]

Updates the metadata of the job run by call OCI REST API.

Parameters:
  • client (DataScienceClient) – OCI DataScienceClient

  • metadata (dict) – Metadata to be saved as freeform tags.

class ads.jobs.templates.driver_oci.GitManager(repo_url: str, code_dir: str | None = None)[source]

Bases: object

Contains methods for fetching code from Git repository

Initialize the GitManager

Parameters:
  • repo_url (str) – The URL of the repository.

  • code_dir (str) – The local directory for storing the code from Git repository.

Raises:

ValueError – URL is not specified.

checkout_code(branch: str | None = None, commit: str | None = None)[source]

Checkouts the branch or commit of the Git repository.

If neither branch nor commit is specified, the tip of the default branch will be used. If both branch and commit are specified, the commit will be used.

Parameters:
  • branch (str, optional) – The name of the branch, by default None

  • commit (str, optional) – The commit ID (SHA1 hash), by default None

fetch_repo()[source]

Clones the Git repository.

class ads.jobs.templates.driver_oci.GitSSHKey(secret_id)[source]

Bases: object

ads.jobs.templates.driver_oci.main()[source]

The main function for running the job.

ads.jobs.templates.driver_python module

This is a driver script auto-generated by Oracle ADS to run Python script in OCI Data Science Jobs.

The following environment variables are used: CODE_ENTRYPOINT:

Relative path to the entry script/module file in the user code directory.

ENTRY_FUNCTION:

Optional, function name in the entry script/module to be invoked. If this is not specified, the entry script will be run as Python script.

PYTHON_PATH:

Optional, additional paths to be added to sys.path for looking up modules and packages. The root of the user code will be added by default. Multiple paths can be separated by os.pathsep, which is colon(:) for Linux and Mac, semicolon(;) for Windows.

OUTPUT_DIR:

Optional, output directory to be copied to object storage.

OUTPUT_URI:

Optional, object storage URI for saving files from the output directory.

WORKING_DIR:

Optional, the working directory of the user code. This can be specified as a relative path from /home/datascience/decompressed_artifact/code If this is not specified, the working directory will be /home/datascience/decompressed_artifact/code

This module requires the following package: oci

ads.jobs.templates.driver_python.main()[source]

The main function for running the job.

Module contents