# Python

Build, test and cache Python projects managed by uv or Poetry alongside JavaScript packages.

The Python plugin lets Axle see the Python projects in a repository, so a repository of JavaScript packages and Python projects builds in one run, in dependency order, from the cache when nothing changed. It reads projects managed by [uv](https://docs.astral.sh/uv/) and by [Poetry](https://python-poetry.org/). It's written in Python and runs with uv.

## Add it

```sh
axle add python
```

This writes it into the root `axle.toml`:

```toml
[plugins.python]
source = "npm:@axle-rs/plugin-python@0.1.0"
hash = "sha256-…"
```

It needs `uv` on the `PATH`, and runs with a Python of 3.12 or newer that uv finds or installs.

## What it finds

Each `pyproject.toml` with a name, under `[project]` or Poetry's `[tool.poetry]`, is a project: the members of every uv workspace, as `members` and `exclude` under `[tool.uv.workspace]` say, and projects outside any workspace. `axle list` shows them with the kind `plugin`. Files Git ignores are skipped, and so are folders named `.venv`, `node_modules`, `__pycache__` and `.git`, a project at the root of the repository and a folder that is already a package.

A project depends on another project the plugin found when it names it in `dependencies`, `optional-dependencies` or `[dependency-groups]`, or in Poetry's `[tool.poetry.dependencies]` and its groups, so its tasks wait for that project's. Names compare the way Python's do, so `My_Lib` and `my-lib` are the same.

## Versions and the cache

The plugin reads the versions each project uses from its workspace's `uv.lock`, through every dependency of its dependencies, or from a Poetry project's own `poetry.lock`, and Axle hashes them like a JavaScript lockfile. A new version of a package misses the cache of the projects that use it and no others. The lockfile itself isn't among the files every task reads, and `--affected` counts a change to it against every Python project.

The plugin's answers are kept until a `pyproject.toml`, `uv.lock`, `poetry.lock` or `.gitignore` changes.

## Tasks

Each project gets a `build` task, with `outputs = ["dist/**"]`: `uv build --out-dir dist`, or `poetry build --output dist` for a Poetry project. A project is a Poetry project when its `pyproject.toml` has `[tool.poetry]` or Poetry's build backend, or its folder has a `poetry.lock`, and it isn't in a uv workspace and has no `uv.lock`; its tasks need `poetry` on the `PATH`. `tasks` in the plugin's settings adds tasks or changes them for every Python project:

```toml
[plugins.python]
source = "npm:@axle-rs/plugin-python@0.1.0"
hash = "sha256-…"
tasks = { test = "uv run pytest", lint = { command = "uv run ruff check", cache = false }, build = false }
```

A task is a command, a table with a `command` and any [task settings](https://axlers.dev/docs/reference/configuration.md#tasks), or `false` to leave it out. A project's own `axle.toml` and the root one change them as they would any task, and win over the plugin.
