uv

Issues

The usual configuration for apps in tool.uv.sources is as follows:

[tool.uv.sources]
kb-api = { path = "../api" }

I think we may need to add editable e.g:

kb-api = { path = "../api", editable = true }

Tip

For more information, see Editable dependencies and Path

Release

# check branches
kb.py
# check branches - and switch if necessary
kb.py --checkout
# check branches - switch if necessary - and pull
kb.py --checkout --pull
# check uv is happy (although I think 'bump' does the same)
uv sync

# version number increment
uv version --bump patch
# add the files, then commit
git commit -m "chore: 'pyproject.toml' - bump version"
# release
kb.py --release
# push
git push

Convert to pyproject.toml

Tip

Check existing branches - main may not be the best one to use!

Update uv:

uv self update

Create a branch:

git pull
# Check existing branches - 'main' may not be the best one to use!
git checkout -b 7043-pyproject-toml

Create a pyproject.toml file:

uv init --no-workspace
rm main.py README.md
vim pyproject.toml

# Prepend the 'name' with `kb-'
name = "kb-api"

# Change 'readme' to 'README.rst'
readme = "README.rst"

# python version
requires-python = ">=3.10"

Virtual Environment:

# Create a virtual environment in '.venv' (uv style)
uv venv
# Update 'env' and 'env.fish' to use '.venv' **AND**
set -x PYTHONPATH "src/"
echo "PYTHONPATH: "$PYTHONPATH

Requirements:

# Update the old-style requirements files
# '--create-apps-txt' will only work for projects (not apps)
kb.py --create-apps-txt
# Remove the 'dynamic' section from 'pyproject.toml'
dynamic = ["dependencies", "optional-dependencies"]

Update requirements/base.txt, then add:

uv add -r requirements/base.txt

Remove requirements/base.txt:

git rm -f requirements/base.txt

For an app, remove -r base.txt from requirements/local.txt:

# Remove the following
# --r base.txt

uv add -r requirements/local.txt --group dev
git rm -f requirements/local.txt

For a project:

uv add -r requirements/dev.txt --group dev
# Remove '-r base.txt' from 'requirements/production.txt'
uv add -r requirements/production.txt --group production

Tools in pyproject.toml:

# Add options for pytest - update folder for ``dev_test``!!!
[tool.pytest.ini_options]
addopts= "--ds=settings.dev_test --cov-report html --reuse-db --fail-on-template-vars"
norecursedirs = ".git venv-* build"

[tool.ruff]
line-length = 80
indent-width = 4

[[tool.uv.index]]
name = "dev"
url = "http://salt.kb.vpn/kb/dev/+simple/"
default = true
publish-url = "http://salt.kb.vpn/kb/dev/"

Move source code to the src folder:

mkdir src
git mv api src/

Remove old setup files:

git rm setup.cfg setup.py setup.yaml

Update MANIFEST.in (prepend src):

# replace
# recursive-include base/static *
# recursive-include base/templates *
#
# include LICENSE
# include README
# include requirements/*.txt
# include *.ttf
# include *.txt
#
# prune example_base/

# with
recursive-include src/base/static *
recursive-include src/base/templates *

Tip

If you forgot to do this, then make sure to run uv pip install --group dev in the project which uses your app.

Install requirements:

# why does 'uv sync --group dev' remove our apps?
uv pip install --group dev

Make sure the tests are passing:

rm -rf build/; and pytest

Build:

# https://docs.astral.sh/uv/guides/package/#updating-your-version
uv version --bump patch
rm -rf dist/; and uv build

Publish:

# Add the following to '.private.fish'
set -x UV_PUBLISH_USERNAME "my-user"
set -x UV_PUBLISH_PASSWORD "my-pass"

uv publish --index dev

Compare pyproject.toml with an existing version to update as necessary…