Thanks to visit codestin.com
Credit goes to github.com

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 pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath"
version = "2.1.160"
version = "2.1.161"
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.10"
Expand Down
106 changes: 46 additions & 60 deletions src/uipath/_cli/_push/sw_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
from .._utils._console import ConsoleLogger
from .._utils._constants import (
AGENT_INITIAL_CODE_VERSION,
AGENT_STORAGE_VERSION,
AGENT_TARGET_RUNTIME,
AGENT_VERSION,
SCHEMA_VERSION,
)
from .._utils._project_files import ( # type: ignore
FileInfo,
Expand Down Expand Up @@ -263,7 +261,7 @@ async def _process_file_uploads(
deleted_files = self._collect_deleted_files(
remote_files,
processed_source_files,
files_to_ignore=["agent.json"],
files_to_ignore=["studio_metadata.json"],
directories_to_ignore=[
name
for name, condition in [
Expand All @@ -289,16 +287,12 @@ async def _process_file_uploads(
)
)

# Load uipath.json configuration
with open(os.path.join(self.directory, "uipath.json"), "r") as f:
uipath_config = json.load(f)

# Prepare agent.json migration (may download existing file to increment version)
agent_update = await self._prepare_agent_json_migration(
structural_migration, remote_files, uipath_config
# Prepare metadata file
update_metadata_event = await self._prepare_metadata_file(
structural_migration, remote_files
)
if agent_update:
updates.append(agent_update)
if update_metadata_event:
updates.append(update_metadata_event)

# Perform the structural migration (uploads/updates/deletes all files)
await self._studio_client.perform_structural_migration_async(
Expand Down Expand Up @@ -411,24 +405,21 @@ def _is_folder_empty(self, folder: ProjectFolder) -> bool:

return True

async def _prepare_agent_json_migration(
async def _prepare_metadata_file(
self,
structural_migration: StructuralMigration,
remote_files: Dict[str, ProjectFile],
uipath_config: Dict[str, Any],
) -> Optional[UpdateEvent]:
"""Prepare agent.json to be included in the same structural migration.
"""Prepare .uipath/studio_metadata.json file.

This method:
1. Extracts author from JWT token or pyproject.toml
2. Downloads existing agent.json if it exists to increment code version
3. Builds complete agent.json structure
4. Adds to structural migration as modified or added resource
1. Checks if file exists locally, initializes with defaults if not
2. Extracts author from JWT token or pyproject.toml
3. Downloads existing studio_metadata.json from remote if it exists to increment code version

Args:
structural_migration: The structural migration to add resources to
remote_files: Dictionary of remote files
uipath_config: Configuration from uipath.json

Returns:
FileOperationUpdate describing the operation, or None if error occurred
Expand All @@ -451,74 +442,69 @@ def get_author_from_token_or_toml() -> str:

author = get_author_from_token_or_toml()

# Initialize agent.json structure with metadata
agent_json = {
"version": AGENT_VERSION,
"metadata": {
"storageVersion": AGENT_STORAGE_VERSION,
"targetRuntime": AGENT_TARGET_RUNTIME,
"isConversational": False,
local_metadata_file = os.path.join(
self.directory, str(UiPathConfig.studio_metadata_file_path)
)

if not os.path.exists(local_metadata_file):
metadata = {
"schemaVersion": SCHEMA_VERSION,
"lastPushDate": datetime.now(timezone.utc).isoformat(),
"lastPushAuthor": author,
"codeVersion": AGENT_INITIAL_CODE_VERSION,
"author": author,
"pushDate": datetime.now(timezone.utc).isoformat(),
},
"bindings": uipath_config.get(
"bindings", {"version": "2.0", "resources": []}
),
# TODO: remove this after validation check gets removed on SW side
"entryPoints": [{}],
}

existing = remote_files.get("agent.json")
}
os.makedirs(os.path.dirname(local_metadata_file), exist_ok=True)
with open(local_metadata_file, "w") as f:
json.dump(metadata, f, indent=2)
else:
with open(local_metadata_file, "r") as f:
metadata = json.load(f)

existing = remote_files.get(".uipath/studio_metadata.json")
if existing:
# Agent.json exists - download and increment version
try:
existing_agent_json = (
existing_metadata = (
await self._studio_client.download_project_file_async(existing)
).json()
version_parts = existing_agent_json["metadata"]["codeVersion"].split(
"."
)
version_parts = existing_metadata["codeVersion"].split(".")
if len(version_parts) >= 3:
# Increment patch version (0.1.0 -> 0.1.1)
version_parts[-1] = str(int(version_parts[-1]) + 1)
agent_json["metadata"]["codeVersion"] = ".".join(version_parts)
metadata["codeVersion"] = ".".join(version_parts)
else:
# Invalid version format, use default with patch = 1
agent_json["metadata"]["codeVersion"] = (
AGENT_INITIAL_CODE_VERSION[:-1] + "1"
)
metadata["codeVersion"] = AGENT_INITIAL_CODE_VERSION[:-1] + "1"
except Exception:
logger.info(
"Could not parse existing 'agent.json' file, using default version"
"Could not parse existing metadata file, using default version"
)

with open(local_metadata_file, "w") as f:
f.write(json.dumps(metadata))

structural_migration.modified_resources.append(
ModifiedResource(
id=existing.id,
content_string=json.dumps(agent_json),
content_string=json.dumps(metadata),
)
)
return UpdateEvent(
file_path="agent.json",
file_path=".uipath/studio_metadata.json",
status="updating",
message="Updating 'agent.json'",
message="Updating '.uipath/studio_metadata.json'",
)
else:
# Agent.json doesn't exist - create new one
logger.info(
"'agent.json' file does not exist in Studio Web project, initializing using default version"
)
structural_migration.added_resources.append(
AddedResource(
file_name="agent.json",
content_string=json.dumps(agent_json),
file_name="studio_metadata.json",
content_string=json.dumps(metadata),
parent_path=".uipath",
)
)
return UpdateEvent(
file_path="agent.json",
file_path=".uipath/studio_metadata.json",
status="uploading",
message="Uploading 'agent.json'",
message="Uploading '.uipath/studio_metadata.json'",
)

async def upload_source_files(
Expand Down
3 changes: 1 addition & 2 deletions src/uipath/_cli/_utils/_constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
BINDINGS_VERSION = "2.2"

# Agent.json constants
AGENT_VERSION = "1.0.0"
AGENT_STORAGE_VERSION = "1.0.0"
SCHEMA_VERSION = "1.0.0"
AGENT_INITIAL_CODE_VERSION = "1.0.0"
AGENT_TARGET_RUNTIME = "python"

Expand Down
6 changes: 6 additions & 0 deletions src/uipath/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@ def entry_points_file_path(self) -> Path:

return Path(ENTRY_POINTS_FILE)

@property
def studio_metadata_file_path(self) -> Path:
from uipath._utils.constants import STUDIO_METADATA_FILE

return Path(".uipath", STUDIO_METADATA_FILE)


UiPathConfig = ConfigurationManager()
1 change: 1 addition & 0 deletions src/uipath/_utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
UIPATH_CONFIG_FILE = "uipath.json"
UIPATH_BINDINGS_FILE = "bindings.json"
ENTRY_POINTS_FILE = "entry-points.json"
STUDIO_METADATA_FILE = "studio_metadata.json"


# Folder names
Expand Down
Loading
Loading