From 9436701181845c504df0457a258a64d6e65bd53e Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Fri, 21 Nov 2025 16:43:55 +0800 Subject: [PATCH] fix: exclude unneeded filed from sdist build - LInt and fix examples/* - Switch to pdm.backend - Exclude .uv-cache and .github from sdist build Signed-off-by: Frost Ming --- examples/agent.py | 3 +-- examples/client.py | 8 ++++---- examples/duet.py | 6 ++---- examples/echo_agent.py | 1 - examples/gemini.py | 31 ++++++++++++++----------------- pyproject.toml | 18 +++++++++++------- scripts/gen_all.py | 2 +- scripts/gen_meta.py | 2 +- scripts/gen_schema.py | 2 +- src/acp/__init__.py | 2 +- 10 files changed, 36 insertions(+), 39 deletions(-) diff --git a/examples/agent.py b/examples/agent.py index 3366817..6960bb5 100644 --- a/examples/agent.py +++ b/examples/agent.py @@ -3,8 +3,8 @@ from typing import Any from acp import ( + PROTOCOL_VERSION, Agent, - AgentSideConnection, AuthenticateResponse, InitializeResponse, LoadSessionResponse, @@ -14,7 +14,6 @@ run_agent, text_block, update_agent_message, - PROTOCOL_VERSION, ) from acp.interfaces import Client from acp.schema import ( diff --git a/examples/client.py b/examples/client.py index 7a0cc27..be38edb 100644 --- a/examples/client.py +++ b/examples/client.py @@ -8,11 +8,11 @@ from typing import Any from acp import ( + PROTOCOL_VERSION, Client, - connect_to_agent, RequestError, + connect_to_agent, text_block, - PROTOCOL_VERSION, ) from acp.core import ClientSideConnection from acp.schema import ( @@ -154,8 +154,8 @@ async def interactive_loop(conn: ClientSideConnection, session_id: str) -> None: session_id=session_id, prompt=[text_block(line)], ) - except Exception as exc: # noqa: BLE001 - logging.error("Prompt failed: %s", exc) + except Exception as exc: + logging.error("Prompt failed: %s", exc) # noqa: TRY400 async def main(argv: list[str]) -> int: diff --git a/examples/duet.py b/examples/duet.py index f2c2871..9d6facb 100644 --- a/examples/duet.py +++ b/examples/duet.py @@ -4,6 +4,8 @@ import sys from pathlib import Path +from acp import PROTOCOL_VERSION, spawn_agent_process + def _load_client_module(path: Path): spec = importlib.util.spec_from_file_location("examples_client", path) @@ -15,10 +17,6 @@ def _load_client_module(path: Path): return module -from acp import PROTOCOL_VERSION, spawn_agent_process -from acp.schema import InitializeRequest, NewSessionRequest - - async def main() -> int: root = Path(__file__).resolve().parent agent_path = root / "agent.py" diff --git a/examples/echo_agent.py b/examples/echo_agent.py index 282a205..338e698 100644 --- a/examples/echo_agent.py +++ b/examples/echo_agent.py @@ -4,7 +4,6 @@ from acp import ( Agent, - AgentSideConnection, InitializeResponse, NewSessionResponse, PromptResponse, diff --git a/examples/gemini.py b/examples/gemini.py index e9ec79c..937bbe7 100644 --- a/examples/gemini.py +++ b/examples/gemini.py @@ -8,14 +8,15 @@ import os import shutil import sys +from collections.abc import Iterable from pathlib import Path -from typing import Any, Iterable +from typing import Any from acp import ( - Client, - connect_to_agent, PROTOCOL_VERSION, + Client, RequestError, + connect_to_agent, text_block, ) from acp.core import ClientSideConnection @@ -25,26 +26,22 @@ AgentThoughtChunk, AllowedOutcome, AvailableCommandsUpdate, - CancelNotification, ClientCapabilities, + CreateTerminalResponse, CurrentModeUpdate, + DeniedOutcome, + EmbeddedResourceContentBlock, EnvVariable, FileEditToolCallContent, FileSystemCapability, - CreateTerminalResponse, - DeniedOutcome, - EmbeddedResourceContentBlock, KillTerminalCommandResponse, - InitializeRequest, - NewSessionRequest, PermissionOption, - PromptRequest, ReadTextFileResponse, + ReleaseTerminalResponse, RequestPermissionResponse, ResourceContentBlock, - ReleaseTerminalResponse, - TerminalToolCallContent, TerminalOutputResponse, + TerminalToolCallContent, TextContentBlock, ToolCall, ToolCallProgress, @@ -115,7 +112,7 @@ async def read_text_file( text = _slice_text(text, line, limit) return ReadTextFileResponse(content=text) - async def session_update( + async def session_update( # noqa: C901 self, session_id: str, update: UserMessageChunk @@ -259,7 +256,7 @@ async def interactive_loop(conn: ClientSideConnection, session_id: str) -> None: ) except RequestError as err: _print_request_error("prompt", err) - except Exception as exc: # noqa: BLE001 + except Exception as exc: print(f"Prompt failed: {exc}", file=sys.stderr) @@ -275,7 +272,7 @@ def _resolve_gemini_cli(binary: str | None) -> str: raise FileNotFoundError("Unable to locate `gemini` CLI, provide --gemini path") -async def run(argv: list[str]) -> int: +async def run(argv: list[str]) -> int: # noqa: C901 parser = argparse.ArgumentParser(description="Interact with the Gemini CLI over ACP.") parser.add_argument("--gemini", help="Path to the Gemini CLI binary") parser.add_argument("--model", help="Model identifier to pass to Gemini") @@ -331,7 +328,7 @@ async def run(argv: list[str]) -> int: _print_request_error("initialize", err) await _shutdown(proc, conn) return 1 - except Exception as exc: # noqa: BLE001 + except Exception as exc: print(f"initialize error: {exc}", file=sys.stderr) await _shutdown(proc, conn) return 1 @@ -347,7 +344,7 @@ async def run(argv: list[str]) -> int: _print_request_error("new_session", err) await _shutdown(proc, conn) return 1 - except Exception as exc: # noqa: BLE001 + except Exception as exc: print(f"new_session error: {exc}", file=sys.stderr) await _shutdown(proc, conn) return 1 diff --git a/pyproject.toml b/pyproject.toml index 4ad791a..14e47d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,10 @@ name = "agent-client-protocol" version = "0.6.3" description = "A Python implement of Agent Client Protocol (ACP, by Zed Industries)" -authors = [{ name = "Chojan Shang", email = "psiace@apache.org" }] +authors = [ + { name = "Chojan Shang", email = "psiace@apache.org" }, + { name = "Frost Ming", email = "me@frostming.com" }, +] readme = "README.md" keywords = ['python'] requires-python = ">=3.10,<3.15" @@ -18,7 +21,7 @@ classifiers = [ "Topic :: Software Development :: Libraries :: Python Modules", ] dependencies = [ - "pydantic>=2.7", + "pydantic>=2.7", ] @@ -47,11 +50,11 @@ dev = [ logfire = ["logfire>=0.14", "opentelemetry-sdk>=1.28.0"] [build-system] -requires = ["hatchling"] -build-backend = "hatchling.build" +requires = ["pdm-backend"] +build-backend = "pdm.backend" -[tool.hatch.build.targets.wheel] -packages = ["src/acp"] +[tool.pdm.build] +source-includes = ["examples/", "tests/"] [tool.ty.environment] python = "./.venv" @@ -103,11 +106,12 @@ ignore = [ "E501", # DoNotAssignLambda "E731", + # Long exception message + "TRY003", ] [tool.ruff.lint.per-file-ignores] "tests/*" = ["S101"] -"examples/*" = ["ALL"] "src/acp/meta.py" = ["ALL"] "src/acp/schema.py" = ["ALL"] diff --git a/scripts/gen_all.py b/scripts/gen_all.py index 872a98a..1279aeb 100644 --- a/scripts/gen_all.py +++ b/scripts/gen_all.py @@ -129,7 +129,7 @@ def fetch_json(url: str) -> dict: with urllib.request.urlopen(url) as response: # noqa: S310 - trusted source configured by repo return json.loads(response.read().decode("utf-8")) except urllib.error.URLError as exc: - raise RuntimeError(f"Failed to fetch {url}: {exc}") from exc # noqa: TRY003 + raise RuntimeError(f"Failed to fetch {url}: {exc}") from exc def _cached_ref() -> str | None: diff --git a/scripts/gen_meta.py b/scripts/gen_meta.py index 4eb43c5..f6082e5 100644 --- a/scripts/gen_meta.py +++ b/scripts/gen_meta.py @@ -17,7 +17,7 @@ def generate_meta() -> None: meta_json = SCHEMA_DIR / "meta.json" out_py = ROOT / "src" / "acp" / "meta.py" if not meta_json.exists(): - raise SystemExit("schema/meta.json not found. Run gen_schema.py first.") # noqa: TRY003 + raise SystemExit("schema/meta.json not found. Run gen_schema.py first.") data = json.loads(meta_json.read_text("utf-8")) agent_methods = data.get("agentMethods", {}) diff --git a/scripts/gen_schema.py b/scripts/gen_schema.py index d340426..6763677 100644 --- a/scripts/gen_schema.py +++ b/scripts/gen_schema.py @@ -164,7 +164,7 @@ def generate_schema() -> None: def postprocess_generated_schema(output_path: Path) -> list[str]: if not output_path.exists(): - raise RuntimeError(f"Generated schema not found at {output_path}") # noqa: TRY003 + raise RuntimeError(f"Generated schema not found at {output_path}") raw_content = output_path.read_text(encoding="utf-8") header_block = _build_header_block() diff --git a/src/acp/__init__.py b/src/acp/__init__.py index a25e664..71a693f 100644 --- a/src/acp/__init__.py +++ b/src/acp/__init__.py @@ -178,4 +178,4 @@ def __getattr__(name: str) -> Any: module_name, attr_name = new_path.split(":") module = import_module(module_name) return getattr(module, attr_name) - raise AttributeError(f"module {__name__} has no attribute {name}") # noqa: TRY003 + raise AttributeError(f"module {__name__} has no attribute {name}")