Skip to content

Commit 9dcf169

Browse files
dev: migrate to uv (#584)
1 parent 4e502e3 commit 9dcf169

File tree

10 files changed

+3358
-4480
lines changed

10 files changed

+3358
-4480
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
!alembic.ini
66
!monty/
77
!pyproject.toml
8-
!poetry.lock
8+
!uv.lock
99
!LICENSE
10+
!LICENSE_THIRD_PARTY

.github/workflows/lint_test_build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
env:
3131
RUFF_OUTPUT_FORMAT: "github"
3232

33+
3334
build:
3435
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
3536
name: Build & Push

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ repos:
2222
- id: python-check-blanket-noqa
2323
- id: python-use-type-annotations
2424

25+
- repo: https://github.com/astral-sh/uv-pre-commit
26+
rev: 0.8.19
27+
hooks:
28+
- id: uv-lock
29+
2530
- repo: https://github.com/PyCQA/isort
2631
rev: 6.0.1
2732
hooks:

CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The general workflow can be summarized as follows:
3737

3838
1. Fork + clone the repository.
3939
1. Initialize the development environment:
40-
`poetry install && poetry run prek install`.
40+
`uv sync --all-groups && uv run pre-commit install`.
4141
1. Create a new branch.
4242
1. Commit your changes, update documentation if required.
4343
1. Push the branch to your fork, and
@@ -62,7 +62,7 @@ developer at any time.
6262
- docker
6363
- docker compose
6464
- python 3.10
65-
- poetry
65+
- uv
6666

6767
Additionally, a postgresql database is required to develop Monty, but this is
6868
included in the developer
@@ -104,12 +104,12 @@ GITHUB_TOKEN=...
104104
TLDR:
105105

106106
```sh
107-
poetry install
108-
poetry run prek install
107+
uv sync --all-groups
108+
uv run prek install
109109
```
110110

111-
If you don't already have poetry installed, check the
112-
[poetry documentation](https://python-poetry.org/), or use a tool like pipx or
111+
If you don't already have uv installed, check the
112+
[uv documentation](https://docs.astral.sh/uv/), or use a tool like pipx or
113113
uvx.
114114

115115
Make sure you install prek, as it will lint every commit before its

Dockerfile

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
FROM python:3.10-slim
2+
COPY --from=ghcr.io/astral-sh/uv:0.8.19 /uv /uvx /bin/
3+
WORKDIR /app
24

3-
# Set pip to have cleaner logs and no saved cache
4-
ENV PIP_NO_CACHE_DIR=false
5+
# Enable bytecode compilation
6+
ENV UV_COMPILE_BYTECODE=1
57

6-
# Create the working directory
7-
WORKDIR /bot
8+
# Copy from the cache instead of linking since it's a mounted volume
9+
ENV UV_LINK_MODE=copy
810

9-
# Install project dependencies
11+
# Ensure installed tools can be executed out of the box
12+
ENV UV_TOOL_BIN_DIR=/usr/local/bin
13+
14+
# Set SHA build argument
15+
ARG git_sha="main"
16+
ENV GIT_SHA=$git_sha
1017

1118
# as we have a git dep, install git
1219
RUN apt update && apt install git -y
1320

14-
RUN pip install poetry==2.1.4 poetry-plugin-export==1.9.0
1521

16-
# export requirements after copying req files
17-
COPY pyproject.toml poetry.lock ./
18-
RUN poetry export --without-hashes > requirements.txt
19-
RUN pip uninstall poetry -y
20-
RUN pip install -Ur requirements.txt
22+
# Install the project's dependencies using the lockfile and settings
23+
RUN --mount=type=cache,target=/root/.cache/uv \
24+
--mount=type=bind,source=uv.lock,target=uv.lock \
25+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
26+
uv sync --locked --no-install-project --no-dev
2127

22-
# Set SHA build argument
23-
ARG git_sha="main"
24-
ENV GIT_SHA=$git_sha
28+
# Then, add the rest of the project source code and install it
29+
# Installing separately from its dependencies allows optimal layer caching
30+
COPY . /app
31+
RUN --mount=type=cache,target=/root/.cache/uv \
32+
uv sync --locked --no-dev
2533

26-
# Copy the source code in next to last to optimize rebuilding the image
27-
COPY . .
34+
# Place executables in the environment at the front of the path
35+
ENV PATH="/app/.venv/bin:$PATH"
2836

29-
# install the package using pep 517
30-
RUN pip install . --no-deps
3137

3238
ENTRYPOINT ["python3", "-m", "monty"]

docs/.readthedocs.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ build:
1111
tools:
1212
python: "3.10"
1313
jobs:
14-
post_install:
15-
- pip install poetry
16-
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --with docs
14+
create_environment:
15+
- asdf plugin add uv
16+
- asdf install uv 0.8.19
17+
- asdf global uv 0.8.19
18+
- UV_PROJECT_ENVIRONMENT=$READTHEDOCS_VIRTUALENV_PATH uv sync --no-default-groups --group docs
19+
install:
20+
- "true"
21+
22+
1723

1824
mkdocs:
1925
configuration: mkdocs.yaml

docs/future-plans.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ contributing.
2727
### Dependencies
2828

2929
- Drop some of the additional markdown parsers
30-
- Look into switching to uv from poetry
31-
32-
### Documentation
33-
34-
- Add an autodoc of all app commands to the documentation website.
3530

3631
### GitHub Parsing
3732

@@ -55,3 +50,5 @@ contributing.
5550

5651
- Rewrite the developer-side feature view command
5752
- Add contributing documentation
53+
- Migrate to uv
54+
- Add an autodoc of all app commands to the documentation website.

poetry.lock

Lines changed: 0 additions & 4401 deletions
This file was deleted.

pyproject.toml

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[build-system]
2-
requires = ["poetry-core>=2.0.0,<3"]
3-
build-backend = "poetry.core.masonry.api"
2+
requires = ["flit_core >=3.11,<4"]
3+
build-backend = "flit_core.buildapi"
44

55
[project]
6-
authors = [{ name = "aru", email = "genericusername414@gmail.com" }]
7-
license = { text = "MIT" }
8-
requires-python = ">=3.10, <4"
6+
authors = [{ name = "aru", email = "me@arielle.codes" }]
7+
license = "MIT"
8+
license-files = ["LICENSE", "LICENSE_THIRD_PARTY"]
9+
requires-python = ">=3.10"
910
name = "monty"
10-
version = "1.0.0"
11+
version = "0.0.1"
1112
description = "Helpful bot for python, github, and discord things."
1213
dependencies = [
1314
"aiodns~=3.4",
@@ -40,39 +41,38 @@ dependencies = [
4041
"readme-renderer[md] (>=44.0,<45.0)",
4142
]
4243

43-
[project.optional-dependencies]
44-
fakeredis = ["fakeredis<3.0.0,>=2.29.0"]
45-
dev = ["fakeredis<3.0.0,>=2.29.0", "watchfiles<2.0.0,>=1.0.5"]
46-
47-
[tool.poetry.group.dev.dependencies]
48-
black = "^25.9.0"
49-
ruff = "==0.13.1"
50-
isort = "==6.0.1"
51-
prek = ">=0.2.1,<0.3"
52-
taskipy = "^1.14.1"
53-
python-dotenv = "^1.1.0"
54-
pyright = "==1.1.405"
55-
msgpack-types = "^0.5.0"
56-
mdformat = "^0.7.22"
57-
mdformat-ruff = "^0.1.3"
58-
mdformat-beautysh = "^0.1.1"
59-
mdformat-gfm = "^0.4.1"
60-
mdformat-gfm-alerts = "^2.0.0"
61-
mdformat-mkdocs = "^4.4.1"
62-
mdformat-pyproject = "^0.0.2"
63-
mdformat-simple-breaks = "^0.0.1"
64-
mdformat-tables = "^1.0.0"
65-
mdformat-frontmatter = "^2.0.8"
66-
67-
68-
[tool.poetry.group.docs.dependencies]
69-
mkdocs = "^1.6.1"
70-
mkdocs-material = {version = "^9.6.20", extras = ["imaging"]}
71-
mkdocs-git-revision-date-localized-plugin = "^1.4.7"
72-
markdown-gfm-admonition = "^0.1.1"
73-
74-
[tool.poetry.requires-plugins]
75-
poetry-plugin-export = ">=1.9,<2"
44+
[dependency-groups]
45+
dev = [
46+
"fakeredis<3.0.0,>=2.29.0",
47+
"watchfiles<2.0.0,>=1.0.5",
48+
"python-dotenv<2.0.0,>=1.1.0",
49+
]
50+
tools = [
51+
"black<26.0.0,>=25.9.0",
52+
"isort==6.0.1",
53+
"poethepoet>=0.37.0",
54+
"prek>=0.2.1,<0.3",
55+
"ruff==0.13.1",
56+
]
57+
typing = ["pyright==1.1.405", "msgpack-types<1.0.0,>=0.5.0"]
58+
docs = [
59+
"mkdocs<2.0.0,>=1.6.1",
60+
"mkdocs-material[imaging]<10.0.0,>=9.6.20",
61+
"mkdocs-git-revision-date-localized-plugin<2.0.0,>=1.4.7",
62+
"markdown-gfm-admonition<1.0.0,>=0.1.1",
63+
]
64+
mdformat = [
65+
"mdformat<1.0.0,>=0.7.22",
66+
"mdformat-ruff<1.0.0,>=0.1.3",
67+
"mdformat-beautysh<1.0.0,>=0.1.1",
68+
"mdformat-gfm<1.0.0,>=0.4.1",
69+
"mdformat-gfm-alerts<3.0.0,>=2.0.0",
70+
"mdformat-mkdocs<5.0.0,>=4.4.1",
71+
"mdformat-pyproject<1.0.0,>=0.0.2",
72+
"mdformat-simple-breaks<1.0.0,>=0.0.1",
73+
"mdformat-tables<2.0.0,>=1.0.0",
74+
"mdformat-frontmatter<3.0.0,>=2.0.8",
75+
]
7676

7777
[tool.black]
7878
line-length = 120
@@ -170,14 +170,11 @@ ignore = [
170170
[tool.ruff.lint.mccabe]
171171
max-complexity = 20
172172

173-
[tool.taskipy.tasks]
174-
export = 'poetry export --without-hashes -o requirements.txt'
175-
start = "python -m monty"
176-
lint = "prek run --all-files"
177-
prek = "prek install"
173+
[tool.poe.tasks]
174+
lint = { cmd = "prek run --all-files", help = "Lint the source code" }
175+
prek = { cmd = "prek install", help = "Install the git pre-commit hooks" }
178176
pyright = { cmd = "dotenv -f task.env run -- pyright", help = "Run pyright" }
179-
html = "coverage html"
180-
report = "coverage report"
177+
sync = { cmd = "uv sync --all-groups --all-extras", help = "Sync all groups and extras to a local environment" }
181178

182179
[tool.pyright]
183180
typeCheckingMode = "basic"

0 commit comments

Comments
 (0)