Skip to content

Commit

Permalink
feat(uv) switched from poetry to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
Vineeth Voruganti committed Sep 14, 2024
1 parent cac0733 commit 22f68fb
Show file tree
Hide file tree
Showing 7 changed files with 1,934 additions and 2,534 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ docker-compose.yml.example
.github/**
.vscode/**
data/**

.venv
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ api/docker-compose.yml
*.db
data
docker-compose.yml
compose.yml


# Byte-compiled / optimized / DLL files
Expand Down
44 changes: 23 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,41 @@
# https://testdriven.io/blog/docker-best-practices/
FROM python:3.11-slim-bullseye

RUN apt-get update && apt-get install -y build-essential
COPY --from=ghcr.io/astral-sh/uv:0.4.9 /uv /bin/uv

# Set Working directory
WORKDIR /app

# https://stackoverflow.com/questions/53835198/integrating-python-poetry-with-docker
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.8.3
RUN addgroup --system app && adduser --system --group app
RUN chown -R app:app /app
USER app

RUN pip install "poetry==$POETRY_VERSION"
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

# Copy only requirements to cache them in docker layer
WORKDIR /app
COPY poetry.lock pyproject.toml /app/
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

# Project initialization:
RUN poetry config virtualenvs.create false \
&& poetry install --no-root --no-interaction --no-ansi
# Install the project's dependencies using the lockfile and settings
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 --no-dev

WORKDIR /app
# Copy only requirements to cache them in docker layer
COPY uv.lock pyproject.toml /app/

RUN addgroup --system app && adduser --system --group app
RUN chown -R app:app /app
USER app
# Sync the project
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev

# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"

COPY --chown=app:app src/ /app/src/

EXPOSE 8000

# https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker
CMD ["fastapi", "run", "src/main.py"]
CMD ["fastapi", "dev", "--host", "0.0.0.0", "src/main.py"]

3 changes: 1 addition & 2 deletions docker-compose.yml.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.8"
services:
api:
image: honcho:latest
Expand All @@ -18,7 +17,7 @@ services:
build:
context: .
dockerfile: Dockerfile
entrypoint: ["python", "-m", "src.deriver"]
entrypoint: ["uv", "run", "python", "-m", "src.deriver"]
depends_on:
database:
condition: service_healthy
Expand Down
2,475 changes: 0 additions & 2,475 deletions poetry.lock

This file was deleted.

67 changes: 32 additions & 35 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
[tool.poetry]
[project]
name = "honcho"
version = "0.0.11"
description = "Honcho Server"
authors = ["Plastic Labs <[email protected]>"]
authors = [
{name = "Plastic Labs", email = "[email protected]"},
]
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.9"
fastapi = "^0.111.0"
python-dotenv = "^1.0.0"
sqlalchemy = "^2.0.30"
fastapi-pagination = "^0.12.24"
pgvector = "^0.2.5"
sentry-sdk = {extras = ["fastapi", "sqlalchemy"], version = "^2.3.1"}
greenlet = "^3.0.3"
psycopg = {extras= ["binary"], version="^3.1.19"}
httpx = "^0.27.0"
opentelemetry-instrumentation-fastapi = "^0.45b0"
opentelemetry-sdk = "^1.24.0"
opentelemetry-exporter-otlp = "^1.24.0"
opentelemetry-instrumentation-sqlalchemy = "^0.45b0"
opentelemetry-instrumentation-logging = "^0.45b0"
rich = "^13.7.1"
mirascope = "^0.18.0"
openai = "^1.43.0"

[tool.poetry.group.test.dependencies]
pytest = "^8.2.2"
sqlalchemy-utils = "^0.41.2"
pytest-asyncio = "^0.23.7"
coverage = "^7.6.0"
interrogate = "^1.7.0"
requires-python = ">=3.9"
dependencies = [
"fastapi[standard]>=0.111.0",
"python-dotenv>=1.0.0",
"sqlalchemy>=2.0.30",
"fastapi-pagination>=0.12.24",
"pgvector>=0.2.5",
"sentry-sdk[fastapi,sqlalchemy]>=2.3.1",
"greenlet>=3.0.3",
"psycopg[binary]>=3.1.19",
"httpx>=0.27.0",
"opentelemetry-instrumentation-fastapi>=0.45b0",
"opentelemetry-sdk>=1.24.0",
"opentelemetry-exporter-otlp>=1.24.0",
"opentelemetry-instrumentation-sqlalchemy>=0.45b0",
"opentelemetry-instrumentation-logging>=0.45b0",
"rich>=13.7.1",
"mirascope>=0.18.0",
"openai>=1.43.0",
]
[project.optional-dependencies]
test = [
"pytest>=8.2.2",
"sqlalchemy-utils>=0.41.2",
"pytest-asyncio>=0.23.7",
"coverage>=7.6.0",
"interrogate>=1.7.0",
]

[tool.ruff.lint]
# from https://docs.astral.sh/ruff/linter/#rule-selection example
Expand All @@ -54,10 +56,5 @@ ignore = ["E501"]
[tool.ruff.flake8-bugbear]
extend-immutable-calls = ["fastapi.Depends"]


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.lpytest.ini_options]
asyncio_mode = "auto"
Loading

0 comments on commit 22f68fb

Please sign in to comment.