From 176a8057a599759f678b7e217b18ae3fddfd4a9e Mon Sep 17 00:00:00 2001 From: nazarfil Date: Wed, 9 Jul 2025 13:00:20 +0200 Subject: [PATCH 1/2] fix: exposes pipeline run id --- openhexa/sdk/pipelines/run.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openhexa/sdk/pipelines/run.py b/openhexa/sdk/pipelines/run.py index f76c6cb2..770b016a 100644 --- a/openhexa/sdk/pipelines/run.py +++ b/openhexa/sdk/pipelines/run.py @@ -20,6 +20,13 @@ class CurrentRun: def _connected(self): return "HEXA_SERVER_URL" in os.environ + def id(self): + """Exposes pipeline run id.""" + if "HEXA_RUN_ID" in os.environ: + return os.environ["HEXA_RUN_ID"] + else: + raise RuntimeError("Current run ID is not set. Make sure you are running this in a pipeline context.") + def add_file_output(self, path: str): """Record a run output for a file creation operation. From 20a7b24fff00b32839faf1a44b8daa58bdf2e7ce Mon Sep 17 00:00:00 2001 From: nazarfil Date: Wed, 9 Jul 2025 13:22:17 +0200 Subject: [PATCH 2/2] exposes current pipeline code, type --- openhexa/sdk/__init__.py | 3 +- openhexa/sdk/pipelines/__init__.py | 1 + openhexa/sdk/pipelines/current_pipeline.py | 47 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 openhexa/sdk/pipelines/current_pipeline.py diff --git a/openhexa/sdk/__init__.py b/openhexa/sdk/__init__.py index 0f601fba..077472c3 100644 --- a/openhexa/sdk/__init__.py +++ b/openhexa/sdk/__init__.py @@ -1,7 +1,7 @@ """SDK package.""" from .datasets import Dataset -from .pipelines import current_run, parameter, pipeline +from .pipelines import current_pipeline, current_run, parameter, pipeline from .pipelines.parameter import DHIS2Widget, IASOWidget from .utils import OpenHexaClient from .workspaces import workspace @@ -17,6 +17,7 @@ __all__ = [ "workspace", "pipeline", + "current_pipeline", "parameter", "current_run", "DHIS2Connection", diff --git a/openhexa/sdk/pipelines/__init__.py b/openhexa/sdk/pipelines/__init__.py index aa51bcdb..55de75f5 100644 --- a/openhexa/sdk/pipelines/__init__.py +++ b/openhexa/sdk/pipelines/__init__.py @@ -15,6 +15,7 @@ "Pipeline", "parameter", "current_run", + "current_pipeline", "import_pipeline", "download_pipeline", "get_local_workspace_config", diff --git a/openhexa/sdk/pipelines/current_pipeline.py b/openhexa/sdk/pipelines/current_pipeline.py new file mode 100644 index 00000000..62ba35e6 --- /dev/null +++ b/openhexa/sdk/pipelines/current_pipeline.py @@ -0,0 +1,47 @@ +"""Current Pipeline context module.""" +import os + +from openhexa.sdk.utils import Environment, get_environment + + +class PipelineConfigError(Exception): + """Raised whenever the system cannot find an environment variable required to configure the current pipeline.""" + + pass + + +class CurrentPipeline: + """It is used to view manage the current pipeline state and operations.""" + + @property + def code(self) -> str: + """The unique slug of the workspace. + + Slugs are used to identify the workspace. + """ + try: + return os.environ["HEXA_PIPELINE_CODE"] + except KeyError: + raise PipelineConfigError("The pipeline code is not available in this environment.") + + @property + def name(self) -> str: + """The name of the current pipeline.""" + try: + return os.environ["HEXA_PIPELINE_NAME"] + except KeyError: + raise PipelineConfigError("The pipeline name is not available in this environment.") + + @property + def type(self) -> str: + """The type of the current pipeline.""" + try: + return os.environ["HEXA_PIPELINE_TYPE"] + except KeyError: + raise PipelineConfigError("The pipeline type is not available in this environment.") + + +if get_environment() == Environment.CLOUD_JUPYTER: + current_pipeline = None +else: + current_pipeline = CurrentPipeline()