Skip to content

Commit 2278037

Browse files
committed
docs update
1 parent 05cb2d9 commit 2278037

File tree

3 files changed

+59
-71
lines changed

3 files changed

+59
-71
lines changed

README.md

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ iex (iwr "https://pup-py-fetch.hf.space?python=3.11&pixi=marimo&tables=duckdb,pa
4747

4848
## How It Works
4949

50-
Puppy can be used as a CLI or as a module.
50+
Puppy can be used as a CLI in a Linux or Windows shell, or as a [module](#using-pup-as-a-module-pupfetch) in any python shell/script/[notebook](#puppy--environments-in-notebooks).
5151

5252
Installing puppy preps the folder to house python, in complete isolation from system or any other python on your system:
5353

5454
0) 🐍 this folder is home to one and only one python executable, managed by pixi
55-
1) ✨ pixi installs core components: python, uv, click
55+
1) ✨ pixi installs core components: python, uv, [click](https://github.com/pallets/click)
5656
2)[Bash](https://github.com/liquidcarbon/puppy/blob/main/pup.sh) or [Powershell](https://github.com/liquidcarbon/puppy/blob/main/pup.ps1) runner/installer is placed into `~/.pixi/bin` (the only folder that goes on PATH)
57-
3) 🐶 `pup.py` is the python/[click](https://github.com/pallets/click) CLI that wraps pixi and uv commands
57+
3) 🐶 `pup.py` is the python/click CLI that wraps pixi and uv commands
5858
4) 🟣 `pup new` and `pup add` use uv to handle projects, packages and virtual environments
5959
5) 📀 `pup clone` and `pup sync` help build environments from external `pyproject.toml` project files
6060

6161
https://github.com/user-attachments/assets/9cdd5173-5358-404a-84cc-f569da9972f8
6262

63-
## Using `pup` as a Module
63+
## Using `pup` as a Module: `pup.fetch`
6464

6565
Pup can help you construct and activate python projects interactively, such as from (i)python shells, jupyter notebooks, or [marimo notebooks](https://github.com/marimo-team/marimo/discussions/2994).
6666

@@ -142,12 +142,61 @@ Specify what to install:
142142
Hello from test-only-root!
143143
```
144144

145-
## Notebooks (WIP)
145+
## Puppy & Environments in Notebooks
146146

147-
Coming soon: templates for Jupyter and Marimo notebooks.
148-
[Unified environment management for any computational notebooks](https://github.com/marimo-team/marimo/discussions/2994) - no more Jupyter kernels!
147+
> [!NOTE]
148+
> Conda or PyPI packages installed with `pixi add ...` always remain on `sys.path` and stay available across all environments. Though one could exclude them, I have yet to find a reason to do so.
149+
150+
### Jupyter
151+
152+
There's a good chance you're confused about how Jupyter kernels work and find setting up kernels with virtual environments too complicated to bother. Puppy's [v1](https://github.com/liquidcarbon/puppy/tree/v1) was addressing that problem, but in v2 (current version) this is taken care of by `pup.fetch`. Here's the gist:
153+
154+
1) install ONE instance of jupyter with `pixi add jupyter` per major version of python
155+
2) run it with `pixi run jupyter lab` or `pixi run jupyter notebook`
156+
3) use `pup.fetch` to build and activate your environment - THAT'S IT!
157+
158+
For details, scan through the [previous section](#using-pup-as-a-module-pupfetch). In brief, `pup.fetch` creates/modifies and/or activates your venv by appending its folder to `sys.path`. This is pretty very similar to how venvs and kernels work. A jupyter kernel is a pointer to a python executable. Within a venv, the executable `.venv/bin/python` is just a symlink to the parent python - in our case, to pixi's python. The activation and separation of packages is achieved by manipulating `sys.path` to include local `site-packages` folder(s).
159+
160+
161+
### Marimo
162+
163+
With marimo, you have more options: [Unified environment management for any computational notebooks](https://github.com/marimo-team/marimo/discussions/2994) - no more Jupyter kernels!
164+
165+
## Multi-Puppy-Verse
166+
167+
Can I have multiple puppies? As many as you want! Puppy is not just a package installer, but also a system to organize multiple python projects.
168+
169+
A pup/py home is defined by one and only one python executable, which is managed by pixi, along with tools like uv, jupyter, hatch, pytest, and conda-managed packages. We use home-specific tools through a pixi shell from anywhere within the folder, e.g. `pixi run python`, `pixi run jupyter`, or, to be explicit, by calling their absolute paths.
170+
171+
> [!NOTE]
172+
> If you need a "kernel" with a different version of python, install puppy in a new folder. **Puppy's folders are completely isolated from each other and any other python installation on your system.** Remember, one puppy folder = one python executable, managed by Pixi. Pup commands work the same from anywhere within a pup folder, run relative to its root, via `.pixi/envs/default/bin/python`. Place puppy folders side-by-side, not within other puppy folders - nested puppies might misbehave.
173+
174+
```
175+
# ├── puphome/ # python 3.12 lives here
176+
# │ ├── public-project/
177+
# │ │ ├── .git # this folder may be a git repo (see pup clone)
178+
# │ │ ├── .venv
179+
# │ │ └── pyproject.toml
180+
# │ ├── env2/
181+
# │ │ ├── .venv/ # this one is in pre-git development
182+
# │ │ └── pyproject.toml
183+
# │ ├── pixi.toml
184+
# │ └── pup.py
185+
# ├── pup311torch/ # python 3.11 here
186+
# │ ├── env3/
187+
# │ ├── env4/
188+
# │ ├── pixi.toml
189+
# │ └── pup.py
190+
# └── pup313beta/ # 3.13 here
191+
# ├── env5/
192+
# ├── pixi.toml
193+
# └── pup.py
194+
```
195+
196+
The blueprint for a pup/py home is in `pixi.toml`; at this level, git is usually not needed. The inner folders are git-ready project environments managed by pup and uv. In each of the inner folders, there is a classic `.venv` folder and a `pyproject.toml` file populated by uv. When you run `pup list`, pup scans this folder structure and looks inside each `pyproject.toml`. The whole setup is very easy to [containerize](examples/) (command to generate `Dockerfile` coming soon!).
149197

150-
`pup play --help`
198+
> [!TIP]
199+
> Use `pup list -f` to list all dependencies spelled out in `uv.lock`.
151200
152201
## But Why
153202

pup.py

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
The CLI for pup, a cute python project manager.
55
"""
66

7-
__version__ = "2.4.0"
7+
__version__ = "2.5.0"
88

99
import collections
1010
import json
1111
import platform
1212
import subprocess
1313
import sys
1414
from pathlib import Path
15-
from textwrap import dedent
1615
from time import strftime
1716
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple
1817

@@ -160,52 +159,6 @@ def load_pyproject_toml(path: Path) -> Dict[str, Any]:
160159
"""Load folder's `pyproject.toml` file."""
161160
return tomllib.load((path / "pyproject.toml").open("rb"))
162161

163-
# @staticmethod
164-
# def verbose(fn: Callable) -> Callable:
165-
# click.echo("decorator for CLI commands")
166-
# return fn
167-
168-
169-
class Notebook:
170-
"""Notebook stuff."""
171-
172-
def __init__(self, engine: str):
173-
return
174-
175-
@staticmethod
176-
def install_nb_package(engine: str):
177-
with open(Pup.HOME / "pixi.toml") as f:
178-
pixi_toml = f.read()
179-
if engine == "marimo":
180-
if "marimo" not in pixi_toml:
181-
Pup.do("""pixi add "marimo>=0" """)
182-
elif engine in ("lab", "notebook"):
183-
if "jupyter" not in pixi_toml:
184-
Pup.do("""pixi add "jupyter>=1" """)
185-
else:
186-
Pup.say(f"notebook engine '{engine}' not supported")
187-
exit(1)
188-
return
189-
190-
191-
class Template:
192-
"""Templates and env managers for `pup play`."""
193-
194-
TIME_FORMAT: str = "%y%m%d%H%M%S"
195-
196-
Marimo = dedent("""
197-
import marimo
198-
app = marimo.App(width="full")
199-
200-
@app.cell
201-
def __():
202-
import pup; pup.fetch()
203-
return (pup,)
204-
205-
if __name__ == "__main__":
206-
app.run()
207-
""")
208-
209162

210163
# prep Pup attributes and environments before setting up CLI
211164
Pup.welcome()
@@ -417,20 +370,6 @@ def pup_list(
417370
)
418371

419372

420-
@main.command(name="play")
421-
@click.option(
422-
"--engine",
423-
"-e",
424-
type=click.Choice(["marimo", "notebook", "lab"]),
425-
default="marimo",
426-
help="notebook engine",
427-
)
428-
def play(engine: str, kernel: str):
429-
"""Create a notebook in a specified environment."""
430-
431-
Notebook.install_nb_package(engine)
432-
433-
434373
### Utils ###
435374

436375

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "puppy"
3-
version = "2.4.1"
3+
version = "2.5.0"
44
description = "Your new best friend in the python world."
55
readme = "README.md"
66
requires-python = ">=3.10"

0 commit comments

Comments
 (0)