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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,6 @@ testcases/**/CLAUDE.md
testcases/**/.agent/
testcases/**/agent.mermaid
testcases/**/project.uiproj

# Generated at build time by hatch_build.py
/src/uipath_langchain/_version.py
90 changes: 90 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Hatch build hook that stamps the source git commit into the built package.

Writes the file named by ``version-file`` in ``[tool.hatch.build.hooks.custom]``
using the setuptools-scm / hatch-vcs convention (``__version__`` and
``__commit_id__``), so an installed package can report the exact commit it was
built from::

from <package>._version import __commit_id__

The file is generated at build time and git-ignored. The commit comes from
``git rev-parse HEAD`` when building from a checkout of this repo. When there is
no checkout (e.g. building a wheel from an sdist), the commit already recorded
in the file is kept. If neither is available, ``__commit_id__`` is ``None``.
"""

import ast
import subprocess
from pathlib import Path
from typing import Any

from hatchling.builders.config import BuilderConfig
from hatchling.builders.hooks.plugin.interface import BuildHookInterface

TEMPLATE = '''\
"""Version and source commit of this build. Generated by hatch_build.py."""

__all__ = ["__version__", "__commit_id__", "version", "commit_id"]

__version__ = version = {version!r}
__commit_id__ = commit_id = {commit_id!r}
'''


class CommitIdBuildHook(BuildHookInterface[BuilderConfig]):
"""Generate the version file before each build."""

PLUGIN_NAME = "custom"

def initialize(self, version: str, build_data: dict[str, Any]) -> None:
"""Write the version file and ship it despite it being git-ignored."""
relative_path = self.config["version-file"]
version_file = Path(self.root) / relative_path
commit_id = _git_commit(Path(self.root)) or _recorded_commit(version_file)
version_file.write_text(
TEMPLATE.format(version=self.metadata.version, commit_id=commit_id),
encoding="utf-8",
)
build_data["artifacts"].append(f"/{relative_path}")


def _git_commit(root: Path) -> str | None:
"""Return HEAD's full SHA if ``root`` is tracked in a git checkout."""
try:
# Confirms root belongs to this repo, not to an unrelated parent checkout.
subprocess.run(
["git", "ls-files", "--error-unmatch", "pyproject.toml"],
cwd=root,
check=True,
capture_output=True,
)
result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=root,
check=True,
capture_output=True,
text=True,
)
except (OSError, subprocess.CalledProcessError):
return None
return result.stdout.strip() or None


def _recorded_commit(version_file: Path) -> str | None:
"""Return the commit already in ``version_file`` (e.g. one shipped in an sdist)."""
try:
tree = ast.parse(version_file.read_text(encoding="utf-8"))
except (OSError, SyntaxError):
return None
for node in tree.body:
if (
isinstance(node, ast.Assign)
and any(
isinstance(t, ast.Name) and t.id == "__commit_id__"
for t in node.targets
)
and isinstance(node.value, ast.Constant)
and isinstance(node.value.value, str)
):
return node.value.value
return None
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-langchain"
version = "0.18.30"
version = "0.18.31"
description = "Python SDK that enables developers to build and deploy LangGraph agents to the UiPath Cloud Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down Expand Up @@ -102,8 +102,12 @@ dev = [
# directly, so they are declared here rather than relied on by accident.
"starlette>=1.3.1, <2.0.0",
"uvicorn>=0.30.0",
"hatchling",
]

[tool.hatch.build.hooks.custom]
version-file = "src/uipath_langchain/_version.py"

[tool.hatch.build.targets.wheel]
packages = ["src/uipath_langchain"]

Expand Down
74 changes: 55 additions & 19 deletions uv.lock

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

Loading