6 Comments
User's avatar
ArthurJ's avatar

Great post!

Expand full comment
Jan Koch's avatar

That's a good introduction, thank for this. Wondering though: why didn't you use that `uv init` creates the subdirectory? Are you aware that instead of activating the venv, you could also just use `uv run python -m main.py`. This allows you to almost forget about the venv.

Expand full comment
Boldizsár's avatar

Thanks Jan! I think I'm not aware of the `uv init` option you're suggesting, what would you have run instead? Thanks in advance for sharing.

About `uv run` I am indeed aware and I know a lot of people who use it, but I think it's more ergonomic to activate the venv once and then directly run the shorter commands. For one, typing `uv run` a lot adds up fast. Second, directly running commands gives you proper shell completion, which doesn't work (at least for me) with the `uv run` wrapper. But I admit that this is just a personal preference so if you're more comfortable with `uv run` and not activating the venv then there're no problem with that, keep using it!

Expand full comment
Jan Koch's avatar

`uv init alice` creates the folder directly. Didn't think about shell completion, thanks for sharing this

Expand full comment
Boldizsár's avatar

Thank you! That's close, but it doesn't exactly do what we need. Take a look, try it out in a random empty folder:

boldizsar@machine:/tmp/tmp.jRIqfFGn6V $ uv init alice

tree Initialized project `alice` at `/tmp/tmp.jRIqfFGn6V/alice`

boldizsar@machine:/tmp/tmp.jRIqfFGn6V $ tree .

.

└── alice

├── main.py

├── pyproject.toml

└── README.md

2 directories, 3 files

It did create the alice subfolder, but it also placed the `pyproject.toml` and the `README.md` inside the folder. This effectively means that it just placed the project root somewhere else, but the Python module is still `main`, instead of `alice`. It would be great though if uv could initialize the project structure that we want – README.md and pyproject.toml at the root, but the Python code inside a custom subfolder.

Expand full comment
Jan Koch's avatar

You could add the `--package` or `--lib` option and get a src folder

Expand full comment