11---
22marp : true
33theme : simplepy
4- _class : lead
5- paginate : false
6- backgroundColor : # fff
7- backgroundImage : url('https://marp.app/assets/hero-background.svg')
4+ paginate : true
5+ _paginate : skip
86---
97
108# SIMPLE-Py
119
12- ## Intro to setup
10+ ## Setting up for development
1311
1412---
1513
@@ -20,21 +18,321 @@ backgroundImage: url('https://marp.app/assets/hero-background.svg')
2018
2119### Required
2220
23- - ` uv `
24- - ` pixi `
21+ - ` uv ` — fast package manager (Rust)
22+ - ` pixi ` — conda package manager (Rust)
2523- A system compiler
2624
2725</div >
2826<div >
2927
3028### Recommended
3129
32- - ` prek `
33- - ` nox `
30+ - ` prek ` — linter/formatter runner
31+ - ` nox ` — task runner
32+
33+ _ (install via ` uv tool install ` )_
34+
35+ </div >
36+ </div >
37+
38+ ---
39+
40+ ## Low level concepts
41+
42+ ### How not to break your computer
43+
44+ These topics give you an understanding of what's going on.
45+ We'll introduce high-level abstractions next!
46+
47+ ---
48+
49+ ## Virtual environments
50+
51+ How to install stuff — three options:
52+
53+ | | Location | Pros | Cons |
54+ | ------------------------ | ----------------- | ------------------- | ----------------------- |
55+ | ** System site-packages** | ` /... ` | Works from anywhere | Can break your machine |
56+ | ** User site-packages** | ` ~/.local/... ` | User permission | Can break other Pythons |
57+ | ** Virtual environment** | ` .venv/ ` (common) | Many! | More effort |
58+
59+ ---
60+
61+ ## Why virtual environments?
62+
63+ System or user installs sound nice, but:
64+
65+ - Can't install incompatible packages
66+ - Can break your system
67+ - Can't control per-project needs
68+ - Hard to know your real requirements
69+ - Difficult to update
70+
71+ ** Solution:** a virtual environment — a folder (` .venv ` ) that isolates dependencies.
72+
73+ ---
74+
75+ ## Virtual environment structure
76+
77+ ```
78+ .venv
79+ ├── .gitignore
80+ ├── CACHEDIR.TAG
81+ ├── bin
82+ │ ├── activate # shell activation script
83+ │ ├── python # symlinks to your Python
84+ │ ├── python3
85+ │ └── python3.14
86+ ├── lib
87+ │ └── python3.14
88+ │ └── site-packages # installed libraries
89+ └── pyvenv.cfg # marks this as a venv
90+ ```
91+
92+ ---
93+
94+ ## Using a virtual environment
95+
96+ ** Direct usage:**
97+
98+ ``` bash
99+ .venv/bin/python ...
100+ ```
101+
102+ ** Activation:**
103+
104+ ``` bash
105+ . .venv/bin/activate
106+ python ...
107+ deactivate
108+ ```
109+
110+ > Activation sets ` PATH ` so the venv's ` bin/ ` comes first.
111+
112+ ---
113+
114+ ## Creating a virtual environment
115+
116+ | Command | Speed | Notes |
117+ | ----------------------- | ------ | ------------------------------------ |
118+ | ` python3 -m venv .venv ` | Slow | Built in (may need separate install) |
119+ | ` virtualenv .venv ` | Medium | Better defaults, requires install |
120+ | ` uv venv ` | Fast | Empty (no pip), defaults to ` .venv ` |
121+
122+ ** We'll use ` uv ` .**
123+
124+ ---
125+
126+ ## Requirements
127+
128+ A venv is expendable — you should be able to delete and recreate it.
129+
130+ Instead of manually installing, list packages in a file:
131+
132+ <div class =" columns " >
133+ <div >
134+
135+ ### Project (app)
136+
137+ - ** requirements.txt** — classic list
138+ - ** requirements.in** — manual locking
139+ - ** Lock file** — pinned versions
140+ - ** dependency-groups** — named collections
141+
142+ </div >
143+ <div >
144+
145+ ### Package (library)
146+
147+ - ** dependencies** — minimum to install
148+ - ** optional-dependencies** — extra requestable sets
149+
150+ Libraries also use "Project" patterns for dev needs (tests, docs).
34151
35152</div >
36153</div >
37154
38155---
39156
40- ## Basic concepts
157+ ## Lock files
158+
159+ - Every dependency ** fully specified** , ideally with a SHA
160+ - Great way to reproduce an environment exactly
161+ - ** Cannot** be used for libraries — two libraries with conflicting pins couldn't coexist
162+
163+ ---
164+
165+ ## Low-level summary
166+
167+ | Concept | Description |
168+ | ---------------- | ---------------------------------- |
169+ | ** venv** | Virtual environment isolating deps |
170+ | ** requirements** | List of packages to install |
171+ | ** lock files** | Fully pinned set of packages |
172+
173+ Creating, activating, installing, and locking are all ** separate steps** with different tools.
174+
175+ ---
176+
177+ ## High level packaging
178+
179+ ---
180+
181+ ## Persistent apps
182+
183+ Apps you install and run — never need to import alongside unrelated packages.
184+
185+ 1 . Make a venv somewhere
186+ 2 . Install the app in it
187+ 3 . Put just that app on your PATH
188+
189+ This is what ` pipx ` and ` uv tool ` do!
190+
191+ ``` bash
192+ uv tool install cowsay
193+ uv tool list
194+ uv tool upgrade cowsay
195+ uv tool uninstall cowsay
196+ ```
197+
198+ ---
199+
200+ ## Single-use apps
201+
202+ Combine install + run — ` uvx ` :
203+
204+ ``` bash
205+ uvx cowsay
206+ ```
207+
208+ Makes a venv, downloads the app, runs it. Recreates if over a week old.
209+
210+ ** All of PyPI at your fingertips** — no need to remember to update!
211+
212+ ---
213+
214+ ## Single-file scripts
215+
216+ ``` python
217+ # /// script
218+ # dependencies = ["numpy"]
219+ # ///
220+
221+ import numpy as np
222+
223+ if __name__ == " __main__" :
224+ print (np.array([1 , 2 , 3 ]))
225+ ```
226+
227+ ``` bash
228+ uv run simple.py # dependencies downloaded into a temp venv
229+ ```
230+
231+ ---
232+
233+ ## Projects (websites, etc.)
234+
235+ Very similar to libraries — key difference: ** always commit your lockfile** .
236+
237+ You can make an unpublishable library:
238+
239+ ``` toml
240+ [project ]
241+ classifiers = [
242+ " Private :: Do Not Upload" ,
243+ ]
244+ ```
245+
246+ ---
247+
248+ ## Libraries
249+
250+ Shared with others — must coexist in an environment with whatever else the user needs.
251+
252+ Basic ` pyproject.toml ` :
253+
254+ ``` toml
255+ [build-system ]
256+ requires = [" hatchling" ]
257+ build-backend = " hatchling.build"
258+
259+ [project ]
260+ name = " example"
261+ version = " 0.1.0"
262+ ```
263+
264+ The ` [build-system] ` tells tools how to build the package.
265+
266+ ---
267+
268+ ## Dependency locations
269+
270+ ``` toml
271+ [build-system ]
272+ requires = [" hatchling" ] # 1: build-time only
273+
274+ [project ]
275+ dependencies = [] # 2: always installed
276+
277+ [project .optional-dependencies ]
278+ extra = [] # 3: user-requested extras
279+
280+ [dependency-groups ]
281+ dev = [] # 4: dev-only, not in metadata
282+ ```
283+
284+ ---
285+
286+ ## Dependency comparison
287+
288+ | | ` b-s.r ` | ` p.d ` | ` p.o-d ` | ` d-g ` |
289+ | ------------------------- | ------- | ----- | ------- | ----- |
290+ | Public metadata | ✅ | ✅ | ✅ | ❌ |
291+ | Always installed | ❌ | ✅ | ❌ | ❌ |
292+ | Named groups | ❌ | ❌ | ✅ | ✅ |
293+ | Independently installable | ❌ | ❌ | ✅ | ✅ |
294+
295+ ---
296+
297+ ## High-level project management with ` uv `
298+
299+ If ` dependency-groups ` has a ` dev ` group, ` uv run ` installs it by default:
300+
301+ ``` toml
302+ [build-system ]
303+ requires = [" hatchling" ]
304+ build-backend = " hatchling.build"
305+
306+ [project ]
307+ name = " example"
308+ version = " 0.1.0"
309+ requires-python = " >=3.12"
310+ dependencies = [" numpy" ]
311+
312+ [dependency-groups ]
313+ dev = [" pytest" ]
314+ ```
315+
316+ ---
317+
318+ ## ` uv run pytest ` does all of this:
319+
320+ - Downloads Python if needed
321+ - Creates ` .venv ` if it doesn't exist
322+ - Installs from ` uv.lock ` if it exists
323+ - Creates ` uv.lock ` from dependencies if it doesn't exist
324+ - Makes an editable install of your project
325+ - Runs the command in that venv
326+
327+ Edit dependencies? Just ` uv run ` again — lockfile and venv update automatically.
328+
329+ ---
330+
331+ ## Summary
332+
333+ - ** Virtual environments** isolate dependencies per project
334+ - ** ` uv ` ** handles venvs, installs, locking, and running
335+ - ** ` uv tool ` / ` uvx ` ** for apps
336+ - ** ` uv run ` ** for project development
337+ - ** ` pyproject.toml ` ** declares dependencies at four levels
338+ - ** Lock files** ensure reproducibility
0 commit comments