Skip to content

[FEATURE] Change from Python package manager from conda to uv #97

@Eric-Liu-SANDAG

Description

@Eric-Liu-SANDAG

Is your feature request related to a problem? Please describe

A faster and more modern package manager (in addition to other benefits) compared to conda is uv. For example, uv provides a single unified interface which makes managing dependencies easier, as opposed to conda which sometimes requires a mix of conda and pip.

Describe the solution you'd like

The following steps should be done:

  • (If not done already) Install uv following the instructions on their website
  • Convert the contents of environment.yml into pyproject.toml (see Additional context for basic example)
  • Update any documentation, including the README.md with information on the new environment
  • Delete the old environment.yml file
  • Test code execution in the new uv environment to ensure everything still works (see Additional context for basic instructions)
  • Double check that the .gitignore is still correct (see Additional context for details)

Describe alternatives you've considered

N/A

Additional context (converting environment.yml into pyproject.toml)

To convert environment.yml into pyproject.toml, take the following example. SANDAG/HistoricalForecastError contains an environment.yml with roughly the following contents:

name: HistoricalError
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - https://repo.anaconda.com/pkgs/msys2
dependencies:
  - blas=1.0=mkl
  # Nearly 40 more lines of dependencies, version numbers, and checksum/sha values
  - zlib=1.2.13=h8cc25b3_1
  - pip:
      - pymssql==2.3.2

The corresponding pyproject.toml would be:

[project]
name = "HistoricalForecastError" # Required
version = "0.0.0" # Required, can leave as "0.0.0" if none available
requires-python = ">=3.11"
dependencies = [
    "pymssql>=2.3.2,<3.0.0",
]

Note that the dependency version has a minimum version so bug fixes can be automatically pulled, but is capped by a major version release, which is required when the interface changes (see Semantic Versioning)

Additional context (creating a uv environment and running code)

uv environments are built on top of Python's virtual environment, so all you need to do navigate to the project root and run in the command line

uv venv
uv sync

In order to run scripts in the newly created uv environment, simply do

uv run {script}

uv will automatically enter the virtual environment, run a bunch of checks, and run the script for you, all at blazing fast speed

Additional context (what should and shouldn't be committed)

You should commit pyproject.toml and uv.lock, the later of which is automatically created when running uv sync. Note that uv will ensure that the environment and pyproject.toml are synced up, so anytime you do uv run {script}, uv will automatically update the environment and uv.lock with any changes to pyproject.toml

You should not commit the virtual environment folder (default .venv/). This should be skipped via the .gitigonre

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions