Pragmatism in the real world

Developing rst2pdf with uv

Thanks to Kyle and Lorna, we’ve moved rst2pdf‘s development out of the dark ages of setup.py and into uv with pyproject.toml.

As a result, I’ve changed the way I develop rst2pdf locally; these are my initial notes.

Set up Python environment

Given a clone of the rst2pdf git repository, do this get going:

$ uv sync --all-extras

This will create a virtual environment in .venv with all dependencies installed. It will also install Python if required.

Setup pre-commit

$ uv tool install pre-commit
$ pre-commit install --allow-missing-config

This installs pre-commit globally so it can be executed from any terminal window.

Changing Python version

If you want to use a different Python version, say 3.12:

$ echo 3.12 > .python-version
$ uv sync --all-extras

uv will install the correct Python version and ensure that the virtual environment is correct

Operations while developing

Run tests:

$ uv run pytest -n auto

Run one test:

$ uv run pytest -k test_issue_255

Run: pre-commit checks:

$ pre-commit run --all-files --show-diff-on-failure

Activate the visual environment

If you want to run pytest or rst2pdf locally, then we can activate the Virtual environment as usual:

. .venv/bin/activate

Now we can run whatever’s installed within the virtual environment directly which is convenient.

Use deactivate to turn it off.

That’s it

That’s all I’m using so far and it seems to be working as well as my previous pyenv system.

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *