Skip to content

Latest commit

 

History

History
79 lines (62 loc) · 1.58 KB

README.md

File metadata and controls

79 lines (62 loc) · 1.58 KB

uv Demo

Steps

  1. Install uv:
$ curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Create a new project (with the --lib option):
$ uv init --lib uv-demo

Tip

The --lib option specifies the build-system for us in pyproject.toml and creates the project in the src layout.

  1. Add dependencies (requests, polars, pytest, ruff)
    • Note: Add pytest and ruff under the dev group.
$ uv add requests
$ uv add polars
$ uv add --dev pytest
$ uv add --dev ruff

Those commands added the following sections to our initial pyproject.toml file, and created/updated a uv.lock file.

[project]
name = "uv-demo"
version = "0.1.0"
description = ""
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "polars>=1.6.0",
    "requests>=2.32.3",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
    "pytest>=8.3.2",
    "ruff>=0.6.3",
]
  1. Add code (demo.py, __init__.py, __main__.py) and tests (test_demo.py).

  2. Run tests and lint/format code:

$ uv run pytest
$ uv run ruff check --fix
$ uv run ruff format
  1. Run the app:
$ uv run python -m uv_demo

Or, add the following section to pyproject.toml:

[project.scripts]
"uv-demo" = "uv_demo:main"

to run it more directly:

$ uv run uv-demo
  1. Add uv-based GH workflow to lint and run tests.