Skip to content

Migrate dependency management from Poetry to uv#68

Merged
mihow merged 10 commits into
mainfrom
copilot/migrate-poetry-to-uv
Jun 4, 2026
Merged

Migrate dependency management from Poetry to uv#68
mihow merged 10 commits into
mainfrom
copilot/migrate-poetry-to-uv

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 20, 2026

Migrates project from Poetry to uv, adopting PEP 621 standard format for modern Python packaging.

Changes

pyproject.toml

  • Build system: poetry-corehatchling
  • Project metadata: [tool.poetry][project] (PEP 621)
  • Dependencies: Poetry caret syntax (^1.0) → minimum version constraints (>=1.0)
  • Optional dependencies: Poetry groups → [project.optional-dependencies]
  • Python requirement: Updated to >=3.10
  • Preserved: CLI scripts, flake8 configuration

README.md

  • Installation: poetry installuv sync
  • Virtual environment: poetry shellsource .venv/bin/activate
  • Script execution: poetry runuv run
  • Added platform-specific uv installation instructions

GitHub Actions CI Workflow

  • Added .github/workflows/ci.yml for continuous integration
  • Python 3.12 testing
  • Automated package installation with uv sync --extra dev --extra research
  • CLI command testing (ami-dataset, ami-classification)
  • Placeholder for test suite execution with uv run pytest
  • Core and optional dependencies (dev, research) import verification

Migration Example

Before:

poetry install
poetry run pre-commit install
poetry run python script.py

After:

uv sync
uv run pre-commit install
uv run python script.py
Original prompt

Objective

Migrate the project from Poetry to uv for dependency management, following modern Python packaging standards and best practices.

Background

uv is a modern, extremely fast Python package manager from Astral (creators of Ruff). It offers:

  • 10-100x faster installation than pip/Poetry
  • Full PEP 621/735 standard compliance
  • Built-in lockfile support
  • Native virtual environment management
  • Better dependency resolution
  • Active development and strong community support

Tasks

1. Convert pyproject.toml to PEP 621 Format

Current file location: pyproject.toml

Convert from Poetry-specific format to modern PEP 621 standard:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ami-ml"
version = "0.1.0"
description = "Software & research related to the automated monitoring of insects"
readme = "README.md"
license = {text = "MIT"}
requires-python = ">=3.9"
authors = [
    {name = "Aditya Jain", email = "aditya.jain@mila.quebec"},
    {name = "Michael Bunsen", email = "michael.bunsen@mila.quebec"},
    {name = "Fagner Cunha", email = "fagner.cunha@icomp.ufam.edu.br"},
    {name = "Léonard Pasi", email = "leonardpasi@gmail.com"},
]

dependencies = [
    "click>=8.1.6",
    "numpy>=1.25.1",
    "torch>=2.0,!=2.0.1",
    "tqdm>=4.65.0",
    "segment-anything>=1.0",
    "torchvision>=0.15.1,!=0.15.2",
    "torchmetrics>=0.11.4",
    "pillow>=10.0.0",
    "matplotlib>=3.7.2",
    "python-dwca-reader>=0.15.1",
    "pandas>=2.1.0",
    "scikit-learn>=1.3.0",
    "webdataset>=0.2.48",
    "timm>=0.9.8",
    "typer>=0.12.3",
    "python-dotenv>=1.0.1",
    "wandb>=0.17.5",
    "pygbif>=0.6.5",
    "opencv-python>=4.11.0.86",
]

[project.optional-dependencies]
research = [
    "awscli>=1.33.44",
    "awscli-plugin-endpoint>=0.4",
    "absl-py>=2.1.0",
]
dev = [
    "pre-commit>=3.3.3",
    "black>=23.7.0",
    "flake8>=6.0.0",
    "Flake8-pyproject>=1.2.3",
    "isort>=5.12.0",
    "mypy>=1.4.1",
    "ipdb>=0.13.13",
    "python-devtools>=2",
    "ipykernel>=6.29.4",
    "pytest>=8.1.1",
]

[project.scripts]
ami-dataset = "src.dataset_tools.cli:cli"
ami-classification = "src.classification.cli:cli"

[tool.hatch.build.targets.wheel]
packages = ["src"]

[tool.flake8]
max-line-length = 88
ignore = ["E203", "E266", "E501", "W503"]
max-complexity = 25
per-file-ignores = [
    "__init__.py:F401",
    "src/localization/training.py:E402"
]
exclude = [
    ".git",
    "research/deprecated/*",
    "__pycache__"
]

2. Update README.md

Update the Setup and Usage sections to reflect uv instead of Poetry:

Changes needed in README.md:

Replace the Setup section (lines 22-37) with:

## Setup

[uv](https://github.com/astral-sh/uv) is used to manage the dependencies common to all scripts and sub-projects. uv is a fast, modern Python package manager.

1. Install [uv](https://docs.astral.sh/uv/getting-started/installation/)
   ```bash
   # On macOS and Linux
   curl -LsSf https://astral.sh/uv/install.sh | sh
   
   # On Windows
   powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
  1. Clone this repository
  2. Create a .env or copy .env.example and update the values
  3. Install dependencies in the root of the repository:
    uv sync
  4. Install pre-commit hooks:
    uv run pre-commit install

[Optional] Conda + uv

An optional way to setup the environment is to use Conda for creating and managing the Python environment, while using uv for managing the packages and dependencies.

  1. Install Conda
  2. Create conda environment using the environment.yml: conda env create -f environment.yml
  3. Activate the conda environment: conda activate ami-ml
  4. Install packages in the root of the repository using uv: uv sync

Replace the Usage section (lines 39-60) with:

```markdown
## Usage

Activate the virtual environment before running scripts

```bash
source .venv/bin/activate  # On Linux/macOS
# or
.venv\Scripts\activate     # On Windows

Example for running a script (in the activated environment):

python src/localization/inference_localization.py \
  --data_dir ~/TRAPIMAGES/Sample/ \
  --ckpt_path ~/Downloads/fasterrcnn_mobilenet_v3_large_fpn_uqfh7u9w.pt \
  --model_type fasterrcnn_mobilenet_v3_large_fpn

Alternatively, one can run scripts without activating the environment:

uv run python <script>

The uv run command automatically uses the project's virtual environment.


### 3. Update research/README.md

Update the usage instructions to use uv:

**Changes needed in research/README.md**:

Replace the Usage section (lines 4-11) with:

```markdown
## Usage
An example environment variables file is provided in `.env.example`. To use it, rename the file to `.env` and update the values as needed.

Example of running a script us...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/RolnickLab/ami-ml/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

…nd update README

Co-authored-by: mihow <158175+mihow@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate dependency management from Poetry to uv Migrate dependency management from Poetry to uv Jan 20, 2026
Copilot AI requested a review from mihow January 20, 2026 20:48
@mihow
Copy link
Copy Markdown
Collaborator

mihow commented Jan 20, 2026

@copilot run some commands to test if it works

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 20, 2026

@copilot run some commands to test if it works

Tested the migration successfully! Here's what I verified:

uv sync - Installed 96 core packages in ~36 seconds
uv sync --extra dev - Installed 47 dev packages in ~1 second
✅ Virtual environment created at .venv/
✅ Lock file generated (uv.lock with 201 resolved packages)
✅ Core dependencies (torch, numpy, pandas) import successfully
✅ CLI commands ami-dataset and ami-classification work
✅ Pre-commit available with dev extras
✅ Virtual environment activation works as documented
✅ Torch 2.9.1+cu128 with CUDA support installed

All commands from the updated README work as expected. The migration is fully functional!

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: /usr/bin/curl curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Copy Markdown
Collaborator

@mihow mihow left a comment

Choose a reason for hiding this comment

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

Looks promising! Add a git workflow to install the package and test a command. Make a placeholder step for running our test suite (uv test, etc)

Co-authored-by: mihow <158175+mihow@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 20, 2026

Looks promising! Add a git workflow to install the package and test a command. Make a placeholder step for running our test suite (uv test, etc)

Added GitHub Actions CI workflow in commit 76e46e3. The workflow includes:

✅ Multi-version Python testing (3.9, 3.10, 3.11, 3.12)
✅ uv installation and dependency sync with uv sync --extra dev
✅ CLI command testing for ami-dataset and ami-classification
✅ Placeholder test suite step with uv run pytest tests/ -v
✅ Core dependency import verification

The workflow runs on pushes and PRs to main branch. The test suite step includes a TODO comment and falls back gracefully if tests aren't fully configured yet.

Copilot AI requested a review from mihow January 20, 2026 21:05
mihow
mihow previously requested changes Jan 20, 2026
Copy link
Copy Markdown
Collaborator

@mihow mihow left a comment

Choose a reason for hiding this comment

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

Make the required python version >py10. update the test matrix, just test py12 in the workflows. How does this project manage optional dependencies, if there are any? do the workflows test any optional deps?

…3.12, and add research extras testing

Co-authored-by: mihow <158175+mihow@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 20, 2026

Make the required python version >py10. update the test matrix, just test py12 in the workflows. How does this project manage optional dependencies, if there are any? do the workflows test any optiona...

Updated in commit f43ff1c:

✅ Python requirement changed to >=3.10 in pyproject.toml
✅ CI workflow simplified to test only Python 3.12 (removed matrix)
✅ Optional dependencies testing added:

  • dev extras: already installed (pre-commit, black, flake8, pytest, etc.)
  • research extras: now installed and verified (awscli, awscli-plugin-endpoint, absl-py)

The workflow now runs uv sync --extra dev --extra research and includes a verification step to import both core and research optional dependencies.

Copilot AI requested a review from mihow January 20, 2026 21:17
@mihow mihow requested a review from f-PLT January 20, 2026 21:29
@mihow mihow marked this pull request as ready for review February 11, 2026 02:57
Copy link
Copy Markdown
Collaborator

@mihow mihow left a comment

Choose a reason for hiding this comment

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

I was able to use this on my local workstation to install and run each step of the workflow. I don't know how it will work on DRAC & in SLURM jobs though.

@mihow mihow dismissed their stale review February 11, 2026 03:14

i didn't mean to request changes

Comment thread pyproject.toml Outdated
Comment thread README.md
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the project’s dependency management from Poetry to uv by adopting PEP 621 metadata in pyproject.toml, updating developer-facing setup/usage documentation, and introducing a GitHub Actions CI workflow that installs and sanity-checks the package.

Changes:

  • Converted pyproject.toml from [tool.poetry] to PEP 621 [project] metadata and switched the build backend to Hatchling.
  • Updated README.md to use uv sync / uv run instead of Poetry commands.
  • Added a new .github/workflows/ci.yml workflow to install dependencies with uv, run CLI help checks, run pytest, and verify imports.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 9 comments.

File Description
README.md Updates setup and usage instructions to use uv (and adds platform-specific install/activation guidance).
pyproject.toml Migrates packaging metadata/dependencies to PEP 621 and switches build backend to Hatchling.
.github/workflows/ci.yml Introduces CI that installs via uv and runs basic CLI/tests/import checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread pyproject.toml
Comment thread README.md Outdated
Comment thread README.md
Comment thread README.md
Comment thread README.md Outdated
mihow and others added 3 commits June 4, 2026 13:14
CI workflow (.github/workflows/ci.yml):
- Install uv via astral-sh/setup-uv action instead of curl|sh (supply-chain).
- Use `uv sync --frozen` so CI fails if uv.lock is out of date.
- Run the real test suite (`uv run pytest tests/ -v`) instead of swallowing
  failures with `|| echo`; the repo has tests under tests/.

pyproject.toml:
- Cap Python at <3.15 to avoid breakage on too-new interpreters (per f-PLT).

.python-version:
- Pin the project interpreter to 3.12 so contributors share one venv version
  and avoid churning uv.lock (per f-PLT, agreed by mihow).

README.md:
- `uv sync --extra dev` in setup so the following pre-commit step has it.
- Fix Windows activation to `.\.venv\Scripts\Activate.ps1` (PowerShell).
- Note that `uv run` uses the project venv automatically.

research/README.md:
- Replace stale "Conda + Poetry" instructions with uv.

uv.lock:
- Regenerate; drops dead python<3.10 entries.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Separate fast `lint` job (pre-commit in isolated hook envs, no torch) from
  the heavy `test` job (full dependency install + pytest).
- Enable uv's built-in cache (enable-cache) on both jobs and cache the
  pre-commit hook environments.
- Lint only files changed in the PR; the repo predates this CI and carries
  flake8 debt in older modules, so a full-tree run would fail on unrelated code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Delete the now-stale poetry.lock (uv.lock is the source of truth).
- environment.yml: install uv instead of poetry in the optional Conda flow;
  bump pinned python to 3.12 to match .python-version.
- research/eccv2024 job scripts: `poetry run` -> `uv run`.
- src/classification/README.md: drop "Conda + Poetry" recommendation in favour
  of uv.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mihow and others added 2 commits June 4, 2026 13:43
The lint job diffed `head.sha..base.sha` from a shallow PR checkout, but on
pull_request events actions/checkout builds a merge commit and clones shallow,
so those SHAs aren't resolvable objects and `git diff` failed with
"Invalid revision range".

Run the lint job on pull requests only, check out full history
(fetch-depth: 0), fetch the base branch, and diff `origin/<base>..HEAD`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The migration carried over `license = "MIT"` from the old Poetry config, but
the repository switched to AGPLv3 in #76. Align the packaging metadata.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mihow mihow merged commit 0c2e981 into main Jun 4, 2026
2 checks passed
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.

4 participants