Skip to content

Commit

Permalink
migrate from poetry to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
daya0576 committed Dec 14, 2024
1 parent 2ad9ee6 commit dc4dcb6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 63 deletions.
43 changes: 11 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,32 @@
FROM python:3.12-slim AS python-base

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
\
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
\
POETRY_VERSION=1.8.4 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
ENV UV_COMPILE_BYTECODE=1 \
\
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"
ENV PATH="$VENV_PATH/bin:$PATH"

# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"


################################
# BUILDER-BASE
# Used to build deps + create our virtual environment
################################
FROM python-base AS builder-base
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
build-essential \
curl

# install poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN curl -sSL https://install.python-poetry.org | python3 -
# copy project requirement files here to ensure they will be cached.
curl \
ca-certificates
WORKDIR $PYSETUP_PATH
COPY poetry.lock pyproject.toml ./
# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
RUN poetry install --only main
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
ENV PATH="/root/.local/bin/:$PATH"

COPY uv.lock pyproject.toml ./
RUN uv sync --frozen --no-install-project --no-dev

# [Experimental] Remove unused nicegui libs
ENV NICEGUI_LIB_PATH="/opt/pysetup/.venv/lib/python3.12/site-packages/nicegui/elements/lib"
ENV NICEGUI_LIB_PATH="$VENV_PATH/lib/python3.12/site-packages/nicegui/elements/lib"
RUN rm -rf "$NICEGUI_LIB_PATH/mermaid/"
RUN rm -rf "$NICEGUI_LIB_PATH/plotly/"
RUN rm -rf "$NICEGUI_LIB_PATH/vanilla-jsoneditor/"


################################
# PRODUCTION
# Final image used for runtime
################################
FROM python-base AS production
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH

Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ To avoid [permission issues](https://github.com/daya0576/beaverhabits/discussion
| **ENABLE_IOS_STANDALONE**(bool) | Experiential feature to enable standalone mode on iOS. The default setting is `false` |
| **INDEX_SHOW_HABIT_COUNT**(bool) | To display the total completed count badge on the main page. The default setting is `false` |

## Development

BeaverHabits favors poetry as package management tool. Here is how to set up the development environment:

```sh
# First, install poetry (you can do it in a python's virtualenv)
pip install poetry

# Then run (which is similar to pip install -e .)
poetry install

# Finally, start the server
./start.sh dev
```


# Features

1. Pages
Expand Down
2 changes: 1 addition & 1 deletion beaverhabits/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def init_auth_routes(app: FastAPI) -> None:
app.include_router(
fastapi_users.get_auth_router(auth_backend), prefix="/auth/jwt", tags=["auth"]
fastapi_users.get_auth_router(auth_backend), prefix="/auth", tags=["auth"]
)
app.include_router(
fastapi_users.get_register_router(UserRead, UserCreate),
Expand Down
60 changes: 31 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
[tool.poetry]
[project]
authors = [
{name = "Henry Zhu", email = "[email protected]"},
]
requires-python = "<4.0,>=3.12"
dependencies = [
"nicegui<3.0.0,>=2.7.0",
"pydantic-settings<3.0.0,>=2.2.1",
"fastapi-users[sqlalchemy]<15.0.0,>=14.0.0",
"uvicorn[standard]<1.0.0,>=0.28.0",
"sqlalchemy[asyncio]<3.0.0,>=2.0.29",
"asyncpg<1.0.0,>=0.29.0",
"aiosqlite<1.0.0,>=0.20.0",
"pytz<2025.0,>=2024.1",
"sentry-sdk[fastapi]<3.0.0,>=2.15.0",
"python-dateutil<3.0.0.0,>=2.9.0.post0",
]
name = "beaverhabits"
version = "0.1.0"
description = ""
authors = ["Henry Zhu <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
nicegui = "^2.7.0"
pydantic-settings = "^2.2.1"
fastapi-users = {extras = ["sqlalchemy"], version = "^14.0.0"}
uvicorn = {extras = ["standard"], version = "^0.28.0"}
sqlalchemy = {extras = ["asyncio"], version = "^2.0.29"}
asyncpg = "^0.29.0"
aiosqlite = "^0.20.0"
pytz = "^2024.1"
sentry-sdk = {extras = ["fastapi"], version = "^2.15.0"}
python-dateutil = "^2.9.0.post0"
[dependency-groups]
dev = [
"icecream<3.0.0,>=2.1.3",
"autopep8<3.0.0,>=2.0.4",
"pytest-selenium<5.0.0,>=4.1.0",
"pytest-asyncio<1.0.0.0,>=0.23.5.post1",
"webdriver-manager<5.0.0,>=4.0.1",
"selenium<5.0.0,>=4.18.1",
"beautifulsoup4<5.0.0,>=4.12.3",
"pytest<9.0.0,>=8.1.1",
"pip>=24.3.1",
]

[tool.poetry.group.dev.dependencies]
icecream = "^2.1.3"
autopep8 = "^2.0.4"
pytest-selenium = "^4.1.0"
pytest-asyncio = "^0.23.5.post1"
webdriver-manager = "^4.0.1"
selenium = "^4.18.1"
beautifulsoup4 = "^4.12.3"
pytest = "^8.1.1"

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

[tool.poetry.scripts]
[project.scripts]
main = "beaverhabits.routes:main"

1 change: 0 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ if [ "$1" = "prd" ]; then
# Set nicegui storage path to avoid permission issues
if [ -z "$NICEGUI_STORAGE_PATH" ]; then
export NICEGUI_STORAGE_PATH=".user/.nicegui"
echo "NICEGUI_STORAGE_PATH not set. Using default value: .user/.nicegui"
fi
# we also use a single worker in production mode so socket.io connections are always handled by the same worker
uvicorn beaverhabits.main:app --workers 1 --log-level info --port 8080 --host 0.0.0.0
Expand Down

0 comments on commit dc4dcb6

Please sign in to comment.