dev: Migrate to uv (#6470)

This commit is contained in:
Michael Genson
2025-11-01 14:36:40 -05:00
committed by GitHub
parent 01713b0416
commit 75616d66b8
16 changed files with 2191 additions and 4223 deletions

View File

@@ -8,28 +8,13 @@ FROM mcr.microsoft.com/devcontainers/python:${VARIANT}
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
# install poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN echo "export PROMPT_COMMAND='history -a'" >> /home/vscode/.bashrc \
&& echo "export HISTFILE=~/commandhistory/.bash_history" >> /home/vscode/.bashrc \
&& chown vscode:vscode -R /home/vscode/
RUN npm install -g @go-task/cli
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true
# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$PATH"
RUN curl -sSL https://install.python-poetry.org | python3 -
# RUN poetry config virtualenvs.create false
# Install additional OS packages
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
curl \
@@ -39,5 +24,9 @@ RUN apt-get update \
libsasl2-dev libldap2-dev libssl-dev \
gnupg gnupg2 gnupg1
# create directory used for Docker Secrets
# Install uv
RUN pip install uv
ENV UV_LINK_MODE=copy
# Create directory for Docker Secrets
RUN mkdir -p /run/secrets

View File

@@ -48,7 +48,7 @@
],
// Use 'onCreateCommand' to run commands at the end of container creation.
// Use 'postCreateCommand' to run commands after the container is created.
"onCreateCommand": "sudo chown -R vscode:vscode /workspaces/mealie/frontend/node_modules /home/vscode/commandhistory && task setup",
"onCreateCommand": "sudo chown -R vscode:vscode /workspaces/mealie/frontend/node_modules /home/vscode/commandhistory && task setup --force",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {

View File

@@ -70,13 +70,8 @@ jobs:
with:
python-version: "3.12"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
plugins: |
poetry-plugin-export
- name: Install uv
run: pip install uv
- name: Retrieve built frontend
uses: actions/download-artifact@v4

View File

@@ -25,24 +25,21 @@ jobs:
with:
python-version: "3.12"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install uv
run: pip install uv
- name: Load cached venv
id: cached-poetry-dependencies
id: cached-python-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
key: venv-${{ runner.os }}-${{ hashFiles('**/uv.lock') }}
- name: Check venv cache
id: cache-validate
if: steps.cached-poetry-dependencies.outputs.cache-hit == 'true'
if: steps.cached-python-dependencies.outputs.cache-hit == 'true'
run: |
echo "import fastapi;print('venv good?')" > test.py && poetry run python test.py && echo "cache-hit-success=true" >> $GITHUB_OUTPUT
echo "import fastapi;print('venv good?')" > test.py && uv run python test.py && echo "cache-hit-success=true" >> $GITHUB_OUTPUT
rm test.py
continue-on-error: true
@@ -50,13 +47,13 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install libsasl2-dev libldap2-dev libssl-dev
poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
uv sync --group dev
if: steps.cached-python-dependencies.outputs.cache-hit != 'true'
- name: Run locale generation
run: |
cd dev/code-generation
poetry run python main.py locales
uv run python main.py locales
env:
CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }}

View File

@@ -49,24 +49,21 @@ jobs:
with:
python-version: "3.12"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install uv
run: pip install uv
- name: Load cached venv
id: cached-poetry-dependencies
id: cached-python-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
key: venv-${{ runner.os }}-${{ hashFiles('**/uv.lock') }}
- name: Check venv cache
id: cache-validate
if: steps.cached-poetry-dependencies.outputs.cache-hit == 'true'
if: steps.cached-python-dependencies.outputs.cache-hit == 'true'
run: |
echo "import fastapi;print('venv good?')" > test.py && poetry run python test.py && echo "cache-hit-success=true" >> $GITHUB_OUTPUT
echo "import fastapi;print('venv good?')" > test.py && uv run python test.py && echo "cache-hit-success=true" >> $GITHUB_OUTPUT
rm test.py
continue-on-error: true
@@ -74,13 +71,12 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install libsasl2-dev libldap2-dev libssl-dev
poetry install
poetry add "psycopg2-binary==2.9.9"
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' || steps.cache-validate.outputs.cache-hit-success != 'true'
uv sync --group dev --extra pgsql
if: steps.cached-python-dependencies.outputs.cache-hit != 'true' || steps.cache-validate.outputs.cache-hit-success != 'true'
- name: Formatting (Ruff)
run: |
poetry run ruff format . --check
uv run ruff format . --check
- name: Lint (Ruff)
run: |

View File

@@ -55,7 +55,7 @@
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"package.json": "package-lock.json, yarn.lock, .eslintrc.js, tsconfig.json, .prettierrc, .editorconfig",
"pyproject.toml": "poetry.lock, alembic.ini, .pylintrc",
"pyproject.toml": "uv.lock, alembic.ini, .pylintrc",
"netlify.toml": "runtime.txt",
"README.md": "LICENSE, SECURITY.md"
},

View File

@@ -28,7 +28,7 @@ tasks:
docs:gen:
desc: runs the API documentation generator
cmds:
- poetry run python dev/code-generation/gen_docs_api.py
- uv run python dev/code-generation/gen_docs_api.py
docs:
desc: runs the documentation server
@@ -36,7 +36,7 @@ tasks:
deps:
- docs:gen
cmds:
- poetry run python -m mkdocs serve
- uv run python -m mkdocs serve
setup:ui:
desc: setup frontend dependencies
@@ -54,10 +54,10 @@ tasks:
desc: setup python dependencies
run: once
cmds:
- poetry install --with main,dev,postgres
- poetry run pre-commit install
- uv sync --extra pgsql --group dev
- uv run pre-commit install
sources:
- poetry.lock
- uv.lock
- pyproject.toml
- .pre-commit-config.yaml
@@ -70,7 +70,7 @@ tasks:
dev:generate:
desc: run code generators
cmds:
- poetry run python dev/code-generation/main.py {{ .CLI_ARGS }}
- uv run python dev/code-generation/main.py {{ .CLI_ARGS }}
- task: docs:gen
- task: py:format
@@ -96,22 +96,22 @@ tasks:
py:mypy:
desc: runs python type checking
cmds:
- poetry run mypy mealie
- uv run mypy mealie
py:test:
desc: runs python tests (support args after '--')
cmds:
- poetry run pytest {{ .CLI_ARGS }}
- uv run pytest {{ .CLI_ARGS }}
py:format:
desc: runs python code formatter
cmds:
- poetry run ruff format .
- uv run ruff format .
py:lint:
desc: runs python linter
cmds:
- poetry run ruff check mealie
- uv run ruff check mealie
py:check:
desc: runs all linters, type checkers, and formatters
@@ -124,10 +124,10 @@ tasks:
py:coverage:
desc: runs python coverage and generates html report
cmds:
- poetry run pytest
- poetry run coverage report -m
- poetry run coveragepy-lcov
- poetry run coverage html
- uv run pytest
- uv run coverage report -m
- uv run coveragepy-lcov
- uv run coverage html
- open htmlcov/index.html
py:package:copy-frontend:
@@ -147,17 +147,17 @@ tasks:
desc: Generate requirements file to pin all packages, effectively a "pip freeze" before installation begins
internal: true
cmds:
- poetry export -n --only=main --extras=pgsql --output=dist/requirements.txt
- uv export --no-editable --no-emit-project --extra pgsql --format requirements-txt --output-file dist/requirements.txt
# Include mealie in the requirements, hashing the package that was just built to ensure it's the one installed
- echo "mealie[pgsql]=={{.MEALIE_VERSION}} \\" >> dist/requirements.txt
- poetry run pip hash dist/mealie-{{.MEALIE_VERSION}}-py3-none-any.whl | tail -n1 | tr -d '\n' >> dist/requirements.txt
- pip hash dist/mealie-{{.MEALIE_VERSION}}-py3-none-any.whl | tail -n1 | tr -d '\n' >> dist/requirements.txt
- echo " \\" >> dist/requirements.txt
- poetry run pip hash dist/mealie-{{.MEALIE_VERSION}}.tar.gz | tail -n1 >> dist/requirements.txt
- pip hash dist/mealie-{{.MEALIE_VERSION}}.tar.gz | tail -n1 >> dist/requirements.txt
vars:
MEALIE_VERSION:
sh: poetry version --short
sh: python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])"
sources:
- poetry.lock
- uv.lock
- pyproject.toml
- dist/mealie-*.whl
- dist/mealie-*.tar.gz
@@ -184,13 +184,13 @@ tasks:
deps:
- py:package:deps
cmds:
- poetry build -n --output=dist
- uv build --out-dir dist
- task: py:package:generate-requirements
py:
desc: runs the backend server
cmds:
- poetry run python mealie/app.py
- uv run python mealie/app.py
py:postgres:
desc: runs the backend server configured for containerized postgres
@@ -202,12 +202,12 @@ tasks:
POSTGRES_PORT: 5432
POSTGRES_DB: mealie
cmds:
- poetry run python mealie/app.py
- uv run python mealie/app.py
py:migrate:
desc: generates a new database migration file e.g. task py:migrate -- "add new column"
cmds:
- poetry run alembic --config mealie/alembic/alembic.ini revision --autogenerate -m "{{ .CLI_ARGS }}"
- uv run alembic --config mealie/alembic/alembic.ini revision --autogenerate -m "{{ .CLI_ARGS }}"
- task: py:format
ui:build:

View File

@@ -113,8 +113,8 @@ def main():
{"children": all_children},
)
subprocess.run(["poetry", "run", "ruff", "check", str(out_path), "--fix"])
subprocess.run(["poetry", "run", "ruff", "format", str(out_path)])
subprocess.run(["uv", "run", "ruff", "check", str(out_path), "--fix"])
subprocess.run(["uv", "run", "ruff", "format", str(out_path)])
if __name__ == "__main__":

View File

@@ -100,8 +100,8 @@ def main() -> None:
render_python_template(template, template_path, {"module": module})
path_args = (str(p) for p in template_paths)
subprocess.run(["poetry", "run", "ruff", "check", *path_args, "--fix"])
subprocess.run(["poetry", "run", "ruff", "format", *path_args])
subprocess.run(["uv", "run", "ruff", "check", *path_args, "--fix"])
subprocess.run(["uv", "run", "ruff", "format", *path_args])
if __name__ == "__main__":

View File

@@ -50,40 +50,29 @@ RUN apt-get update \
curl \
&& rm -rf /var/lib/apt/lists/*
ENV POETRY_HOME="/opt/poetry" \
POETRY_NO_INTERACTION=1
# prepend poetry to path
ENV PATH="$POETRY_HOME/bin:$PATH"
# install poetry - respects $POETRY_VERSION & $POETRY_HOME
ENV POETRY_VERSION=2.0.1
RUN curl -sSL https://install.python-poetry.org | python3 -
# install poetry plugins needed to build the package
RUN poetry self add "poetry-plugin-export>=1.9"
RUN pip install uv
WORKDIR /mealie
# copy project files here to ensure they will be cached.
COPY poetry.lock pyproject.toml ./
COPY uv.lock pyproject.toml ./
COPY mealie ./mealie
# Copy frontend to package it into the wheel
COPY --from=frontend-builder /frontend/dist ./mealie/frontend
# Build the source and binary package
RUN poetry build --output=dist
RUN uv build --out-dir dist
# Create the requirements file, which is used to install the built package and
# its pinned dependencies later. mealie is included to ensure the built one is
# what's installed.
RUN export MEALIE_VERSION=$(poetry version --short) \
&& poetry export --only=main --extras=pgsql --output=dist/requirements.txt \
&& echo "mealie[pgsql]==$MEALIE_VERSION \\" >> dist/requirements.txt \
&& poetry run pip hash dist/mealie-$MEALIE_VERSION-py3-none-any.whl | tail -n1 | tr -d '\n' >> dist/requirements.txt \
RUN uv export --no-editable --no-emit-project --extra pgsql --format requirements-txt --output-file dist/requirements.txt \
&& MEALIE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") \
&& echo "mealie[pgsql]==${MEALIE_VERSION} \\" >> dist/requirements.txt \
&& pip hash dist/mealie-${MEALIE_VERSION}-py3-none-any.whl | tail -n1 | tr -d '\n' >> dist/requirements.txt \
&& echo " \\" >> dist/requirements.txt \
&& poetry run pip hash dist/mealie-$MEALIE_VERSION.tar.gz | tail -n1 >> dist/requirements.txt
&& pip hash dist/mealie-${MEALIE_VERSION}.tar.gz | tail -n1 >> dist/requirements.txt
###############################################
# Package Container

View File

@@ -12,13 +12,13 @@ yarnpkg generate
popd
rm -r mealie/frontend
cp -a frontend/dist mealie/frontend
poetry build
poetry export -n --only=main --extras=pgsql --output=dist/requirements.txt
MEALIE_VERSION=$(poetry version --short)
uv build --out-dir dist
uv export --no-editable --no-emit-project --extra pgsql --format requirements-txt --output-file dist/requirements.txt
MEALIE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "mealie[pgsql]==${MEALIE_VERSION} \\" >> dist/requirements.txt
poetry run pip hash dist/mealie-${MEALIE_VERSION}-py3-none-any.whl | tail -n1 | tr -d '\n' >> dist/requirements.txt
pip hash dist/mealie-${MEALIE_VERSION}-py3-none-any.whl | tail -n1 | tr -d '\n' >> dist/requirements.txt
echo " \\" >> dist/requirements.txt
poetry run pip hash dist/mealie-${MEALIE_VERSION}.tar.gz | tail -n1 >> dist/requirements.txt
pip hash dist/mealie-${MEALIE_VERSION}.tar.gz | tail -n1 >> dist/requirements.txt
```
The Python package can be installed with all of its dependencies pinned to the versions tested by the developers with:

View File

@@ -33,7 +33,7 @@ Make sure the VSCode Dev Containers extension is installed, then select "Dev Con
### Prerequisites
- [Python 3.12](https://www.python.org/downloads/)
- [Poetry](https://python-poetry.org/docs/#installation)
- [uv](https://docs.astral.sh/uv/)
- [Node](https://nodejs.org/en/)
- [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable)
- [task](https://taskfile.dev/#/installation)

4032
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,94 +1,93 @@
[tool.poetry]
authors = ["Hayden <hay-kot@pm.me>"]
description = "A Recipe Manager"
license = "AGPL"
[project]
name = "mealie"
version = "3.4.0"
include = [
# Explicit include to override .gitignore when packaging the frontend
{ path = "mealie/frontend/**/*", format = ["sdist", "wheel"] }
description = "A Recipe Manager"
authors = [{ name = "Hayden", email = "hay-kot@pm.me" }]
license = "AGPL-3.0-only"
requires-python = ">=3.12,<3.13"
dependencies = [
"Jinja2>=3.1.2,<4.0.0",
"Pillow>=12.0.0,<13.0.0",
"PyYAML>=6.0.1,<7.0.0",
"SQLAlchemy>=2.0.0,<3.0.0",
"aiofiles>=25.0.0,<26.0.0",
"alembic>=1.11.3,<2.0.0",
"aniso8601==10.0.1",
"appdirs==1.4.4",
"apprise>=1.4.5,<2.0.0",
"bcrypt>=5.0.0,<6.0.0",
"extruct>=0.18.0,<1.0.0",
"fastapi>=0.120.0,<1.0.0",
"httpx>=0.28.0,<1.0.0",
"lxml>=6.0.0,<7.0.0",
"orjson>=3.8.0,<4.0.0",
"pydantic>=2.6.1,<3.0.0",
"pyhumps>=3.5.3,<4.0.0",
"python-dateutil>=2.8.2,<3.0.0",
"python-dotenv>=1.0.0,<2.0.0",
"python-ldap>=3.3.1,<4.0.0",
"python-multipart>=0.0.20,<1.0.0",
"python-slugify>=8.0.0,<9.0.0",
"recipe-scrapers>=15.0.0,<16.0.0",
"requests>=2.31.0,<3.0.0",
"tzdata>=2024.1,<2025.0.0",
"uvicorn[standard]>=0.38.0,<1.0.0",
"beautifulsoup4>=4.11.2,<5.0.0",
"isodate>=0.7.0,<1.0.0",
"text-unidecode>=1.3,<2.0",
"rapidfuzz>=3.2.0,<4.0.0",
"authlib>=1.3.0,<2.0.0",
"html2text>=2025.0.0,<2026.0.0",
"paho-mqtt>=1.6.1,<2.0.0",
"pydantic-settings>=2.1.0,<3.0.0",
"pillow-heif>=1.0.0,<2.0.0",
"pyjwt>=2.8.0,<3.0.0",
"openai>=2.0.0,<3.0.0",
"typing-extensions>=4.12.2,<5.0.0",
"itsdangerous>=2.2.0,<3.0.0",
"ingredient-parser-nlp>=2.0.0,<3.0.0",
]
[tool.poetry.scripts]
[project.scripts]
mealie = "mealie.main:main"
[tool.poetry.dependencies]
Jinja2 = "^3.1.2"
Pillow = "^12.0.0"
PyYAML = "^6.0.1"
SQLAlchemy = "^2"
aiofiles = "^25.0.0"
alembic = "^1.11.3"
aniso8601 = "10.0.1"
appdirs = "1.4.4"
apprise = "^1.4.5"
bcrypt = "^5.0.0"
extruct = "^0.18.0"
fastapi = "^0.120.0"
httpx = "^0.28.0"
lxml = "^6.0.0"
orjson = "^3.8.0"
psycopg2-binary = { version = "^2.9.1", optional = true }
pydantic = "^2.6.1"
pyhumps = "^3.5.3"
python = ">=3.12,<3.13"
python-dateutil = "^2.8.2"
python-dotenv = "^1.0.0"
python-ldap = "^3.3.1"
python-multipart = "^0.0.20"
python-slugify = "^8.0.0"
recipe-scrapers = "^15.0.0"
requests = "^2.31.0"
tzdata = "^2024.1"
uvicorn = { extras = ["standard"], version = "^0.38.0" }
beautifulsoup4 = "^4.11.2"
isodate = "^0.7.0"
text-unidecode = "^1.3"
rapidfuzz = "^3.2.0"
authlib = "^1.3.0"
html2text = "^2025.0.0"
paho-mqtt = "^1.6.1"
pydantic-settings = "^2.1.0"
pillow-heif = "^1.0.0"
pyjwt = "^2.8.0"
openai = "^2.0.0"
typing-extensions = "^4.12.2"
itsdangerous = "^2.2.0"
ingredient-parser-nlp = "^2.0.0"
[tool.poetry.group.postgres.dependencies]
psycopg2-binary = { version = "^2.9.1" }
[tool.poetry.group.dev.dependencies]
coverage = "^7.0"
coveragepy-lcov = "^0.1.1"
mkdocs-material = "^9.0.0"
mypy = "^1.5.1"
pre-commit = "^4.0.0"
pylint = "^4.0.0"
pytest = "^8.0.0"
pytest-asyncio = "^1.0.0"
rich = "^14.0.0"
ruff = "^0.14.0"
types-PyYAML = "^6.0.4"
types-python-dateutil = "^2.8.18"
types-python-slugify = "^6.0.0"
types-requests = "^2.27.12"
types-urllib3 = "^1.26.11"
pydantic-to-typescript2 = "^1.0.4"
[project.optional-dependencies]
pgsql = [
"psycopg2-binary>=2.9.1,<3.0.0"
]
[dependency-groups]
dev = [
"coverage>=7.0,<8.0",
"coveragepy-lcov>=0.1.1,<1.0.0",
"mkdocs-material>=9.0.0,<10.0.0",
"mypy>=1.5.1,<2.0.0",
"pre-commit>=4.0.0,<5.0.0",
"pylint>=4.0.0,<5.0.0",
"pytest>=8.0.0,<9.0.0",
"pytest-asyncio>=1.0.0,<2.0.0",
"rich>=14.0.0,<15.0.0",
"ruff>=0.14.0,<1.0.0",
"types-PyYAML>=6.0.4,<7.0.0",
"types-python-dateutil>=2.8.18,<3.0.0",
"types-python-slugify>=6.0.0,<7.0.0",
"types-requests>=2.27.12,<3.0.0",
"types-urllib3>=1.26.11,<2.0.0",
"pydantic-to-typescript2>=1.0.4,<2.0.0",
]
[build-system]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0"]
requires = ["setuptools>=77.0.0"]
build-backend = "setuptools.build_meta"
[tool.vulture]
exclude = ["**/models/**/*.py", "dir/"]
ignore_decorators = ["@*router.*", "@app.on_event", "@field_validator", "@controller"]
make_whitelist = true
min_confidence = 60
paths = ["mealie"]
sort_by_size = true
[tool.setuptools]
include-package-data = true
[tool.setuptools.packages.find]
include = ["mealie*"]
[tool.setuptools.package-data]
"*" = ["*"]
[tool.pytest.ini_options]
addopts = "-ra -q"
@@ -102,9 +101,6 @@ testpaths = ["tests"]
[tool.coverage.report]
skip_empty = true
[tool.poetry.extras]
pgsql = ["psycopg2-binary"]
[tool.mypy]
follow_imports = "skip"
ignore_missing_imports = true
@@ -113,6 +109,7 @@ python_version = "3.12"
strict_optional = true
[tool.ruff]
target-version = "py312"
line-length = 120
output-format = "concise"
@@ -139,9 +136,6 @@ exclude = [
"venv",
]
# Assume Python 3.12.
target-version = "py312"
[tool.ruff.lint.isort]
known-third-party = ["alembic"]

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"enabledManagers": [
"poetry",
"pep621",
"dockerfile",
"npm"
],

2040
uv.lock generated Normal file

File diff suppressed because it is too large Load Diff