Skip to content

chore: migrate from requirements.txt to uv with pyproject.toml#1688

Open
laurigates wants to merge 1 commit intohacksider:mainfrom
laurigates:pr/uv-migration
Open

chore: migrate from requirements.txt to uv with pyproject.toml#1688
laurigates wants to merge 1 commit intohacksider:mainfrom
laurigates:pr/uv-migration

Conversation

@laurigates
Copy link
Copy Markdown
Contributor

@laurigates laurigates commented Feb 24, 2026

Summary

Migrate the project's dependency management from bare requirements.txt to uv with a modern pyproject.toml.

  • pyproject.toml — all dependencies from requirements.txt in PEP 517 format with proper platform markers, build system (hatchling), and dev extras (pytest)
  • mise.toml + .python-version — reproducible Python version management via mise
  • justfile — convenient task runner wrapping common commands (just setup, just start, just start-cpu, just test)
  • .gitignore — exclude .venv/, uv.lock, .mise.local.toml

requirements.txt is preserved untouched for users who prefer pip.

Why uv?

  • Dramatically faster installs (Rust-based resolver)
  • Reliable cross-platform lockfile (uv.lock)
  • Native support for platform-conditional extras (e.g. onnxruntime-silicon on Apple Silicon vs onnxruntime-gpu elsewhere)
  • Drop-in replacement: uv pip install -r requirements.txt still works

Quick Start (after this PR)

# Install uv: https://docs.astral.sh/uv/getting-started/installation/
uv sync          # create .venv and install all deps
just start       # run with platform-default GPU (coreml / cuda)
just start-cpu   # run CPU-only

Test plan

  • uv sync completes without errors on macOS ARM (onnxruntime-silicon)
  • uv sync completes without errors on Linux/Windows (onnxruntime-gpu)
  • just start-cpu launches the GUI
  • pip install -r requirements.txt still works (backward compat)

🤖 Generated with Claude Code

Summary by Sourcery

Adopt uv-based dependency and environment management with a modern pyproject.toml and supporting tooling for running, testing, and maintaining the project.

Build:

  • Define project metadata, core dependencies, and dev dependencies in pyproject.toml with a hatchling-based build system and uv-friendly configuration.
  • Introduce mise configuration and a .python-version file to pin Python 3.10 and manage a local virtual environment.
  • Update ignore rules (e.g., virtualenv and lockfile artifacts) to align with the new uv-based workflow.

Chores:

  • Add a justfile with recipes for environment setup, model downloading, running the application with different execution providers, running tests, and cleaning uv artifacts.

Add pyproject.toml with properly typed dependencies, platform-specific
ONNX Runtime variants, and optional dev dependencies. Add mise.toml for
Python version management and justfile for common development tasks.

The requirements.txt remains for backward compatibility with pip users.
uv is the recommended workflow going forward:

    uv sync          # install dependencies
    just start       # run with platform GPU
    just start-cpu   # run CPU-only

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Feb 24, 2026

Reviewer's Guide

Migrates the project from requirements.txt-based dependency management to a uv + pyproject.toml setup, adds mise-based Python version management and a justfile task runner, and updates gitignore for new artifacts while keeping requirements.txt for backward compatibility.

Sequence diagram for running the application with just and uv

sequenceDiagram
    actor Developer
    participant Shell
    participant Just
    participant Uv as uv
    participant Venv as venv_.venv
    participant RunPy as run.py

    Developer->>Shell: just start
    Shell->>Just: invoke_recipe_start
    Just->>Uv: uv run run.py --execution-provider default_provider
    Uv->>Venv: create_or_use_venv
    Uv->>RunPy: execute_within_venv
    RunPy-->>Developer: GUI_running_with_GPU_or_coreml

    Developer->>Shell: just start-cpu
    Shell->>Just: invoke_recipe_start_cpu
    Just->>Uv: uv run run.py
    Uv->>Venv: create_or_use_venv
    Uv->>RunPy: execute_within_venv
    RunPy-->>Developer: GUI_running_CPU_only
Loading

Flow diagram for justfile tasks and dependencies

flowchart TD
    subgraph Setup_group
        Setup[setup]
        Install[install]
        Models[models]
    end

    subgraph Run_group
        Start[start]
        StartCpu[start_cpu]
        StartWith[start_with_provider]
    end

    subgraph Test_group
        Test[test]
    end

    subgraph Maintenance_group
        Clean[clean]
    end

    Setup --> Install
    Setup --> Models

    Install --> UVSync[uv_sync]
    UVSync --> Venv[.venv_created_and_synced]

    Models --> ModelsDirCreated[create_models_directory]
    ModelsDirCreated --> DownloadModel1[download_inswapper_128_fp16.onnx_if_missing]
    ModelsDirCreated --> DownloadModel2[download_gfpgan_1024.onnx_if_missing]

    Start --> RunGPU[uv_run_run.py_with_default_execution_provider]
    StartCpu --> RunCPU[uv_run_run.py_CPU_only]
    StartWith --> RunCustom[uv_run_run.py_with_custom_provider]

    Test --> Pytest[uv_run_pytest_tests]

    Clean --> RemoveVenv[remove_.venv]
    Clean --> RemoveLock[remove_uv.lock]
Loading

File-Level Changes

Change Details Files
Introduce pyproject.toml with uv-compatible project metadata and dependency declarations, including platform-specific runtime dependencies and dev extras.
  • Define project metadata (name, version, description, readme, Python requirement) under [project].
  • Move runtime dependencies from requirements.txt into the dependencies array, adding appropriate environment markers for platform-specific packages like onnxruntime-silicon and onnxruntime-gpu.
  • Configure hatchling as the build backend and enable direct references via hatch metadata.
  • Configure wheel build target to package the modules directory.
  • Add a dev dependency group for pytest under [dependency-groups].
pyproject.toml
Add a justfile as a task runner to standardize common workflows (setup, running the app, testing, cleaning).
  • Define global settings and variables including models directory and default execution provider based on OS.
  • Export TCL_LIBRARY and TK_LIBRARY environment variables using Python-based discovery for Tk support.
  • Add grouped recipes for setup (install via uv sync and model downloads), running the app with different execution providers, running tests via uv run pytest, and cleaning the virtual environment and lockfile.
justfile
Add mise configuration for reproducible Python version and virtualenv management, along with a compatible .python-version file.
  • Pin Python tool version to 3.10 via mise configuration and configure mise to create/use a .venv directory for the virtual environment.
  • Add a .python-version file to align with mise and/or other Python version managers.
mise.toml
.python-version
Update gitignore to exclude artifacts created by uv and mise-based workflows.
  • Ignore the .venv directory that uv and mise will use for the virtual environment.
  • Ignore uv.lock lockfile.
  • Ignore .mise.local.toml for local mise overrides.
.gitignore

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • In the pyproject dependencies, pillow==12.1.1 does not appear to be a currently released version on PyPI; consider aligning this pin with an existing version or whatever was previously used in requirements.txt to avoid resolution failures.
  • The onnxruntime-gpu==1.24.2; sys_platform != 'darwin' and unpinned tensorflow; sys_platform != 'darwin' markers will also apply to non-GPU environments (e.g., Linux/Windows without CUDA, or macOS Intel); if you expect CPU-only setups there, consider narrowing these markers or providing a CPU-only alternative.
  • In the models recipe of the justfile, you may want to make curl fail loudly and avoid writing partial files by adding -f (and perhaps --retry), so transient network issues don't silently leave corrupted model files in the models directory.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the pyproject dependencies, `pillow==12.1.1` does not appear to be a currently released version on PyPI; consider aligning this pin with an existing version or whatever was previously used in `requirements.txt` to avoid resolution failures.
- The `onnxruntime-gpu==1.24.2; sys_platform != 'darwin'` and unpinned `tensorflow; sys_platform != 'darwin'` markers will also apply to non-GPU environments (e.g., Linux/Windows without CUDA, or macOS Intel); if you expect CPU-only setups there, consider narrowing these markers or providing a CPU-only alternative.
- In the `models` recipe of the justfile, you may want to make `curl` fail loudly and avoid writing partial files by adding `-f` (and perhaps `--retry`), so transient network issues don't silently leave corrupted model files in the `models` directory.

## Individual Comments

### Comment 1
<location path="justfile" line_range="38" />
<code_context>
+    mkdir -p {{ models_dir }}
+    if [ ! -f "{{ models_dir }}/inswapper_128_fp16.onnx" ]; then
+        echo "Downloading inswapper_128_fp16.onnx..."
+        curl -L -o "{{ models_dir }}/inswapper_128_fp16.onnx" \
+            "https://huggingface.co/hacksider/deep-live-cam/resolve/main/inswapper_128_fp16.onnx"
+    else
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider using `curl -f` so HTTP errors cause the script to fail instead of creating a corrupt/empty model file.

Without `-f`, a 404 or other HTTP error still creates a zero-byte file and the script keeps running (even with `set -euo pipefail`). Using `curl -fL -o ...` makes curl fail on HTTP errors, preventing silently corrupted model files.

Suggested implementation:

```
        curl -fL -o "{{ models_dir }}/inswapper_128_fp16.onnx" \

```

```
        curl -fL -o "{{ models_dir }}/gfpgan-1024.onnx" \

```
</issue_to_address>

### Comment 2
<location path="pyproject.toml" line_range="17" />
<code_context>
+    "psutil==5.9.8",
+    "tk==0.1.0",
+    "customtkinter==5.2.2",
+    "pillow==12.1.1",
+    "opennsfw2==0.10.2",
+    "protobuf==4.25.1",
</code_context>
<issue_to_address>
**issue (bug_risk):** The pinned Pillow version looks unrealistically high and may not exist on PyPI, which will break installs.

Pinning to `pillow==12.1.1` will almost certainly fail with `No matching distribution found`. Please either pin to a verified existing release or use a compatible version range (for example, `>=x.y,<x+1.0`) to avoid breaking installs.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

mkdir -p {{ models_dir }}
if [ ! -f "{{ models_dir }}/inswapper_128_fp16.onnx" ]; then
echo "Downloading inswapper_128_fp16.onnx..."
curl -L -o "{{ models_dir }}/inswapper_128_fp16.onnx" \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Consider using curl -f so HTTP errors cause the script to fail instead of creating a corrupt/empty model file.

Without -f, a 404 or other HTTP error still creates a zero-byte file and the script keeps running (even with set -euo pipefail). Using curl -fL -o ... makes curl fail on HTTP errors, preventing silently corrupted model files.

Suggested implementation:

        curl -fL -o "{{ models_dir }}/inswapper_128_fp16.onnx" \

        curl -fL -o "{{ models_dir }}/gfpgan-1024.onnx" \

"psutil==5.9.8",
"tk==0.1.0",
"customtkinter==5.2.2",
"pillow==12.1.1",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The pinned Pillow version looks unrealistically high and may not exist on PyPI, which will break installs.

Pinning to pillow==12.1.1 will almost certainly fail with No matching distribution found. Please either pin to a verified existing release or use a compatible version range (for example, >=x.y,<x+1.0) to avoid breaking installs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant