Skip to content

Commit

Permalink
Merge pull request #227 from luigi311/uv
Browse files Browse the repository at this point in the history
Swap to UV
  • Loading branch information
luigi311 authored Feb 20, 2025
2 parents 196a49f + ba6cad1 commit 031d43e
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 37 deletions.
5 changes: 1 addition & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.venv
.dockerignore
.env
.env.sample
Expand All @@ -9,7 +10,3 @@

Dockerfile*
README.md

test

venv
48 changes: 28 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,36 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v5

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version-file: ".python-version"

- name: "Install dependencies"
run: pip install -r requirements.txt && pip install -r test/requirements.txt
run: uv sync --all-extras --dev

- name: "Run tests"
run: pytest -vvv
run: uv run pytest -vvv

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v5

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version-file: ".python-version"

- name: "Install dependencies"
run: |
pip install -r requirements.txt
uv sync --all-extras --dev
sudo apt update && sudo apt install -y docker-compose
- name: "Checkout JellyPlex-Watched-CI"
Expand All @@ -63,53 +71,53 @@ jobs:
- name: "Test Plex"
run: |
mv test/ci_plex.env .env
python main.py
python test/validate_ci_marklog.py --plex
uv run main.py
uv run test/validate_ci_marklog.py --plex
rm mark.log
- name: "Test Jellyfin"
run: |
mv test/ci_jellyfin.env .env
python main.py
python test/validate_ci_marklog.py --jellyfin
uv run main.py
uv run test/validate_ci_marklog.py --jellyfin
rm mark.log
- name: "Test Emby"
run: |
mv test/ci_emby.env .env
python main.py
python test/validate_ci_marklog.py --emby
uv run main.py
uv run test/validate_ci_marklog.py --emby
rm mark.log
- name: "Test Guids"
run: |
mv test/ci_guids.env .env
python main.py
python test/validate_ci_marklog.py --guids
uv run main.py
uv run test/validate_ci_marklog.py --guids
rm mark.log
- name: "Test Locations"
run: |
mv test/ci_locations.env .env
python main.py
python test/validate_ci_marklog.py --locations
uv run main.py
uv run test/validate_ci_marklog.py --locations
rm mark.log
- name: "Test writing to the servers"
run: |
# Test writing to the servers
mv test/ci_write.env .env
python main.py
uv run main.py
# Test again to test if it can handle existing data
python main.py
uv run main.py
python test/validate_ci_marklog.py --write
uv run test/validate_ci_marklog.py --write
rm mark.log
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ target/
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
25 changes: 22 additions & 3 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.13-alpine
FROM ghcr.io/astral-sh/uv:python3.13-alpine

ENV PUID=1000
ENV PGID=1000
Expand Down Expand Up @@ -36,9 +36,28 @@ RUN set -eux; \

WORKDIR /app

COPY ./requirements.txt ./
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

RUN pip install --no-cache-dir -r requirements.txt
ENV UV_LINK_MODE=copy

# Set the cache directory to /tmp instead of root
ENV UV_CACHE_DIR=/tmp/.cache/uv

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/tmp/.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

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
COPY . /app
RUN --mount=type=cache,target=/tmp/.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 . .

Expand Down
27 changes: 23 additions & 4 deletions Dockerfile.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.13-slim
FROM ghcr.io/astral-sh/uv:bookworm-slim

ENV PUID=1000
ENV PGID=1000
Expand All @@ -10,11 +10,30 @@ RUN apt-get update && \

WORKDIR /app

COPY ./requirements.txt ./
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

RUN pip install --no-cache-dir -r requirements.txt
ENV UV_LINK_MODE=copy

COPY . .
# Set the cache directory to /tmp instead of root
ENV UV_CACHE_DIR=/tmp/.cache/uv

ENV UV_PYTHON_INSTALL_DIR=/app/.bin

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/tmp/.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

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
COPY . /app
RUN --mount=type=cache,target=/tmp/.cache/uv \
uv sync --frozen --no-dev

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

RUN chmod +x *.sh && \
dos2unix *.sh
Expand Down
7 changes: 4 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ echo "Starting JellyPlex-Watched with UID: $PUID and GID: $PGID"

# If root run as the created user
if [ "$(id -u)" = '0' ]; then
chown -R "$PUID:$PGID" /app/.venv
chown -R "$PUID:$PGID" "$LOG_DIR"
chown -R "$PUID:$PGID" "$MARK_DIR"

# Run the application as the created user
exec gosu "$PUID:$PGID" "$@"
else
# Run the application as the current user
exec "$@"
fi

# Run the application as the current user
exec "$@"
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[project]
name = "jellyplex-watched"
version = "6.1.2"
description = "Sync watched between media servers locally"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"packaging==24.2",
"plexapi==4.16.1",
"pydantic==2.10.6",
"python-dotenv==1.0.0",
"requests==2.32.3",
]

[dependency-groups]
lint = [
"ruff>=0.9.6",
]
dev = [
"pytest>=8.3.4",
]
Binary file removed requirements.txt
Binary file not shown.
Loading

0 comments on commit 031d43e

Please sign in to comment.