Compare commits

..

1 Commits

Author SHA1 Message Date
Adrian Lyjak 1b49acf94e fix: theres just one publish token 2025-10-03 10:55:39 -04:00
26 changed files with 139 additions and 484 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
uses: astral-sh/setup-uv@v6
with:
version: ${{ env.UV_VERSION }}
+1 -1
View File
@@ -21,7 +21,7 @@ jobs:
- uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v5
uses: actions/setup-node@v4
with:
node-version-file: "ts/llama_cloud_services/.nvmrc"
+2 -2
View File
@@ -30,12 +30,12 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
uses: github/codeql-action/init@v3
with:
languages: python
dependency-caching: true
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
uses: github/codeql-action/analyze@v3
with:
category: "/language:python"
+2 -2
View File
@@ -22,7 +22,7 @@ jobs:
with:
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
- name: Install uv
uses: astral-sh/setup-uv@v7
uses: astral-sh/setup-uv@v6
with:
version: ${{ env.UV_VERSION }}
@@ -31,7 +31,7 @@ jobs:
- uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v5
uses: actions/setup-node@v4
with:
node-version-file: "ts/llama_cloud_services/.nvmrc"
- name: Install dependencies
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v7
uses: astral-sh/setup-uv@v6
with:
version: ${{ env.UV_VERSION }}
+1 -1
View File
@@ -26,7 +26,7 @@ jobs:
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v7
uses: astral-sh/setup-uv@v6
with:
version: ${{ env.UV_VERSION }}
+1 -1
View File
@@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v5
uses: actions/setup-node@v4
with:
node-version-file: "ts/llama_cloud_services/.nvmrc"
- name: Install dependencies
@@ -15,23 +15,23 @@ jobs:
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout Repo
uses: actions/checkout@v5
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: pnpm/action-setup@v3
- name: Setup Node.js
uses: actions/setup-node@v5
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"
- name: Setup Python
uses: actions/setup-python@v6
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v7
uses: astral-sh/setup-uv@v3
- name: Install dependencies
run: pnpm install
+1 -1
View File
@@ -8,7 +8,7 @@
"scripts": {
"pre-commit-version": "pnpm changeset",
"version": "./scripts/changeset-version.py version",
"publish": "./scripts/changeset-version.py publish --tag"
"publish": "./scripts/changeset-version.py publish"
},
"devDependencies": {
"prettier": "^3.6.2",
+1 -15
View File
@@ -21,21 +21,7 @@ importers:
specifier: ^3.6.2
version: 3.6.2
py:
devDependencies:
changesets:
specifier: ^1.0.2
version: 1.0.2
py/llama_parse:
dependencies:
llama-cloud-services-py:
specifier: workspace:*
version: link:..
devDependencies:
changesets:
specifier: ^1.0.2
version: 1.0.2
py: {}
ts/e2e-tests:
devDependencies:
-1
View File
@@ -1,4 +1,3 @@
packages:
- "ts/*"
- "py"
- "py/*"
-37
View File
@@ -1,42 +1,5 @@
# llama-cloud-services-py
## 0.6.76
### Patch Changes
- 4f24f53: Add aggressive_table_extraction flag in python sdk
## 0.6.75
### Patch Changes
- f81532e: Safest types possible for parse
## 0.6.74
### Patch Changes
- 1bf5223: Fix default bbox values
- 24166dc: Now only escape single dollar signs - preserve double for latex equations
## 0.6.73
### Patch Changes
- e6a7939: Loosen packaging dep requirement
## 0.6.72
### Patch Changes
- ad6734b: Fixup and test versioning
## 0.6.71
### Patch Changes
- 51011b9: Escape dollar signs in jupyter notebooks
## 0.6.70
### Patch Changes
-7
View File
@@ -188,10 +188,6 @@ class LlamaParse(BasePydanticReader):
default=False,
description="If set to true, LlamaParse will try to detect long table and adapt the output.",
)
aggressive_table_extraction: Optional[bool] = Field(
default=False,
description="If set to true, LlamaParse will try to extract tables aggressively, may lead to false positives.",
)
annotate_links: Optional[bool] = Field(
default=False,
description="Annotate links found in the document to extract their URL.",
@@ -717,9 +713,6 @@ class LlamaParse(BasePydanticReader):
if self.adaptive_long_table:
data["adaptive_long_table"] = self.adaptive_long_table
if self.aggressive_table_extraction:
data["aggressive_table_extraction"] = self.aggressive_table_extraction
if self.annotate_links:
data["annotate_links"] = self.annotate_links
+27 -146
View File
@@ -1,87 +1,17 @@
import httpx
import os
import re
from pydantic import BaseModel, ConfigDict, Field, SerializeAsAny, model_validator
from typing import Dict, Any, List, Optional, get_origin, get_args
from pydantic import BaseModel, Field, SerializeAsAny
from typing import Dict, Any, List, Optional
from llama_cloud_services.parse.utils import (
make_api_request,
is_jupyter,
)
from llama_cloud_services.parse.utils import make_api_request
from llama_index.core.async_utils import asyncio_run
from llama_index.core.schema import Document, ImageDocument, ImageNode, TextNode
PAGE_REGEX = r"page[-_](\d+)\.jpg$"
SAFE_MODEL_CONFIGS = ConfigDict(
extra="allow",
validate_assignment=False,
arbitrary_types_allowed=True,
validate_default=False,
)
class SafeBaseModel(BaseModel):
"""Base model that gracefully handles None values from unstable backend responses."""
model_config = SAFE_MODEL_CONFIGS
@model_validator(mode="before")
@classmethod
def coerce_none_to_defaults(cls, data: Any) -> Any:
"""
Replace None values with appropriate defaults based on field type annotations.
This prevents validation errors when the backend returns None for non-optional fields.
"""
if not isinstance(data, dict):
return data
# Process each field that has a None value
result = {}
for key, value in data.items():
if value is not None or key not in cls.model_fields:
result[key] = value
continue
# Value is None and field exists in model
field_info = cls.model_fields[key]
# If field has a default or default_factory, let Pydantic handle it
from pydantic_core import PydanticUndefined
if (
field_info.default is not PydanticUndefined
or field_info.default_factory is not None
):
continue
# Otherwise, provide a sensible default based on the type annotation
annotation = field_info.annotation
origin = get_origin(annotation)
# Handle List types
if origin is list:
result[key] = []
# Handle Dict types
elif origin is dict:
result[key] = {}
# Handle basic types
elif annotation == str or (origin and str in get_args(annotation)):
result[key] = ""
elif annotation == int or (origin and int in get_args(annotation)):
result[key] = 0
elif annotation == float or (origin and float in get_args(annotation)):
result[key] = 0.0
elif annotation == bool or (origin and bool in get_args(annotation)):
result[key] = False
# If we can't determine a safe default, skip (let Pydantic try)
else:
result[key] = value
return result
class JobMetadata(SafeBaseModel):
class JobMetadata(BaseModel):
"""Metadata about the job."""
job_pages: int = Field(default=0, description="The number of pages in the job.")
@@ -94,31 +24,19 @@ class JobMetadata(SafeBaseModel):
)
class BBox(SafeBaseModel):
class BBox(BaseModel):
"""A bounding box."""
x: Optional[float] = Field(
default=None,
description="The x-coordinate of the bounding box.",
)
y: Optional[float] = Field(
default=None,
description="The y-coordinate of the bounding box.",
)
w: Optional[float] = Field(
default=None,
description="The width of the bounding box.",
)
h: Optional[float] = Field(
default=None,
description="The height of the bounding box.",
)
x: float = Field(description="The x-coordinate of the bounding box.")
y: float = Field(description="The y-coordinate of the bounding box.")
w: float = Field(description="The width of the bounding box.")
h: float = Field(description="The height of the bounding box.")
class PageItem(SafeBaseModel):
class PageItem(BaseModel):
"""An item in a page."""
type: str = Field(default="", description="The type of the item.")
type: str = Field(description="The type of the item.")
lvl: Optional[int] = Field(
default=None, description="The level of indentation of the item."
)
@@ -140,10 +58,10 @@ class PageItem(SafeBaseModel):
)
class ImageItem(SafeBaseModel):
class ImageItem(BaseModel):
"""An image in a page."""
name: str = Field(default="", description="The name of the image.")
name: str = Field(description="The name of the image.")
height: Optional[float] = Field(
default=None, description="The height of the image."
)
@@ -163,28 +81,22 @@ class ImageItem(SafeBaseModel):
type: Optional[str] = Field(default=None, description="The type of the image.")
class LayoutItem(SafeBaseModel):
class LayoutItem(BaseModel):
"""The layout of a page."""
image: str = Field(
default="", description="The name of the image containing the layout item"
)
confidence: float = Field(
default=0.0, description="The confidence of the layout item."
)
label: str = Field(default="", description="The label of the layout item.")
image: str = Field(description="The name of the image containing the layout item")
confidence: float = Field(description="The confidence of the layout item.")
label: str = Field(description="The label of the layout item.")
bbox: Optional[BBox] = Field(
default=None, description="The bounding box of the layout item."
)
isLikelyNoise: bool = Field(
default=False, description="Whether the layout item is likely noise."
)
isLikelyNoise: bool = Field(description="Whether the layout item is likely noise.")
class ChartItem(SafeBaseModel):
class ChartItem(BaseModel):
"""A chart in a page."""
name: str = Field(default="", description="The name of the chart.")
name: str = Field(description="The name of the chart.")
x: Optional[float] = Field(
default=None, description="The x-coordinate of the chart."
)
@@ -197,7 +109,7 @@ class ChartItem(SafeBaseModel):
)
class Page(SafeBaseModel):
class Page(BaseModel):
"""A page of the document."""
page: int = Field(default=0, description="The page number.")
@@ -252,7 +164,7 @@ class Page(SafeBaseModel):
)
class JobResult(SafeBaseModel):
class JobResult(BaseModel):
"""The raw JSON result from the LlamaParse API."""
pages: List[Page] = Field(
@@ -346,29 +258,6 @@ class JobResult(SafeBaseModel):
documents = await self.aget_text_documents(split_by_page)
return [TextNode(text=doc.text, metadata=doc.metadata) for doc in documents]
def _format_markdown_for_notebook(self, text: Optional[str]) -> Optional[str]:
"""Format markdown text for Jupyter notebook display by escaping dollar signs."""
if text is None:
return None
def escape_single_dollar_signs(text: str) -> str:
"""Escape single dollar signs in text to prevent Jupyter from interpreting them as LaTeX.
Preserves all strings of dollar signs greater than length 1,
especially preserving double dollar signs ($$) which denote LaTeX equations.
Args:
text: The text to escape
Returns:
Text with single dollar signs escaped
"""
# Replace single $ with \$, but preserve $$
# Use negative lookahead and lookbehind to match $ not preceded or followed by $
return re.sub(r"(?<!\$)\$(?!\$)", r"\$", text)
return escape_single_dollar_signs(text)
def get_markdown_documents(self, split_by_page: bool = False) -> List[Document]:
"""
Get the markdown documents from the job.
@@ -379,22 +268,17 @@ class JobResult(SafeBaseModel):
if split_by_page:
return [
Document(
text=self._format_markdown_for_notebook(page.md)
if is_jupyter()
else page.md,
text=page.md,
metadata={"page_number": page.page, "file_name": self.file_name},
)
for page in self.pages
]
else:
text = self._page_separator.join(
[page.md if page.md is not None else "" for page in self.pages]
)
return [
Document(
text=self._format_markdown_for_notebook(text)
if is_jupyter()
else text,
text=self._page_separator.join(
[page.md if page.md is not None else "" for page in self.pages]
),
metadata={"file_name": self.file_name},
)
]
@@ -444,10 +328,7 @@ class JobResult(SafeBaseModel):
"""
url = f"{self._base_url}/api/v1/parsing/job/{self.job_id}/result/raw/markdown"
response = await make_api_request(self._client, "GET", url)
markdown = response.content.decode("utf-8")
return (
self._format_markdown_for_notebook(markdown) if is_jupyter() else markdown
)
return response.content.decode("utf-8")
def get_text(self) -> str:
"""
-12
View File
@@ -1,4 +1,3 @@
import functools
import httpx
import itertools
import logging
@@ -357,17 +356,6 @@ def partition_pages(
return
@functools.lru_cache(maxsize=1)
def is_jupyter() -> bool:
"""Check if we're running in a Jupyter environment."""
try:
from IPython import get_ipython
return get_ipython().__class__.__name__ == "ZMQInteractiveShell"
except (ImportError, AttributeError):
return False
def extract_tables_from_json_results(
json_results: List[dict], download_path: str
) -> List[str]:
-37
View File
@@ -1,37 +0,0 @@
# llama_parse
## 0.6.76
### Patch Changes
- Updated dependencies [4f24f53]
- llama-cloud-services-py@0.6.76
## 0.6.75
### Patch Changes
- Updated dependencies [f81532e]
- llama-cloud-services-py@0.6.75
## 0.6.74
### Patch Changes
- Updated dependencies [1bf5223]
- Updated dependencies [24166dc]
- llama-cloud-services-py@0.6.74
## 0.6.73
### Patch Changes
- Updated dependencies [e6a7939]
- llama-cloud-services-py@0.6.73
## 0.6.72
### Patch Changes
- Updated dependencies [ad6734b]
- llama-cloud-services-py@0.6.72
-20
View File
@@ -1,20 +0,0 @@
{
"name": "llama_parse",
"version": "0.6.76",
"description": "",
"main": "index.js",
"private": false,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"llama-cloud-services-py": "workspace:*"
},
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "pnpm@10.11.1",
"devDependencies": {
"changesets": "^1.0.2"
}
}
+2 -2
View File
@@ -11,13 +11,13 @@ dev = [
[project]
name = "llama-parse"
version = "0.6.76"
version = "0.6.70"
description = "Parse files into RAG-Optimized formats."
authors = [{name = "Logan Markewich", email = "logan@llamaindex.ai"}]
requires-python = ">=3.9,<4.0"
readme = "README.md"
license = "MIT"
dependencies = ["llama-cloud-services>=0.6.76"]
dependencies = ["llama-cloud-services>=0.6.70"]
[project.scripts]
llama-parse = "llama_parse.cli.main:parse"
+3 -6
View File
@@ -1,10 +1,7 @@
{
"name": "llama-cloud-services-py",
"version": "0.6.76",
"private": false,
"version": "0.6.70",
"private": "true",
"license": "MIT",
"scripts": {},
"devDependencies": {
"changesets": "^1.0.2"
}
"scripts": {}
}
+2 -2
View File
@@ -19,7 +19,7 @@ dev = [
[project]
name = "llama-cloud-services"
version = "0.6.76"
version = "0.6.70"
description = "Tailored SDK clients for LlamaCloud services."
authors = [{name = "Logan Markewich", email = "logan@runllama.ai"}]
requires-python = ">=3.9,<4.0"
@@ -34,7 +34,7 @@ dependencies = [
"eval-type-backport>=0.2.0,<0.3 ; python_version < '3.10'",
"platformdirs>=4.3.7,<5",
"tenacity>=8.5.0, <10.0",
"packaging>=23.0"
"packaging>=25.0"
]
[project.scripts]
-34
View File
@@ -6,40 +6,6 @@ from llama_cloud_services import LlamaParse
from llama_cloud_services.parse.types import JobResult
def test_format_parse_result_markdown_for_notebook():
"""Test the _format_markdown_for_notebook function.
Right now, the only work it does is escape single dollar signs."""
result = JobResult(job_id="test", file_name="test.pdf", job_result={})
# Test None input
assert result._format_markdown_for_notebook(None) is None
# Test single dollar sign gets escaped
assert result._format_markdown_for_notebook("This costs $5") == "This costs \\$5"
# Test double dollar signs are preserved (LaTeX equations)
assert (
result._format_markdown_for_notebook("$$x^2 + y^2 = z^2$$")
== "$$x^2 + y^2 = z^2$$"
)
# Test mixed single and double dollar signs
text = "This costs $5, but $$E = mc^2$$ is priceless"
expected = "This costs \\$5, but $$E = mc^2$$ is priceless"
assert result._format_markdown_for_notebook(text) == expected
# Test multiple single dollar signs
assert result._format_markdown_for_notebook("$10 and $20") == "\\$10 and \\$20"
# Test three or more consecutive dollar signs (preserve them)
assert result._format_markdown_for_notebook("$$$") == "$$$"
# Test adjacent dollar signs with text in between
text = "$$inline$$ and $separate"
expected = "$$inline$$ and \\$separate"
assert result._format_markdown_for_notebook(text) == expected
@pytest.fixture
def file_path() -> str:
return "tests/test_files/attention_is_all_you_need.pdf"
Generated
+3 -3
View File
@@ -1,5 +1,5 @@
version = 1
revision = 3
revision = 2
requires-python = ">=3.9, <4.0"
resolution-markers = [
"python_full_version >= '3.14'",
@@ -1596,7 +1596,7 @@ wheels = [
[[package]]
name = "llama-cloud-services"
version = "0.6.73"
version = "0.6.69"
source = { editable = "." }
dependencies = [
{ name = "click", version = "8.1.8", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
@@ -1633,7 +1633,7 @@ requires-dist = [
{ name = "eval-type-backport", marker = "python_full_version < '3.10'", specifier = ">=0.2.0,<0.3" },
{ name = "llama-cloud", specifier = "==0.1.43" },
{ name = "llama-index-core", specifier = ">=0.12.0" },
{ name = "packaging", specifier = ">=23.0" },
{ name = "packaging", specifier = ">=25.0" },
{ name = "platformdirs", specifier = ">=4.3.7,<5" },
{ name = "pydantic", specifier = ">=2.8,!=2.10" },
{ name = "python-dotenv", specifier = ">=1.0.1,<2" },
+84 -139
View File
@@ -12,15 +12,14 @@ There's 2 things this does:
"""
from dataclasses import dataclass
import json
import os
import subprocess
import sys
from pathlib import Path
from typing import Any, List, cast
from typing import List
import urllib.request
import urllib.error
import re
import click
import tomlkit
@@ -28,109 +27,54 @@ from packaging.version import Version
def _run_command(
cmd: List[str], cwd: Path | None = None, env: dict[str, str] | None = None
) -> None:
"""Run a command, streaming output to the console, and raise on failure."""
subprocess.run(cmd, check=True, text=True, cwd=cwd or Path.cwd(), env=env)
def _run_and_capture(
cmd: List[str], cwd: Path | None = None, env: dict[str, str] | None = None
) -> str:
"""Run a command and return stdout as text, raising on failure."""
result = subprocess.run(
cmd,
check=True,
text=True,
cwd=cwd or Path.cwd(),
env=env,
capture_output=True,
cmd: List[str], check: bool = True, capture: bool = True, cwd: Path | None = None
) -> subprocess.CompletedProcess:
"""Run a command and return the result."""
return subprocess.run(
cmd, check=check, capture_output=capture, text=True, cwd=cwd or Path.cwd()
)
return result.stdout
@dataclass
class Package:
name: str
version: str
path: Path
def update_python_versions(version: str) -> None:
"""llama-cloud-services and llama-parse share a version. llama-parse is just a silly sidecar that proxies to llama-cloud-services
for compatibility.
def python_package_name(self) -> str | None:
if "/py/" in str(self.path) or str(self.path).endswith("/py"):
return self.name.removesuffix("-py")
return None
def _get_pnpm_workspace_packages() -> list[Package]:
"""Return directories for all workspace packages from pnpm list JSON output."""
output = _run_and_capture(["pnpm", "list", "-r", "--depth=-1", "--json"])
data = cast(list[dict[str, Any]], json.loads(output))
packages: list[Package] = [
Package(name=data["name"], version=data["version"], path=Path(data["path"]))
for data in data
]
return packages
def _sync_package_version_with_pyproject(
package_dir: Path, packages: dict[str, Package], js_package_name: str
) -> None:
"""Sync version from package.json to pyproject.toml.
Returns True if pyproject was changed, else False.
This function updates the version in both pyproject.toml files.
"""
pyproject_path = package_dir / "pyproject.toml"
if not pyproject_path.exists():
return
# Update main pyproject.toml
main_path = Path("py/pyproject.toml")
main_content = main_path.read_text()
main_doc = tomlkit.parse(main_content)
if main_doc["project"]["version"] != version:
click.echo(f"Updating llama-cloud-services version to {version}")
main_doc["project"]["version"] = version
main_path.write_text(tomlkit.dumps(main_doc))
package_version = packages[js_package_name].version
py_doc = tomlkit.parse(pyproject_path.read_text())
# Update llama_parse/pyproject.toml
parse_path = Path("py/llama_parse/pyproject.toml")
parse_content = parse_path.read_text()
parse_doc = tomlkit.parse(parse_content)
if parse_doc["project"]["version"] != version:
click.echo(f"Updating llama-parse version to {version}")
parse_doc["project"]["version"] = version
parse_path.write_text(tomlkit.dumps(parse_doc))
by_python_name = {
pkg.python_package_name(): pkg
for pkg in packages.values()
if pkg.python_package_name()
}
# Update the dependency reference
dependencies = parse_doc["project"]["dependencies"]
for i, dep in enumerate(dependencies):
if isinstance(dep, str) and dep.startswith("llama-cloud-services"):
dependencies[i] = f"llama-cloud-services>={version}"
break
current_version = py_doc["project"]["version"]
assert isinstance(current_version, str)
parse_path.write_text(tomlkit.dumps(parse_doc))
# update workspace dependency strings by replacing the first version after == or >=
deps = py_doc["project"]["dependencies"] or []
changed = False
for i, dep in enumerate(deps):
if not isinstance(dep, str):
continue
pkg = (cast(str, dep).split("==")[0]).split(">=")[0]
if pkg not in by_python_name:
continue
target_version = by_python_name[pkg].version
new_dep = re.sub(
r"(==|>=)\s*([0-9A-Za-z_.+-]+)",
lambda m: m.group(1) + target_version,
dep,
count=1,
)
if new_dep != dep:
deps[i] = new_dep
changed = True
if current_version != package_version:
py_doc["project"]["version"] = package_version
changed = True
if changed:
pyproject_path.write_text(tomlkit.dumps(py_doc))
click.echo(
f"Updated {pyproject_path} version to {package_version} and synced dependency specs"
)
click.echo(f"Updated Python packages to version {version}")
def lock_python_dependencies() -> None:
"""Lock Python dependencies."""
try:
_run_command(["uv", "lock"])
_run_command(["uv", "lock"], capture=False)
click.echo("Locked Python dependencies")
except subprocess.CalledProcessError as e:
click.echo(f"Warning: Failed to lock Python dependencies: {e}", err=True)
@@ -144,64 +88,57 @@ def cli() -> None:
@cli.command()
def version() -> None:
"""Apply changeset versions, then sync versions for co-located JS/Py packages.
"""Apply changeset versions, and propagate them to Python packages."""
# First, run changeset version to update all package.json files (including py/package.json)
_run_command(["npx", "@changesets/cli", "version"], capture=False, check=True)
- Runs changesets to bump package.json versions.
- Discovers all workspace packages via pnpm.
- For any directory containing both package.json and pyproject.toml, and with
package.json private: false, set pyproject [project].version to match the JS version.
- If a pyproject is updated, run `uv sync` in that directory to update its lock file.
"""
# Ensure we're at the repo root
os.chdir(Path(__file__).parent.parent)
# Get the updated Python package version from py/package.json (updated by changesets)
py_package_path = Path("py/package.json")
if not py_package_path.exists():
click.echo("Python package.json not found", err=True)
sys.exit(1)
# First, run changeset version to update all package.json files
_run_command(["npx", "@changesets/cli", "version"])
with open(py_package_path) as f:
py_package = json.load(f)
# Enumerate workspace packages and perform syncs
packages = _get_pnpm_workspace_packages()
version_map = {pkg.name: pkg for pkg in packages}
for pkg in packages:
_sync_package_version_with_pyproject(pkg.path, version_map, pkg.name)
new_version = py_package["version"]
# Update Python pyproject.toml files based on the package.json version
update_python_versions(new_version)
click.echo(f"Successfully propagated version {new_version} to all Python packages")
@cli.command()
@click.option("--tag", is_flag=True, help="Tag the packages after publishing")
@click.option("--dry-run", is_flag=True, help="Dry run the publish")
@click.option("--js/--no-js", default=True, help="Publish the js package")
@click.option("--py/--no-py", default=True, help="Publish the py package")
def publish(tag: bool, dry_run: bool, js: bool, py: bool) -> None:
def publish(tag: bool, dry_run: bool) -> None:
"""Publish all packages."""
# move to the root
os.chdir(Path(__file__).parent.parent)
if js:
if not os.getenv("NPM_TOKEN"):
click.echo("NPM_TOKEN is not set, skipping publish", err=True)
raise click.Abort("No token set")
if py:
if not os.getenv("LLAMA_PARSE_PYPI_TOKEN"):
click.echo("LLAMA_PARSE_PYPI_TOKEN is not set, skipping publish", err=True)
raise click.Abort("No token set")
if not os.getenv("NPM_TOKEN"):
click.echo("NPM_TOKEN is not set, skipping publish", err=True)
raise click.Abort("No token set")
if not os.getenv("LLAMA_PARSE_PYPI_TOKEN"):
click.echo("LLAMA_PARSE_PYPI_TOKEN is not set, skipping publish", err=True)
raise click.Abort("No token set")
# not general script. Just checks each of the 2 packages to see if they need to be published.
if js:
maybe_publish_npm(dry_run)
if py:
maybe_publish_pypi(dry_run)
maybe_publish_ts_package(dry_run)
maybe_publish_py_packages(dry_run)
if tag:
if dry_run:
click.echo("Dry run, skipping tag. Would run:")
click.echo(" npx @changesets/cli tag")
click.echo(" git push --tags")
return
else:
# Let changesets create JS-related tags as usual
_run_command(["npx", "@changesets/cli", "tag"])
_run_command(["git", "push", "--tags"])
_run_command(["npx", "@changesets/cli", "tag"], check=True, capture=True)
_run_command(["git", "push", "--tags"], check=True, capture=True)
def maybe_publish_npm(dry_run: bool) -> None:
def maybe_publish_ts_package(dry_run: bool) -> None:
"""Publish the ts package if it needs to be published."""
target_dir = Path("ts/llama_cloud_services")
ts_path_package = target_dir / "package.json"
@@ -209,11 +146,10 @@ def maybe_publish_npm(dry_run: bool) -> None:
version = package_json["version"]
# Check if this version is already published on npm
result = subprocess.run(
result = _run_command(
["npm", "view", "llama-cloud-services", "versions", "--json"],
check=True,
capture_output=True,
text=True,
capture=True,
cwd=target_dir,
)
@@ -223,18 +159,20 @@ def maybe_publish_npm(dry_run: bool) -> None:
f"npm package llama-cloud-services@{version} already published, skipping"
)
return
click.echo(f"Publishing npm package llama-cloud-services@{version}")
click.echo(f"Publishing llama-cloud-services@{version}")
# defer to the package.json publish script
if dry_run:
click.echo("Dry run, skipping publish. Would run:")
click.echo(" pnpm run publish")
return
else:
_run_command(["pnpm", "run", "build"], cwd=target_dir)
_run_command(["pnpm", "publish"], cwd=target_dir)
output = _run_command(
["pnpm", "runpublish"], check=True, capture=True, cwd=target_dir
)
click.echo(output.stdout)
def maybe_publish_pypi(dry_run: bool) -> None:
def maybe_publish_py_packages(dry_run: bool) -> None:
"""Publish the py packages if they need to be published."""
for pyproject in list(Path("py").glob("*/pyproject.toml")) + [
Path("py/pyproject.toml")
@@ -243,7 +181,7 @@ def maybe_publish_pypi(dry_run: bool) -> None:
if is_published(name, version):
click.echo(f"PyPI package {name}@{version} already published, skipping")
continue
click.echo(f"Publishing PyPI package {name}@{version}")
click.echo(f"Publishing {name}@{version}")
# Use different tokens for different packages
env = os.environ.copy()
@@ -254,11 +192,18 @@ def maybe_publish_pypi(dry_run: bool) -> None:
click.echo(
f"Dry run, skipping publish. Would run with publish token {summary}:"
)
click.echo(" uv build")
click.echo(" uv publish")
click.echo(" uv publish --dry-run")
return
else:
_run_command(["uv", "build"], cwd=pyproject.parent)
_run_command(["uv", "publish"], cwd=pyproject.parent, env=env)
result = subprocess.run(
["uv", "publish"],
check=True,
capture_output=True,
text=True,
cwd=pyproject.parent,
env=env,
)
click.echo(result.stdout)
def current_version(pyproject: Path) -> tuple[str, str]:
-6
View File
@@ -1,11 +1,5 @@
# llama-cloud-services
## 0.3.8
### Patch Changes
- 6e0f2f4: Agent data extraction citations can be undefined
## 0.3.7
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llama-cloud-services",
"version": "0.3.8",
"version": "0.3.7",
"type": "module",
"license": "MIT",
"scripts": {
@@ -38,7 +38,7 @@ export interface ExtractedFieldMetadata {
confidence?: number;
/** The confidence score for the field based on the extracted text only */
extraction_confidence?: number;
citation?: FieldCitation[];
citation: FieldCitation[];
}
export interface FieldCitation {