uv/docs/pip/dependencies.md
Mathieu Kniewallner fd17f6d902
docs: use python to highlight requirements and use more content tabs (#6549)
## Summary

It appears that using `python` for code blocks containing requirements
works quite well.

![Screenshot from 2024-08-23
23-23-05](https://github.com/user-attachments/assets/38c92ef7-1f5e-40eb-8ea4-7024c8180bc4)

![Screenshot from 2024-08-23
23-23-31](https://github.com/user-attachments/assets/940dc7d5-22a8-4cd8-b54a-d56542d4345c)

Also using more content tabs for cases where we need to differentiate
macOS/Linux from Windows.

## Test Plan

Local run of the documentation.
2024-08-27 06:05:14 -05:00

1.6 KiB

Declaring dependencies

It is best practice to declare dependencies in a static file instead of modifying environments with ad-hoc installations. Once dependencies are defined, they can be locked to create a consistent, reproducible environment.

Using pyproject.toml

The pyproject.toml file is the Python standard for defining configuration for a project.

To define project dependencies in a pyproject.toml file:

[project]
dependencies = [
  "httpx",
  "ruff>=0.3.0"
]

To define optional dependencies in a pyproject.toml file:

[project.optional-dependencies]
cli = [
  "rich",
  "click",
]

Each of the keys defines an "extra", which can be installed using the --extra and --all-extras flags or package[<extra>] syntax. See the documentation on installing packages for more details.

See the official pyproject.toml guide for more details on getting started with a pyproject.toml.

Using requirements.in

It is also common to use a lightweight requirements.txt format to declare the dependencies for the project. Each requirement is defined on its own line. Commonly, this file is called requirements.in to distinguish it from requirements.txt which is used for the locked dependencies.

To define dependencies in a requirements.in file:

httpx
ruff>=0.3.0

Optional dependencies groups are not supported in this format.