From c6eecd1154b4b7a570be8e3d7cdfab0a3889d462 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Tue, 19 Nov 2024 09:58:40 +0000 Subject: [PATCH] install improvements --- Makefile | 4 ++++ docs/.hooks/main.py | 8 +++++--- docs/examples/index.md | 14 +++----------- docs/install.md | 38 +++++++++++++++++--------------------- pyproject.toml | 2 +- uv.lock | 2 +- 6 files changed, 31 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 5887557c3f..791203d682 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,10 @@ install: .uv .pre-commit uv sync --frozen --all-extras --group lint --group docs pre-commit install --install-hooks +.PHONY: sync # Update local packages and uv.lock +sync: .uv + uv sync --all-extras --group lint --group docs + .PHONY: format # Format the code format: uv run ruff format diff --git a/docs/.hooks/main.py b/docs/.hooks/main.py index 95469b360d..9fd324e22e 100644 --- a/docs/.hooks/main.py +++ b/docs/.hooks/main.py @@ -16,23 +16,25 @@ def on_page_markdown(markdown: str, page: Page, config: Config, files: Files) -> def replace_uv_python_run(markdown: str) -> str: - return re.sub(r'```bash\n(.*?)python/uv[\- ]run(.+?)\n```', sub_run, markdown) + return re.sub(r'```bash\n(.*?)(python/uv[\- ]run|pip/uv[\- ]add)(.+?)\n```', sub_run, markdown) def sub_run(m: re.Match[str]) -> str: prefix = m.group(1) command = m.group(2) + install = 'pip' in command + suffix = m.group(3) return f"""\ === "pip" ```bash - {prefix}python{command} + {prefix}{'pip install' if install else 'python'}{suffix} ``` === "uv" ```bash - {prefix}uv run{command} + {prefix}uv {'add' if install else 'run'}{suffix} ```""" diff --git a/docs/examples/index.md b/docs/examples/index.md index 71871d3f8c..1d0da7aeea 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -12,17 +12,9 @@ Either way you'll need to install extra dependencies to run some examples, you j If you've installed `pydantic-ai` via pip/uv, you can install the extra dependencies with: -=== "pip" - - ```bash - pip install 'pydantic-ai[examples]' - ``` - -=== "uv" - - ```bash - uv add 'pydantic-ai[examples]' - ``` +```bash +pip/uv-add 'pydantic-ai[examples]' +``` If you clone the repo, you should instead use `uv sync --extra examples` to install extra dependencies. diff --git a/docs/install.md b/docs/install.md index 2c33a32ae3..1db34c429d 100644 --- a/docs/install.md +++ b/docs/install.md @@ -2,40 +2,36 @@ PydanticAI is available [on PyPI](https://pypi.org/project/pydantic-ai/) so installation is as simple as: -=== "pip" - ```bash - pip install pydantic-ai - ``` - -=== "uv" - - ```bash - uv add pydantic-ai - ``` +```bash +pip/uv-add pydantic-ai +``` It requires Python 3.9+. +!!! note "Use `--prerelease=allow` with uv" + Until Pydantic v2.10 is released (very soon), you'll need to use `--prerelease=allow` with `uv` to install PydanticAI. + ## Use with Pydantic Logfire PydanticAI has an excellent (but completely optional) integration with [Pydantic Logfire](https://pydantic.dev/logfire) to help you view and understand agent runs. To use Logfire with PydanticAI, install PydanticAI with the `logfire` optional group: -=== "pip" +```bash +pip/uv-add 'pydantic-ai[logfire]' +``` - ```bash - pip install 'pydantic-ai[logfire]' - ``` +From there, follow the [Logfire setup cods](logfire.md#integrating-logfire) to configure Logfire. -=== "uv" +## Running Examples - ```bash - uv add 'pydantic-ai[logfire]' - ``` +PydanticAI bundles its examples so you can run them very easily. -From there, follow the [Logfire setup cods](logfire.md#integrating-logfire) to configure Logfire. +To install extra dependencies required to run examples, install the `examples` optional group: -## Next Steps +```bash +pip/uv-add 'pydantic-ai[examples]' +``` -To run PydanticAI, follow instructions [in examples](examples/index.md). +For next steps, follow instructions [in examples](examples/index.md). diff --git a/pyproject.toml b/pyproject.toml index 37a96015cc..8aa8acbdde 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ dependencies = [ [project.optional-dependencies] logfire = [ - "logfire>=2", + "logfire>=2.3", ] examples = [ "asyncpg>=0.30.0", diff --git a/uv.lock b/uv.lock index 4f5f99f2ed..0594c7bbf0 100644 --- a/uv.lock +++ b/uv.lock @@ -1480,7 +1480,7 @@ requires-dist = [ { name = "fastapi", marker = "extra == 'examples'", specifier = ">=0.115.4" }, { name = "griffe", specifier = ">=1.3.2" }, { name = "httpx", specifier = ">=0.27.2" }, - { name = "logfire", marker = "extra == 'logfire'", specifier = ">=2" }, + { name = "logfire", marker = "extra == 'logfire'", specifier = ">=2.3" }, { name = "logfire", extras = ["asyncpg", "fastapi"], marker = "extra == 'examples'", specifier = ">=2.3" }, { name = "logfire-api", specifier = ">=1.2.0" }, { name = "openai", specifier = ">=1.54.3" },