Skip to content

Conversation

Copy link

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
Collaborator

mihow commented Jan 20, 2026

@copilot run some commands to test if it works

Copy link
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
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
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
Copy link
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
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
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.

2 participants