Skip to content

build: switch to uv #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN npm run build

# build python app
FROM python:3.12-bookworm AS python-builder
COPY --from=ghcr.io/astral-sh/uv:0.6.2 /uv /uvx /bin/

WORKDIR /app

Expand All @@ -28,26 +29,26 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
libzbar0 \
python3-gdal

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache \
POETRY_REQUESTS_TIMEOUT=600
ENV UV_LINK_MODE=copy \
UV_HTTP_TIMEOUT=300s

COPY pyproject.toml poetry.lock ./

RUN --mount=type=cache,target=$POETRY_CACHE_DIR python3 -m pip install --break-system-packages poetry setuptools \
&& python3 -m poetry install --only main --no-root --no-directory
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project \
&& uv pip install \
gdal[numpy]=="$(gdal-config --version).*" \
psycopg2

COPY sketch_map_tool sketch_map_tool
COPY data data
COPY config config

RUN --mount=type=cache,target=$POETRY_CACHE_DIR python3 -m poetry install --only main --no-root --no-directory \
&& python3 -m poetry run python -m pip install \
gdal[numpy]=="$(gdal-config --version).*" \
psycopg2 \
&& python3 -m poetry run pybabel compile -d sketch_map_tool/translations
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-editable \
&& uv run pybabel compile -d sketch_map_tool/translations


# final image
Expand Down
121 changes: 60 additions & 61 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,78 +1,77 @@
[tool.poetry]
[project]
name = "sketch_map_tool"
version = "2024.11.12.1"
description = ""
description = " Create re-digitizable paper maps for offline data collection in the field."
readme = "README.md"
authors = ["HeiGIT <[email protected]>"]
license = "GNU Affero General Public License v3.0"
requires-python = ">=3.11,<3.13"
dependencies = [
"celery[sqlalchemy,redis]>=5.4.0",
"flask>=3.1.0",
"flask-babel>=4.0.0",
"flower>=2.0.1",
"geojson>=3.2.0",
"kaleido==0.2.1",
"matplotlib>=3.10.0",
"matplotlib-scalebar>=0.8.1",
"neptune>=1.13.0",
"numpy<=2",
"opencv-python-headless>=4.10.0.84",
"plotly>=5.24.1",
"pymupdf>=1.25.1",
"pyproj>=3.7.0",
"pyzbar>=0.1.9",
"qrcode>=8.0",
"redis>=5.2.1",
"reportlab>=4.2.5",
"requests>=2.32.3",
"sam-2",
"setuptools>=75.6.0",
"shapelysmooth>=0.2.0",
"svglib>=1.5.1",
"toml>=0.10.2",
"torch==2.5.1",
"torchvision==0.20.1",
"ultralytics>=8.3.55",
"ultralytics_MB",
"waitress>=3.0.2",
"wheel>=0.45.1",
"wtforms>=3.2.1",
]

[tool.poetry.dependencies]
python=">= 3.11, < 3.13"
Flask = "^3.1.0"
waitress = "^3.0"
requests = "^2.32"
WTForms = "^3.0.1"
matplotlib = "^3.5.3"
reportlab = "^3.6.11"
toml = "^0.10.2"
celery = {extras = ["SQLAlchemy", "redis"], version = "^5.4"}
opencv-python-headless = "<4.8.0.76" # https://github.com/ultralytics/ultralytics/issues/893
qrcode = "^7.3.1"
svglib = "^1.4.1"
PyMuPDF = {extras = ["Pillow"], version = "^1.21.0"}
kaleido = "0.2.1" # Not working with '^', cf. https://github.com/plotly/Kaleido/issues/125
geojson = "^2.5.0"
matplotlib-scalebar = "^0.8.1"
redis = "^4.5.4"
pyproj = "^3.6.1"
ultralytics = "8.1.14"
pyzbar = "^0.1.9"
shapelysmooth = "^0.2.0"
flask-babel = "^4.0.0"
tifffile = "^2024.7.21"
rasterio = "^1.3.10"
ultralytics_MB = { git = "https://github.com/itisacloud/ultralytics_multiband_support.git", rev = "caf0b57b265d3c6761272ecf18a44b1605e9b25f" }
[tool.uv.sources]
torch = [
{ version = "^2.4.0+cpu", source = "pytorch-cpu", platform = "linux" },
{ version = "^2.4.0", source = "pypi", platform = "darwin" }
{ index = "pytorch-cpu", marker = "platform_system == 'Windows' or platform_system == 'Linux'" },
]
torchvision = [
{ version = "^0.20.1+cpu", source = "pytorch-cpu", platform = "linux" },
{ version = "^0.20.1", source = "pypi", platform = "darwin"}
{ index = "pytorch-cpu", marker = "platform_system == 'Windows' or platform_system == 'Linux'" },
]
"sam-2" = { git = "https://github.com/facebookresearch/segment-anything-2.git" }
setuptools = "^72.2.0" # dependencies of gdal
wheel = "^0.43.0" # dependencies of gdal
flower = "^2.0.1"
numpy = "<2" # dependency of gdal and opencv

[tool.poetry.group.dev.dependencies]
# Versions are fixed to match versions used by pre-commit
pytest = "^8.3"
pytest-rerunfailures = "^14.0"
pre-commit = "^2.20.0"
types-toml = "^0.10.8"
types-redis = "^4.3.21.3"
vcrpy = "^6.0"
pytest-celery = "^1.0.1"
locust = "^2.14.2"
hypothesis = "^6.88.4"
ruff = "^0.8.4"
approvaltests = "^12.0.0"
matplotlib = "^3.8.4"
geopandas = "^1.0.1"
testcontainers = {extras = ["postgres", "redis"], version = "^4.9"}
opencv-python = "<4.8.0.76"
psycopg2-binary = "^2.9.9" # dev only. In prod psycopg2 (non-binary) depending on system libraries (libpg) is used.

ultralytics_MB = { git = "https://github.com/itisacloud/ultralytics_multiband_support.git", rev = "caf0b57b265d3c6761272ecf18a44b1605e9b25f" }
sam-2 = { git = "https://github.com/facebookresearch/segment-anything-2.git" }

[[tool.poetry.source]]
[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
priority = "explicit"
explicit = true

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[dependency-groups]
dev = [
"approvaltests>=14.3.0",
"geopandas>=1.0.1",
"hypothesis>=6.123.2",
"locust>=2.32.5",
"opencv-python>=4.10.0.84",
"pre-commit>=4.0.1",
"psycopg2-binary>=2.9.10",
"pytest>=8.3.4",
"pytest-celery>=1.1.3",
"pytest-rerunfailures>=15.0",
"ruff>=0.8.4",
"testcontainers>=4.9.0",
"vcrpy>=7.0.0",
]

[tool.ruff.lint]
select = [
Expand Down
Loading
Loading