|
| 1 | +--- |
| 2 | +marp: true |
| 3 | +theme: theme.css |
| 4 | +paginate: true |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +<!-- _class: title --> |
| 12 | +<!-- _header: '_21.05.2025_' --> |
| 13 | +<!-- paginate: false --> |
| 14 | +# The dependency inferno |
| 15 | +## A descent into the Python packaging hell |
| 16 | + |
| 17 | +#### |
| 18 | +#### |
| 19 | +#### |
| 20 | +#### :zap: Lighting talk :zap: |
| 21 | +#### Sunniva Indrehus |
| 22 | + |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | + |
| 27 | +<!-- paginate: true --> |
| 28 | + |
| 29 | +``` |
| 30 | +autodesk$ echo $(whoami) |
| 31 | +``` |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +<!-- _footer: 'Figure credit:[xkcd](https://imgs.xkcd.com/comics/python_environment.png)' --> |
| 36 | + |
| 37 | +# The Python dependency hell |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +# Short :snake: :package: history |
| 44 | + |
| 45 | +- **1991** Python 1.0 released (Guido van Rossum) |
| 46 | +- **2008** Python 3.0 & rise of `setuptools` |
| 47 | +- **2009** `conda` released (Anaconda Inc.) |
| 48 | +- **2011** `pip` bundled with Python |
| 49 | +- **2013** `virtualenv` becomes widely used |
| 50 | +- **2017** `pipenv` launched (PyPA-backed) |
| 51 | +- **2018** `poetry` (S. Eustace) |
| 52 | +- **2019** [`hatch`](https://github.com/pypa/hatch) (Ofek) |
| 53 | +- **2020**: |
| 54 | + - Widespread `pyproject.toml` adoption ([PEPs 517/518/621](https://peps.python.org/pep-0621/)) |
| 55 | + - [`PDM`](https://github.com/pdm-project/pdm) (Frost Ming) |
| 56 | +- **2024** [`uv`](https://docs.astral.sh/uv/) (Astral) |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +# Short :snake: :package: history |
| 61 | + |
| 62 | +- **1991** Python 1.0 released (Guido van Rossum) |
| 63 | +- **2008** Python 3.0 & rise of `setuptools` |
| 64 | +- **2009** `conda` released (Anaconda Inc.) |
| 65 | +- **2011** `pip` bundled with Python |
| 66 | +- **2013** `virtualenv` becomes widely used |
| 67 | +- **2017** `pipenv` launched (PyPA-backed) |
| 68 | + <div style="border: 2px solid red; padding: 6px; border-radius: 6px; background-color: #fff5f5;"> |
| 69 | + <strong>2018</strong> <code>poetry</code> (S. Eustace) |
| 70 | + </div> |
| 71 | +- **2019** [`hatch`](https://github.com/pypa/hatch) (Ofek) |
| 72 | +- **2020**: |
| 73 | + - Widespread `pyproject.toml` adoption ([PEPs 517/518/621](https://peps.python.org/pep-0621/)) |
| 74 | + - [`PDM`](https://github.com/pdm-project/pdm) (Frost Ming) |
| 75 | +- **2024** [`uv`](https://docs.astral.sh/uv/) (Astral) |
| 76 | + |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | + |
| 81 | +# Short :snake: :package: history |
| 82 | + |
| 83 | +- **1991** Python 1.0 released (Guido van Rossum) |
| 84 | +- **2008** Python 3.0 & rise of `setuptools` |
| 85 | +- **2009** `conda` released (Anaconda Inc.) |
| 86 | +- **2011** `pip` bundled with Python |
| 87 | +- **2013** `virtualenv` becomes widely used |
| 88 | +- **2017** `pipenv` launched (PyPA-backed) |
| 89 | +- **2018** `poetry` (S. Eustace) |
| 90 | +- **2019** [`hatch`](https://github.com/pypa/hatch) (Ofek) |
| 91 | +- **2020**: |
| 92 | + - Widespread `pyproject.toml` adoption ([PEPs 517/518/621](https://peps.python.org/pep-0621/)) |
| 93 | + - [`PDM`](https://github.com/pdm-project/pdm) (Frost Ming) |
| 94 | + <div style="border: 2px solid red; padding: 6px; border-radius: 6px; background-color: #fff5f5;"> |
| 95 | + <strong>2024</strong> <code>uv</code> (Astral) |
| 96 | + </div> |
| 97 | + |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | + |
| 102 | +# UV |
| 103 | + |
| 104 | +- Ultra-fast Python package manager and resolver |
| 105 | +- Drop-in replacement for `pip`, `pip-tools`, and parts of `Poetry` |
| 106 | +- Unified installation of python across OS |
| 107 | +- The lock file is cross platform |
| 108 | + |
| 109 | + |
| 110 | +<div style="display: flex; flex-direction: column; align-items: margin-top: 2em;"> |
| 111 | + <img src="https://github-production-user-asset-6210df.s3.amazonaws.com/1309177/316150505-629e59c0-9c6e-4013-9ad4-adb2bcf5080d.svg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA53PQK4ZA%2F20250520%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250520T123025Z&X-Amz-Expires=300&X-Amz-Signature=6f16d4685a6aaca2b0eb123678ffb5870a70f26cf95691da6d75ce50ca366933&X-Amz-SignedHeaders=host#only-light" alt="Cute kitten" style="max-width: 80%; border-radius: 12px; box-shadow: 0 4px 10px rgba(0,0,0,0.15);" /> |
| 112 | + <figcaption style="margin-top: 0.8em; font-size: 0.9em; color: #555; font-style: italic;"> |
| 113 | + Time for installing Trio's dependencies with warm cache, Figure credit: <a href="https://github-production-user-asset-6210df.s3.amazonaws.com/1309177/316150505-629e59c0-9c6e-4013-9ad4-adb2bcf5080d.svg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA53PQK4ZA%2F20250520%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250520T123025Z&X-Amz-Expires=300&X-Amz-Signature=6f16d4685a6aaca2b0eb123678ffb5870a70f26cf95691da6d75ce50ca366933&X-Amz-SignedHeaders=host#only-light" style="color: blue;">Astral's docs</a> |
| 114 | + </figcaption> |
| 115 | +</div> |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +# Basic API |
| 120 | + |
| 121 | +## Install uv |
| 122 | + |
| 123 | +``` |
| 124 | +~$ curl -LsSf https://astral.sh/uv/install.sh | sh |
| 125 | +~$ uv |
| 126 | +An extremely fast Python package manager. |
| 127 | +
|
| 128 | +Usage: uv [OPTIONS] <COMMAND> |
| 129 | +``` |
| 130 | + |
| 131 | +## Install latest python version |
| 132 | + |
| 133 | +``` |
| 134 | +~$ uv python install |
| 135 | +~$ uv python install 3.12 |
| 136 | +~$ uv python install pypy@3.10 |
| 137 | +``` |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | + |
| 142 | +Start a project |
| 143 | + |
| 144 | +``` |
| 145 | +~$ uv init test-uv |
| 146 | +~test-uv$ ls |
| 147 | +├── .git |
| 148 | +├── .gitignore |
| 149 | +├── .python-version |
| 150 | +├── README.md |
| 151 | +├── main.py |
| 152 | +├── pyproject.toml |
| 153 | +``` |
| 154 | +Run example script |
| 155 | + |
| 156 | +``` |
| 157 | +~test-uv$ uv run main.py |
| 158 | + Using CPython 3.13.3 |
| 159 | + Creating virtual environment at: .venv |
| 160 | + Hello from test-uv! |
| 161 | +``` |
| 162 | +--- |
| 163 | + |
| 164 | +## Start a package project |
| 165 | +``` |
| 166 | +~$ uv init --package test-uv-package |
| 167 | +~test-uv-package$ ls |
| 168 | +├── .git |
| 169 | +├── .gitignore |
| 170 | +├── .python-version |
| 171 | +├── README.md |
| 172 | +├── pyproject.toml |
| 173 | +├── src |
| 174 | +│ ├── test_uv_package |
| 175 | +│ └── __init__.py |
| 176 | +``` |
| 177 | + |
| 178 | +Run example script |
| 179 | + |
| 180 | +``` |
| 181 | +~test-uv-package$ uv run test-uv-package |
| 182 | + Using CPython 3.13.3 |
| 183 | + Creating virtual environment at: .venv |
| 184 | + Hello from test-uv-package! |
| 185 | +``` |
| 186 | + |
| 187 | +--- |
| 188 | + |
| 189 | +# Plain dependency migration |
| 190 | + |
| 191 | +``` |
| 192 | +~my-project$ uvx migrate-to-uv |
| 193 | +Installed 1 package in 16ms |
| 194 | +Locking dependencies with "uv lock"... |
| 195 | +Using CPython 3.12.4 interpreter at: /Users/sunnivaindrehus/.pyenv/versions/3.12.4/bin/python3.12 |
| 196 | +Resolved 123 packages in 1.01s |
| 197 | +Successfully migrated project from Poetry to uv! |
| 198 | +``` |
| 199 | +--- |
| 200 | + |
| 201 | +# Complex dependency migration |
| 202 | + |
| 203 | +1. Make sure to capture all dependendencies (use the right poetry version, and all relevant groups) |
| 204 | + |
| 205 | + ``` |
| 206 | + ~/repo$ poetry@1.8 export -f requirements.txt --output requirements.txt --without-hashes --with dev |
| 207 | + ``` |
| 208 | +
|
| 209 | +2. Remove `pyproject.toml` and `poetry.lock` files. |
| 210 | + |
| 211 | + ``` |
| 212 | + ~/repo$ uv init --bare |
| 213 | + ``` |
| 214 | +
|
| 215 | +3. Install locked dependencies from `.txt`file |
| 216 | + |
| 217 | + ``` |
| 218 | + ~/repo$ uv add -r requirements.txt |
| 219 | + ``` |
| 220 | +
|
| 221 | +--- |
| 222 | +
|
| 223 | +# Private packages migration |
| 224 | +
|
| 225 | +### Poetry (1.8) |
| 226 | +``` |
| 227 | +[tool.poetry.dependencies] |
| 228 | +python = ">=3.11,<3.12" |
| 229 | +my-private-package = { git = "git@github.com:my-org/my-private-package.git", tag = "1.0.1" } |
| 230 | +``` |
| 231 | +
|
| 232 | +
|
| 233 | +### uv |
| 234 | +``` |
| 235 | +[project] |
| 236 | +requires-python = ">=3.11,<3.12" |
| 237 | +dependencies = [ |
| 238 | + "my-private-package; |
| 239 | + ] |
| 240 | + |
| 241 | +[tool.uv.sources] |
| 242 | +"my-private-package" {git= "ssh://git@github.com:my-org/my-private-package.git", rev="34f59994bb920679ba5f0cade8061e0da7ca00b5"} |
| 243 | +``` |
| 244 | +
|
| 245 | +--- |
| 246 | +
|
| 247 | +# Poetry vs. uv |
| 248 | +
|
| 249 | +--- |
| 250 | +
|
| 251 | +# UV |
| 252 | +## - A promising candidate to acend from the Python packaging hell |
| 253 | +
|
| 254 | + |
0 commit comments