4 ms·
If the libraries are meant to be used together, you can get away with one venv. If they should be decoupled, then one venv per lib is better. There is not much
by BiteCode_dev 2y ago
If the libraries are meant to be used together, you can get away with one venv. If they should be decoupled, then one venv per lib is better.
There is not much to know:
- uv python install <version> if you want a particular version of python to be installed
- uv init --vcs none [--python <version>] in each directory to initialize the python project
- uv add [--dev] to add libraries to your venv
- uv run <cmd> when you want to run a command in the venv
That's it, really. Any bonus can be learned later.
- NeutralForest 2y agoThere's also workspaces (https://docs.astral.sh/uv/concepts/projects/workspaces/ https://docs.astral.sh/uv/concepts/projects/workspaces/) if you have common deps and it's possible to act on a specific member of the workspace as well.
- BiteCode_dev 2y agoThat's one of the bonus I was thinking about. It's nice if you have a subset of deps you want to share, or if one dep is actually part of the monorepo, but it does require more to know.
- new_user_final 2y agouv sync if you clone a github repo
- BiteCode_dev 2y agouv run in the freshly cloned repo will create the venv and install all deps automatically. You can even use --extra and --group with uv run like with uv sync. But in a monorepo, those are rare to use.
- theogravity 2y agoThanks for the info. I looked at the group documentation, but it's not clear to me why I would want to use it, or where I would use it: https://docs.astral.sh/uv/concepts/projects/layout/#default-groups https://docs.astral.sh/uv/concepts/projects/layout/#default-... (I'm a JS dev who has to write a set of python packages in a monorepo.)
- BiteCode_dev 2y agosync is something you would rarely use, it's most useful for scripting. uv run is the bread and meat of uv, it will run any command you need in the project, and ensure it will work by synching all deps and making sure your command can import stuff and call python. In fact, if you run a python script, you should do uv run python the_script.py, It's so common uv run the_script.py will work as a shortcut. I will write a series of article on uv on bitecode.dev. I will write it so that it work for non python devs as well.
- theogravity 2y agoDid you mean group and not sync? Really looking forward to the articles!
- BiteCode_dev 2y agoSorry i misread and stayed on sync. Group and extras are for lib makers to create sets of optionals dependenacies. Groups are private ones for maintainers, extras are oublic one for users.
- theogravity 2y agoThanks. Why is the notion of run and tool separate? Coming from JS, we have the package.json#scripts field and everything executes via a `pnpm run <script name>` command.
- BiteCode_dev 2y agoTool ? Maybe you mean uv tool install ? In that case it's something you don't need right now, uv tool is useful, but it's a bonus. It's to install 3rd party utilities outside of the project. There is no equivalent to script yets, althought they are adding it as we speak. uv run exec any command in the context of the venv (which is like a node_modules), you don't need to declare them prior to calling them. e.g: uv run python will start the python shell.
- theogravity 2y agoI was looking at https://docs.astral.sh/uv/concepts/tools/#the-uv-tool-interface https://docs.astral.sh/uv/concepts/tools/#the-uv-tool-interf... Edit: I get it now. It's like npm's `npx` command.
- BiteCode_dev 2y agouvx is the npx equivalent, it's provided with ux, and also has some nice bonuses.