Skip to content

Commit a440708

Browse files
authored
build: migrate from poetry to uv (#37)
1 parent f7bc520 commit a440708

File tree

12 files changed

+2299
-4114
lines changed

12 files changed

+2299
-4114
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 2
22
updates:
3-
- package-ecosystem: "pip"
3+
- package-ecosystem: "uv"
44
directory: "/"
55
schedule:
66
interval: "weekly"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
on:
22
pull_request_target:
3-
types: [ opened, edited ]
3+
types: [opened, edited]
44
name: conventional-release-labels
55
jobs:
66
label:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: bcoe/conventional-release-labels@v1
1010
with:
11-
type_labels: '{"feat": "feature", "fix": "fix", "breaking": "breaking", "ci": "CI"}'
11+
type_labels: '{"feat": "feature", "fix": "fix", "breaking": "breaking", "ci": "CI", "build": "build", "refactor": "refactor"}'

.github/workflows/lint.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,18 @@ jobs:
1414
if: "!startsWith(github.event.head_commit.message, 'bump:')"
1515
steps:
1616
- uses: actions/checkout@v4
17-
- name: Set up Python 3.13
18-
uses: actions/setup-python@v4
19-
with:
20-
python-version: "3.13"
2117

22-
- name: Install dependencies
23-
run: |
24-
python -m pip install --upgrade pip
25-
python -m pip install poetry
26-
poetry install --with test,lint
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@v6
20+
21+
- name: Install the project
22+
run: uv sync --locked --extra lint --extra test
2723

2824
- name: Lint
2925
run: |
30-
poetry run ruff format --check src tests eval
31-
poetry run ruff check src tests eval
32-
poetry run mypy src tests eval
26+
uv run ruff format --check src tests eval
27+
uv run ruff check src tests eval
28+
uv run mypy src tests eval
3329
3430
lint-commit:
3531
runs-on: ubuntu-latest

.github/workflows/security.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,3 @@ jobs:
2929
- name: Run Semgrep
3030
run: |
3131
semgrep scan --config auto
32-
twyn:
33-
runs-on: ubuntu-latest
34-
if: "!startsWith(github.event.head_commit.message, 'bump:')"
35-
container:
36-
image: elementsinteractive/twyn:v2.8.28
37-
steps:
38-
- uses: actions/checkout@v4
39-
- name: Run Twyn against our dependencies
40-
run: |
41-
twyn run -vv

.github/workflows/test.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ jobs:
1414
if: "!startsWith(github.event.head_commit.message, 'bump:')"
1515
steps:
1616
- uses: actions/checkout@v4
17-
- name: Set up Python
18-
uses: actions/setup-python@v4
19-
with:
20-
python-version: "3.13"
2117

22-
- name: Install dependencies
23-
run: |
24-
python -m pip install --upgrade pip
25-
python -m pip install poetry
26-
poetry install --with test
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@v6
2720

28-
- name: Test with pytest
29-
run: |
30-
poetry run pytest
21+
- name: Install the project
22+
run: uv sync --locked --extra test
23+
24+
- name: Run tests
25+
run: uv run pytest tests

.pre-commit-config.yaml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
default_install_hook_types: [pre-push, pre-commit]
22
default_stages:
3-
- "push"
3+
- "push"
44
repos:
5-
- repo: local
6-
hooks:
7-
- id: lint
8-
name: Lint Code
9-
entry: "just lint"
10-
language: system
11-
pass_filenames: false
12-
- id: spell-check
13-
name: Spell Checking Docs
14-
entry: "just spellcheck"
15-
language: system
16-
pass_filenames: false
17-
- id: lint-commit
18-
name: Lint Commits
19-
entry: "just lint-commit"
20-
language: system
21-
pass_filenames: false
22-
- id: poetry-check
23-
name: Poetry lock Consistency
24-
entry: "poetry lock --check"
25-
language: system
26-
pass_filenames: false
27-
- id: format-code
28-
name: Format Code
29-
entry: "just format"
30-
language: system
31-
files: .*\.py$
32-
stages:
33-
- "commit"
5+
- repo: local
6+
hooks:
7+
- id: lint
8+
name: Lint Code
9+
entry: "just lint"
10+
language: system
11+
pass_filenames: false
12+
- id: spell-check
13+
name: Spell Checking Docs
14+
entry: "just spellcheck"
15+
language: system
16+
pass_filenames: false
17+
- id: lint-commit
18+
name: Lint Commits
19+
entry: "just lint-commit"
20+
language: system
21+
pass_filenames: false
22+
- id: uv-check
23+
name: uv lock Consistency
24+
entry: "uv sync --frozen"
25+
language: system
26+
pass_filenames: false
27+
- id: format-code
28+
name: Format Code
29+
entry: "just format"
30+
language: system
31+
files: .*\.py$
32+
stages:
33+
- "commit"

Dockerfile

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ARG USER=lightman
88
ARG GROUP=lightman
99
ARG WORKDIR=/app
1010
ARG VENV_PATH=${WORKDIR}/.venv
11+
ARG BIN_PATH=${VENV_PATH}/bin
1112

1213
WORKDIR ${WORKDIR}
1314

@@ -19,52 +20,46 @@ RUN groupadd -g 1001 ${GROUP} && \
1920
FROM base AS build
2021

2122
# Define stage variables
22-
ARG POETRY_VERSION=2.1.2
23-
ARG POETRY_PLUGIN_EXPORT_VERSION=1.9.0
24-
25-
# These should never change, define as ENV
26-
ENV POETRY_HOME="/opt/poetry"
27-
ENV PATH="${POETRY_HOME}/bin:${PATH}"
28-
29-
# Create venv and upgrade pip
30-
RUN python -m venv ${VENV_PATH} && \
31-
${VENV_PATH}/bin/pip install --no-cache-dir --upgrade pip
32-
23+
ARG UV_VERSION 0.8.0
24+
# Install curl for uv installation
3325
RUN apt-get update && apt-get install -y --no-install-recommends \
3426
curl \
3527
&& rm -rf /var/lib/apt/lists/*
3628

37-
RUN pip install poetry==2.1.2
38-
RUN poetry self add poetry-plugin-export==${POETRY_PLUGIN_EXPORT_VERSION}
29+
ADD https://astral.sh/uv/install.sh /uv-installer.sh
3930

40-
# Copy all the needed files, without write permissions
41-
COPY poetry.lock pyproject.toml ./
31+
# Run the installer then remove it
32+
RUN curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | sh
4233

43-
# Export dependencies to requirements.txt (no dev deps)
44-
RUN poetry export --without-hashes --only main -f requirements.txt > requirements.txt
34+
# Ensure the installed binary is on the `PATH`
35+
ENV PATH="/root/.local/bin/:$PATH"
4536

46-
# Create and install dependencies in the virtual env
47-
RUN ${VENV_PATH}/bin/pip install --no-cache-dir -r requirements.txt
37+
# Copy dependency files
38+
COPY uv.lock pyproject.toml ./
4839

40+
# Install dependencies using uv (only dependencies, not the project itself)
41+
RUN UV_PROJECT_ENVIRONMENT=${VENV_PATH} uv sync --frozen --no-install-project
42+
RUN ${BIN_PATH}/python -m ensurepip
4943
# --------------- `final` stage ---------------
5044
FROM base AS final
5145

5246
# Set non-root user and group
5347
USER ${USER}:${GROUP}
5448

55-
# Copy over the virtual environment with all its dependencies and the project installed
56-
COPY --from=build ${WORKDIR}/requirements.txt requirements.txt
57-
ENV PATH="${VENV_PATH}/bin:$PATH"
58-
59-
# Copy venv with all its dependencies along with pyproject.toml
49+
# Copy the virtual environment from build stage
6050
COPY --from=build --chown=${USER}:${GROUP} ${VENV_PATH} ${VENV_PATH}
51+
52+
# Set PATH to use the virtual environment
53+
ENV PATH="${BIN_PATH}:$PATH"
54+
55+
# Copy pyproject.toml for package metadata
6156
COPY --from=build --chown=${USER}:${GROUP} ${WORKDIR}/pyproject.toml .
6257

6358
COPY README.md README.md
6459
# Copy source code
6560
COPY src src
6661

67-
# Install the CLI tool
68-
RUN $VENV_PATH/bin/pip install --no-cache-dir .
62+
# Install the CLI tool (dependencies already installed in venv)
63+
RUN ${BIN_PATH}/pip3 install --no-deps .
6964

70-
ENTRYPOINT [ "lightman" ]
65+
ENTRYPOINT [ "lightman-ai" ]

justfile

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,39 @@
1-
21
# VARIABLE DEFINITIONS
32
venv := ".venv"
4-
bin := venv + "/bin"
5-
python_version := "python3.13"
6-
run := "poetry run"
7-
target_dirs := "src tests eval"
8-
eval_path := "eval/cli.py"
9-
# SENTINELS
10-
venv-exists := path_exists(venv)
3+
python_version :="3.13"
4+
115

12-
# RECIPES
6+
target_dirs := "src tests"
137

14-
# Shows list of recipes.
8+
# ALIASES
9+
alias t := test
1510
help:
1611
just --list --unsorted
1712

18-
# Generate the virtual environment.
19-
venv:
20-
@if ! {{ venv-exists }}; \
21-
then \
22-
POETRY_VIRTUALENVS_IN_PROJECT=1 poetry env use {{ python_version }}; \
23-
poetry install; \
24-
fi
13+
# Cleans all artifacts generated while running this project, including the virtualenv.
14+
venv:
15+
@uv sync --group test --group lint --group local
16+
2517

2618
# Cleans all artifacts generated while running this project, including the virtualenv.
2719
clean:
2820
@rm -f .coverage*
2921
@rm -rf {{ venv }}
3022

31-
# Runs the evaluation script
32-
eval *args: venv
33-
PYTHONPATH=. {{ run }} python {{ eval_path }} {{ args }}
34-
35-
alias t := test
3623
# Runs the tests with the specified arguments (any path or pytest argument).
37-
test *test-args='': venv
38-
{{ run }} pytest {{ test-args }} --no-cov
24+
test *test-args='':
25+
uv run pytest {{ test-args }} --no-cov
3926

4027
# Runs all tests including coverage report.
41-
test-all: venv
42-
{{ run }} pytest
28+
test-all:
29+
uv run pytest
4330

4431
# Format all code in the project.
45-
format *files=target_dirs: venv
46-
{{ run }} ruff check {{ files }} --fix
47-
{{ run }} ruff format {{ files }}
32+
format:
33+
uv run ruff check {{ target_dirs }} --fix
4834

4935
# Lint all code in the project.
50-
lint report="false": venv
51-
{{ run }} ruff format --check {{ target_dirs }}
52-
{{ run }} ruff check {{ target_dirs }} {{ if report == "true" { "--output-format gitlab > tests/gl-code-quality-report.json" } else { "" } }}
53-
{{ run }} mypy {{ target_dirs }}
54-
55-
# Runs pre-commit with the given arguments (defaults to install).
56-
pre-commit *precommit-args="install": venv
57-
{{ run }} pre-commit {{ precommit-args }}
58-
59-
# Spellchecks your markdown files.
60-
spellcheck *codespell-args: venv
61-
{{ run }} codespell {{ codespell-args }} **/*.md
62-
63-
# Lints commit messages according to conventional commit rules.
64-
lint-commit: venv
65-
{{ run }} cz check --rev-range main..HEAD
66-
36+
lint:
37+
uv run ruff check {{ target_dirs }}
38+
uv run mypy {{ target_dirs }}
6739

lgtm.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
technologies = ["Python"]
22
categories = ["Correctness", "Quality", "Testing", "Security"]
3-
exclude = ["*.md", "poetry.lock", "eval/classified_articles.py"]
3+
exclude = ["*.md", "uv.lock", "eval/classified_articles.py"]
44
model = "gemini-2.5-pro-preview-*"
55
silent = false
66
publish = true

0 commit comments

Comments
 (0)