Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uv and pixi. #464

Merged
merged 8 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ We also have a detailed [tutorial](tutorial.md) that has been given in a couple
The tutorial goes into much more pedagogical detail, it both describes using the template to create a package
and how to use the newly created package with some of the tools included.

1. Install [cookiecutter] in a Conda or `venv` environment (commented lines for
Conda example).
1. Install [cookiecutter] in a `uv venv` or `conda` environment (commented lines for
`uv venv` example).

```
# conda create --channel conda-forge --name new-env-name
# conda activate new-env-name
# conda install pip
pip install cookiecutter
# uv venv # creates a .venv directory wherever you are
# source ./.venv/bin/activate
uv pip install cookiecutter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative to installing in a (project specific) uv virtual environment we could recommend using the uv tools feature. Equivalent would then be something like

uv tool install cookiecutter

which will install cookiecutter in an isolated virtual environment and set up so cookiecutter is added to path.

Alternatively we could recommend using uvx to install and run directly in a temporary virtual environment

uvx cookiecutter gh:ucl-arc/python-tooling

This appears to be fairly minimal overhead (reports 13ms for installing packages in temporary virtual environment in my local system so no noticeable lag).

Problem with the latter is it then makes it difficult to keep instructions generic across different package manager / virtual environment solutions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of a rewording of the whole instructions then.

How about just laying out a few options in prose (doing away with step numbers)...

If you use [`uv`](LINK) you can use our template with the following one-liner
```sh
uvx cookiecutter gh:ucl-arc/python-tooling
```

You could also [install cookiecutter]() system-wide if you're likely to want to use cookiecutter again.
We like installing it as a [uv tool](LINKTOUVTOOLSDOCS)
```
uv tool install cookiecutter
cookiecutter gh:ucl-arc/python-tooling
```

```

2. Run cookiecutter in the desired directory
Expand Down Expand Up @@ -136,7 +135,7 @@ and how to use the newly created package with some of the tools included.
```
cd PROJECT_SLUG
git init
python -m pip install -e ".[dev]"
uv pip install -e ".[dev]"
```
6. Build your package
```
Expand Down Expand Up @@ -167,10 +166,10 @@ cd python-tooling
- To create and remove your virtual environment

```
conda create -n ptoolingVE pip -c conda-forge
conda activate ptoolingVE
conda deactivate ptoolingVE
conda remove -n ptoolingVE --all
uv venv
source .venv/bin/activate
# do your work
deactivate
```

- To run template in the same path of this repo. We do a test cookiecut of a
Expand All @@ -180,7 +179,7 @@ cd python-tooling
cookiecutter .
cd python-template
git init
python -m pip install -e ".[dev]"
uv pip install -e ".[dev]"
```

- To run cookiecutter using a specific branch of the template:
Expand Down
20 changes: 12 additions & 8 deletions docs/pages/virtual.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ layout: default

# Virtual environments

| Name | Short description | 🚦 |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-: |
| conda-forge [miniforge] | Installs, runs, and updates packages and their dependencies. Uses `conda`, but with community maintained packages from `conda-forge` channel instead of commercially maintained packages. | 🟢 |
| [pipenv] | Automatically creates and manages a virtualenv for your projects. | 🟠 |
| [pyenv] | Lets you easily switch between multiple versions of Python. | 🟠 |
| [virtualenv] | Creates isolated Python environments, and offers more features than venv. | 🟠 |
| [venv] | Creates isolated Python environments. Fewer features than other tools, but very widely used and comes built into Python. | 🟠 |
| [anaconda] | Due to recent [licensing ambiguity][anaconda-problems], we recommend avoiding anaconda and many of the default channels. We recommend installing miniforge and sticking to the `conda-forge` channel. | 🔴 |
| Name | Short description | 🚦 |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-: |
| conda-forge [miniforge] | Installs, runs, and updates packages and their dependencies. Uses `conda`, but with community maintained packages from `conda-forge` channel instead of commercially maintained packages. | 🟢 |
| [uv] | Fast dependecy (and project) management tool. A drop-in replacement for `venv`. This will probably become our 🟢 tool, but for now we play cautious as there are some open bugs and features. If you're comfortable using `venv` syntax we'd recommend this. | 🟠 |
samcunliffe marked this conversation as resolved.
Show resolved Hide resolved
| [pipenv] | Automatically creates and manages a virtualenv for your projects. | 🟠 |
| [pixi] | A fast drop-in replacement for `conda`. | 🟠 |
| [pyenv] | Lets you easily switch between multiple versions of Python. | 🟠 |
| [virtualenv] | Creates isolated Python environments, and offers more features than venv. | 🟠 |
| [venv] | Creates isolated Python environments. Fewer features than other tools, but very widely used and comes built into Python. | 🟠 |
| [anaconda] | Due to recent [licensing ambiguity][anaconda-problems], we recommend avoiding anaconda and many of the default channels. We recommend installing miniforge and sticking to the `conda-forge` channel. | 🔴 |

<!-- links here for a more readable table -->

[miniforge]: https://conda-forge.org/download/
[uv]: https://docs.astral.sh/uv/getting-started/installation/
[pixi]: https://pixi.sh/latest/#installation
[pipenv]: https://pipenv.pypa.io/en/latest/
[pyenv]: https://github.com/pyenv/pyenv
[virtualenv]: https://virtualenv.pypa.io/en/latest/
Expand Down