Skip to content
Draft
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
62 changes: 62 additions & 0 deletions .github/scripts/apply_uv_project_overrides.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Apply cross-test wheels to a standalone project in the CI checkout.

UV_OVERRIDE is a uv pip setting. Project commands read override-dependencies
from the project's pyproject.toml, including inside the testcase launcher.
"""

import os
import re
import sys
import tomllib
from pathlib import Path

import tomlkit


def canonical_name(requirement: str) -> str:
name_match = re.match(r"\s*([a-zA-Z0-9_.-]+)", requirement)
if not name_match:
raise ValueError("cannot determine the package name of a project override")
return re.sub(r"[-_.]+", "-", name_match.group(1)).lower()


def apply_overrides(manifest: Path, requests: list[str]) -> None:
# uv ignores member overrides if a parent declares a workspace.
for directory in manifest.parents[1:]:
parent_manifest = directory / "pyproject.toml"
if parent_manifest.is_file() and "workspace" in (
tomllib.loads(parent_manifest.read_text(encoding="utf-8"))
.get("tool", {})
.get("uv", {})
):
raise ValueError(f"use the uv workspace-root manifest: {parent_manifest}")

if not requests:
raise ValueError("the CI wheel override list is empty")

document = tomlkit.parse(manifest.read_text(encoding="utf-8"))
if "tool" not in document:
document["tool"] = tomlkit.table()
if "uv" not in document["tool"]:
document["tool"]["uv"] = tomlkit.table()

settings = document["tool"]["uv"]
requested_names = {canonical_name(requirement) for requirement in requests}
pinned = settings.get("override-dependencies", [])
if any(
isinstance(existing, str) and canonical_name(existing) in requested_names
for existing in pinned
):
raise ValueError("a local CI wheel conflicts with an existing project override")

if "override-dependencies" not in settings:
settings["override-dependencies"] = tomlkit.array().multiline(True)
settings["override-dependencies"].extend(requests)
manifest.write_text(tomlkit.dumps(document), encoding="utf-8")


if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit("pass the integration project pyproject.toml path")
requests = Path(os.environ["UV_OVERRIDE"]).read_text(encoding="utf-8").splitlines()
apply_overrides(Path(sys.argv[1]).resolve(), requests)
48 changes: 48 additions & 0 deletions .github/scripts/test_apply_uv_project_overrides.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import tempfile
import tomllib
import unittest
from pathlib import Path

from apply_uv_project_overrides import apply_overrides

CORE = "uipath-core @ file:///tmp/wheels/uipath_core-0.5.36-py3-none-any.whl"


class ApplyUvProjectOverridesTest(unittest.TestCase):
def setUp(self):
self.directory = tempfile.TemporaryDirectory()
self.addCleanup(self.directory.cleanup)
self.root = Path(self.directory.name)
self.manifest = self.root / "pyproject.toml"

def test_creates_project_configuration(self):
self.manifest.write_text('[project]\nname = "fixture"\nversion = "0.1.0"\n')
apply_overrides(self.manifest, [CORE])
result = tomllib.loads(self.manifest.read_text())
self.assertEqual(result["project"]["name"], "fixture")
self.assertEqual(result["tool"]["uv"]["override-dependencies"], [CORE])

def test_preserves_existing_constraints_and_source_paths(self):
self.manifest.write_text(
'[tool.uv]\noverride-dependencies = ["opentelemetry-sdk<1.40"]\n\n'
'[tool.uv.sources]\nlocal = { path = "../local", editable = true }\n'
)
apply_overrides(self.manifest, [CORE])
uv = tomllib.loads(self.manifest.read_text())["tool"]["uv"]
self.assertEqual(uv["override-dependencies"], ["opentelemetry-sdk<1.40", CORE])
self.assertEqual(uv["sources"]["local"]["path"], "../local")

def test_rejects_duplicate_wheel_override_without_rewriting(self):
before = '[tool.uv]\noverride-dependencies = ["UiPath_Core==0.5.35"]\n'
self.manifest.write_text(before)
with self.assertRaisesRegex(ValueError, "conflicts"):
apply_overrides(self.manifest, [CORE])
self.assertEqual(self.manifest.read_text(), before)

def test_rejects_applying_to_workspace_members(self):
self.manifest.write_text('[tool.uv.workspace]\nmembers = ["child"]\n')
child = self.root / "child" / "pyproject.toml"
child.parent.mkdir()
child.write_text('[project]\nname = "child"\nversion = "0.1.0"\n')
with self.assertRaisesRegex(ValueError, "workspace-root"):
apply_overrides(child, [CORE])
16 changes: 16 additions & 0 deletions .github/workflows/test-uipath-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ jobs:
PYBIN=$(command -v python || command -v python3)
"$PYBIN" "$GITHUB_WORKSPACE/_scripts/.github/scripts/write_uv_overrides.py"

- name: Apply local wheel overrides to the package project
shell: bash
env:
UV_PROJECT_MANIFEST: uipath-integrations-python/packages/${{ matrix.package }}/pyproject.toml
run: uv run --no-project --with tomlkit==0.13.3 python "$GITHUB_WORKSPACE/_scripts/.github/scripts/apply_uv_project_overrides.py" "$GITHUB_WORKSPACE/$UV_PROJECT_MANIFEST"

- name: Install dependencies and run tests
shell: bash
working-directory: uipath-integrations-python/packages/${{ matrix.package }}
Expand Down Expand Up @@ -218,6 +224,16 @@ jobs:
PYBIN=$(command -v python || command -v python3)
"$PYBIN" "$GITHUB_WORKSPACE/_scripts/.github/scripts/write_uv_overrides.py"

- name: Apply local wheel overrides to both projects
shell: bash
env:
UV_PACKAGE_MANIFEST: uipath-integrations-python/packages/${{ matrix.package }}/pyproject.toml
UV_TESTCASE_MANIFEST: uipath-integrations-python/packages/${{ matrix.package }}/testcases/${{ matrix.testcase }}/pyproject.toml
run: |
script="$GITHUB_WORKSPACE/_scripts/.github/scripts/apply_uv_project_overrides.py"
uv run --no-project --with tomlkit==0.13.3 python "$script" "$GITHUB_WORKSPACE/$UV_PACKAGE_MANIFEST"
uv run --no-project --with tomlkit==0.13.3 python "$script" "$GITHUB_WORKSPACE/$UV_TESTCASE_MANIFEST"

- name: Install dependencies
working-directory: uipath-integrations-python/packages/${{ matrix.package }}
run: uv sync
Expand Down
Loading