Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langchain UV Build

From Leeroopedia

Template:Metadata

Overview

Concrete tool for producing Python distribution artifacts for a LangChain package, provided by the uv build command executed within the build job of _release.yml.

Description

The build job in _release.yml performs the following:

  1. Checks out the repository.
  2. Sets up Python 3.11 and uv.
  3. Runs uv build in the specified working-directory to produce wheel (.whl) and source distribution (.tar.gz) files in dist/.
  4. Uploads the dist/ directory as a GitHub Actions artifact named dist.
  5. Extracts pkg-name and version from pyproject.toml using tomllib and writes them as job outputs.

The build job runs with minimal permissions (contents: read) and is intentionally separated from the publish job. This ensures that a compromised build step cannot access PyPI credentials or write to the repository.

Usage

This job is triggered automatically as the first job in the release pipeline when the workflow is dispatched. It only runs if the branch is master or the dangerous-nonmaster-release flag is set.

Code Reference

Source Location: .github/workflows/_release.yml (lines 45-98)

Build Step:

- name: Build project for distribution
  run: uv build
  working-directory: ${{ inputs.working-directory }}

Artifact Upload:

- name: Upload build
  uses: actions/upload-artifact@v6
  with:
    name: dist
    path: ${{ inputs.working-directory }}/dist/

Version Extraction:

import os
import tomllib
with open("pyproject.toml", "rb") as f:
    data = tomllib.load(f)
pkg_name = data["project"]["name"]
version = data["project"]["version"]
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
    f.write(f"pkg-name={pkg_name}\n")
    f.write(f"version={version}\n")

Job Outputs Declaration:

outputs:
  pkg-name: ${{ steps.check-version.outputs.pkg-name }}
  version: ${{ steps.check-version.outputs.version }}

Invocation: Automatic, as the first job in the _release.yml pipeline. Can also be run locally:

cd libs/partners/openai
uv build
ls dist/
# langchain_openai-1.1.9-py3-none-any.whl
# langchain_openai-1.1.9.tar.gz

I/O Contract

Direction Name Type Description
Input working-directory string Package folder path relative to repo root (e.g., libs/core)
Input pyproject.toml File Package metadata including [project].name and [project].version
Output dist/*.whl File Built wheel distribution
Output dist/*.tar.gz File Built source distribution
Output pkg-name string Package name extracted from pyproject.toml (e.g., langchain-core)
Output version string Version string extracted from pyproject.toml (e.g., 1.2.11)

Usage Examples

Example 1: Local build of langchain-core

cd libs/core
uv build
# Creates:
#   dist/langchain_core-1.2.11-py3-none-any.whl
#   dist/langchain_core-1.2.11.tar.gz

Example 2: Inspecting the built wheel

cd libs/core
uv build
unzip -l dist/langchain_core-1.2.11-py3-none-any.whl | head -20

Example 3: Extracting version in CI

import tomllib
with open("pyproject.toml", "rb") as f:
    data = tomllib.load(f)
print(f"Building {data['project']['name']} v{data['project']['version']}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment