Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/uipath-platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-platform"
version = "0.3.23"
version = "0.3.24"
description = "HTTP client library for programmatic access to UiPath Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
22 changes: 22 additions & 0 deletions packages/uipath-platform/src/uipath/platform/common/_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ def folder_identifier(self) -> str:
for resource_type in get_args(model.model_fields["resource_type"].annotation)
)

_KNOWN_RESOURCE_TYPES_IN_LOWER_CASE: dict[str, str] = {
resource_type.lower(): resource_type for resource_type in _KNOWN_RESOURCE_TYPES
}


class ResourceOverwriteParser:
"""Parser for resource overwrite configurations.
Expand All @@ -267,6 +271,24 @@ def knows(cls, key: str) -> bool:
"""
return key.split(".")[0] in _KNOWN_RESOURCE_TYPES

@classmethod
def in_this_sdks_spelling(cls, key: str) -> str:
"""Spell the resource type of ``key`` the way this SDK looks it up.

Other runtimes write some types in another case ("Connection" where this
SDK has "connection"), and lookups here match the key exactly.

Args:
key: The resource key (e.g., "Connection.abc-123").

Returns:
The key with its type respelled (e.g., "connection.abc-123"), or the
key unchanged when the type is unknown in any case.
"""
resource_type, separator, name = key.partition(".")
known = _KNOWN_RESOURCE_TYPES_IN_LOWER_CASE.get(resource_type.lower())
return f"{known}{separator}{name}" if known else key

@classmethod
def parse(cls, key: str, value: dict[str, Any]) -> ResourceOverwrite:
"""Parse a resource overwrite from a key-value pair.
Expand Down
57 changes: 57 additions & 0 deletions packages/uipath-platform/src/uipath/platform/common/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,40 @@ def conversation_id(self) -> str | None:
else None
)

@property
def debug_resource_overwrites(self) -> dict[str, Any] | None:
"""The resource overwrites a debug job carries, or None when it carries none.

Studio Web resolves them before it starts a debug and can put them in the
job, so the run has no need to ask Studio for them. They are read from the
``fpsProperties`` of the config file: the job's own ``debug.executor`` when
that has them, which is how a job started by another job of the debug gets
them, otherwise the entry of this project in ``debug.master``.
"""
fps_properties = self._config_data.get("fpsProperties")
if not isinstance(fps_properties, dict):
return None

carried = _resource_overwrites_of(
_json_object(fps_properties.get("debug.executor"))
)
if carried is not None:
return carried

project_id = self.project_id
master = _json_object(fps_properties.get("debug.master"))
processes = master.get("processes") if master else None
if not project_id or not isinstance(processes, list):
return None

for process in processes:
if not isinstance(process, dict):
continue
executor_info = _json_object(process.get("executorInfo"))
if executor_info and _same_id(executor_info.get("projectId"), project_id):
return _resource_overwrites_of(executor_info)
return None

@property
def is_tracing_enabled(self) -> bool:
from uipath.platform.constants import ENV_TRACING_ENABLED
Expand Down Expand Up @@ -250,6 +284,29 @@ def _config_data(self) -> dict[str, Any]:
return data if isinstance(data, dict) else {}


def _json_object(value: Any) -> dict[str, Any] | None:
"""The JSON object a job property holds, which a job keeps as text."""
import json

if isinstance(value, str):
try:
value = json.loads(value)
except json.JSONDecodeError:
return None
return value if isinstance(value, dict) else None


def _resource_overwrites_of(
executor_info: dict[str, Any] | None,
) -> dict[str, Any] | None:
overwrites = executor_info.get("resourceOverwrites") if executor_info else None
return overwrites if isinstance(overwrites, dict) and overwrites else None


def _same_id(value: Any, project_id: str) -> bool:
return isinstance(value, str) and value.lower() == project_id.lower()


UiPathConfig = ConfigurationManager()


Expand Down
113 changes: 113 additions & 0 deletions packages/uipath-platform/tests/common/test_config_env_vars.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from pathlib import Path

import pytest
Expand Down Expand Up @@ -316,3 +317,115 @@ def test_internal_arguments_and_conversation_id_come_from_the_same_file(
assert UiPathConfig.licensing_context == "ctx"
assert UiPathConfig.is_rooted_to_debug_job is True
assert UiPathConfig.conversation_id == "conv-1"


class TestDebugResourceOverwrites:
_PROJECT_ID = "11111111-1111-1111-1111-111111111111"
_OVERWRITES = {"asset.A": {"name": "B", "folderPath": "F"}}

@pytest.fixture(autouse=True)
def _isolated_config(self, monkeypatch, tmp_path):
monkeypatch.chdir(tmp_path)
monkeypatch.setenv(ENV_UIPATH_PROJECT_ID, self._PROJECT_ID)
UiPathConfig.reset()
yield
UiPathConfig.reset()

@staticmethod
def _write_fps_properties(tmp_path: Path, fps_properties: object) -> None:
(tmp_path / UIPATH_CONFIG_FILE).write_text(
json.dumps({"fpsProperties": fps_properties})
)
UiPathConfig.reset()

@staticmethod
def _master(*executor_infos: dict[str, object]) -> str:
return json.dumps(
{
"processes": [
{"name": "P", "executorInfo": json.dumps(executor_info)}
for executor_info in executor_infos
]
}
)

def test_reads_them_from_the_debug_executor_of_the_job(self, tmp_path):
self._write_fps_properties(
tmp_path,
{"debug.executor": json.dumps({"resourceOverwrites": self._OVERWRITES})},
)
assert UiPathConfig.debug_resource_overwrites == self._OVERWRITES

def test_reads_them_from_the_entry_of_this_project_in_the_debug_master(
self, tmp_path
):
self._write_fps_properties(
tmp_path,
{
# The job a debug starts itself has an executor info of its own.
"debug.executor": json.dumps(
{"projectId": self._PROJECT_ID, "command": "debug"}
),
"debug.master": self._master(
{
"projectId": "another-project",
"resourceOverwrites": {"asset.Other": {"name": "Other"}},
},
{
"projectId": self._PROJECT_ID.upper(),
"resourceOverwrites": self._OVERWRITES,
},
),
},
)
assert UiPathConfig.debug_resource_overwrites == self._OVERWRITES

def test_returns_none_without_config_file(self):
assert UiPathConfig.debug_resource_overwrites is None

@pytest.mark.parametrize(
"fps_properties",
[
[],
{},
{"debug.executor": "not json"},
{"debug.executor": "[]"},
{"debug.executor": '{"resourceOverwrites": {}}'},
{"debug.executor": '{"resourceOverwrites": []}'},
{"debug.master": "not json"},
{"debug.master": '{"processes": {}}'},
{"debug.master": '{"processes": ["x", {"executorInfo": "not json"}]}'},
],
)
def test_returns_none_when_the_job_carries_none(self, tmp_path, fps_properties):
self._write_fps_properties(tmp_path, fps_properties)
assert UiPathConfig.debug_resource_overwrites is None

def test_ignores_the_entries_of_other_projects_in_the_debug_master(self, tmp_path):
self._write_fps_properties(
tmp_path,
{
"debug.master": self._master(
{
"projectId": "another-project",
"resourceOverwrites": self._OVERWRITES,
}
)
},
)
assert UiPathConfig.debug_resource_overwrites is None

def test_ignores_the_debug_master_without_a_project_id(self, monkeypatch, tmp_path):
monkeypatch.delenv(ENV_UIPATH_PROJECT_ID)
self._write_fps_properties(
tmp_path,
{
"debug.master": self._master(
{
"projectId": self._PROJECT_ID,
"resourceOverwrites": self._OVERWRITES,
}
)
},
)
assert UiPathConfig.debug_resource_overwrites is None
18 changes: 18 additions & 0 deletions packages/uipath-platform/tests/common/test_resource_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,21 @@ def test_ontology_binding_parses_as_a_generic_name_and_folder_override() -> None
assert overwrite.resource_type == "ontology"
assert overwrite.resource_identifier == "nxorders"
assert overwrite.folder_identifier == "Shared/NxOrdersSolution"


@pytest.mark.parametrize(
("key", "expected"),
[
("Connection.abc-123", "connection.abc-123"),
("connection.abc-123", "connection.abc-123"),
("MCPSERVER.Name.With.Dots", "mcpServer.Name.With.Dots"),
("asset", "asset"),
("Weird.X", "Weird.X"),
],
)
def test_the_parser_respells_a_known_kind_written_in_another_case(
key: str, expected: str
) -> None:
from uipath.platform.common._bindings import ResourceOverwriteParser

assert ResourceOverwriteParser.in_this_sdks_spelling(key) == expected
2 changes: 1 addition & 1 deletion packages/uipath-platform/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/uipath/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[project]
name = "uipath"
version = "2.15.15"
version = "2.15.16"
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
dependencies = [
"uipath-core>=0.5.35, <0.6.0",
"uipath-runtime>=0.13.7, <0.14.0",
"uipath-platform>=0.3.20, <0.4.0",
"uipath-platform>=0.3.24, <0.4.0",
"uipath-ipc>=2.5.1, <2.6.0",
"click>=8.3.3, <9.0.0",
"httpx>=0.28.1",
Expand Down
Loading
Loading