mantik.utils.mantik_api.run¶
Attributes¶
Classes¶
A class representing the source of a notebook, including its location, |
|
Create a collection of name/value pairs. |
|
Functions¶
|
Determines the type of notebook environment in which the code is |
|
|
|
Retrieves the latest Git commit hash from the current repository. |
|
|
|
|
|
|
|
Updates the notebook source for a specific run within a project. |
|
|
|
Module Contents¶
- class mantik.utils.mantik_api.run.NoteBookSource[source]¶
A class representing the source of a notebook, including its location, version, and provider.
This class encapsulates details about a notebook’s origin, such as whether it is hosted on Google Colab or located locally. It provides functionality to represent the notebook information as JSON and to create instances based on the execution environment.
- (e.g., for Google Colab)
or a local file path.
- derived from a Git commit,
if available. This may not always be set (e.g., in environments like Google Colab).
- Google Colab or local execution.
- create_instance(provider
ProviderType) -> “NoteBookSource”: Creates a new instance of NoteBookSource based on the specified
provider. Handles
environment-specific logic, such as detecting the Colab container hostname or using the local file path.
- For Google Colab:
Resolves the container hostname and IP address.
Sends a request to the Colab API to retrieve session
details. - Constructs a URL pointing to the active notebook in Colab.
- For local execution:
Uses the current file path as the notebook location.
Retrieves the latest Git commit hash as the version.
- Raises:
RuntimeError – If environment-specific detection fails (e.g., failure to retrieve
Colab session details or hostname resolution issues). –
- classmethod create_instance(provider: ProviderType) NoteBookSource [source]¶
- provider: ProviderType[source]¶
- class mantik.utils.mantik_api.run.ProviderType(*args, **kwds)[source]¶
Bases:
enum.Enum
Create a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3
Access them by:
attribute access:
>>> Color.RED <Color.RED: 1>
value lookup:
>>> Color(1) <Color.RED: 1>
name lookup:
>>> Color['RED'] <Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color) 3
>>> list(Color) [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.
- mantik.utils.mantik_api.run.check_notebook_type() ProviderType | None [source]¶
Determines the type of notebook environment in which the code is running.
Returns:¶
- Optional[ProviderType]
ProviderType.JUPYTER: Running in Jupyter notebook
ProviderType.COLAB: Running in Google Colab
None: Running in IPython terminal or standard Python interpreter
Notes
This function uses ipython.get_ipython() to detect the type of interactive shell currently running.
It relies on checking substrings in the shell’s type to
- distinguish
between Jupyter, Google Colab, and other environments.
ProviderType is assumed to be an enum or class that defines constants for different notebook types (e.g., Jupyter, Colab).
- mantik.utils.mantik_api.run.get_download_artifact_url(project_id: uuid.UUID, run_id: uuid.UUID, token: str)[source]¶
- mantik.utils.mantik_api.run.get_latest_git_commit() str [source]¶
Retrieves the latest Git commit hash from the current repository.
- Returns:
The latest Git commit hash as a string if the command executes successfully.
If the current directory is not a Git repository or there are no commits, returns “Not a git repository or no git commit found”. If an unexpected exception occurs, returns an error message with the exception details.
- Return type:
str
- Exceptions:
Handles subprocess.CalledProcessError if the git rev-parse
command fails. - Handles any other exceptions and returns a descriptive error message.
- mantik.utils.mantik_api.run.submit_run(project_id: uuid.UUID, submit_run_data: dict, token: str)[source]¶
- mantik.utils.mantik_api.run.update_logs(project_id: uuid.UUID, run_id: uuid.UUID, logs: str, token: str)[source]¶
- mantik.utils.mantik_api.run.update_notebook_source(project_id: uuid.UUID, run_id: uuid.UUID, notebook_source: NoteBookSource, token: str)[source]¶
Updates the notebook source for a specific run within a project.
- Parameters:
project_id (uuid.UUID) – The unique identifier of the project.
run_id (uuid.UUID) – The unique identifier of the run.
notebook_source (NoteBookSource) – An object containing the notebook
updated. (source data to be)
token (str) – The authentication token used to authorize the API
request.
- Returns:
Status code returned from Mantik API after update process.
- Return type:
Response
- Raises:
Any exceptions raised during the API request will propagate. –
- Side Effects:
Logs a success message if the update is completed successfully.
- mantik.utils.mantik_api.run.update_run_infrastructure(project_id: uuid.UUID, run_id: uuid.UUID, infrastructure: RunInfrastructure, token: str)[source]¶