From e30982692cb7c071451b40a559f90a2afb235580 Mon Sep 17 00:00:00 2001 From: Sam Cunliffe Date: Tue, 22 Oct 2024 12:22:17 +0100 Subject: [PATCH] Add `uv` and `pixi`. (#464) Resolves #419. Notably not done, is that I've not updated the tutorial.md to use `uv` instead of Anaconda. I'd need to use a Windows machine to test the instructions before I'd feel confident changing the tutorial. --------- Co-authored-by: Patrick J. Roddy Co-authored-by: Matt Graham --- README.md | 46 +++++++++++-------------------------------- docs/pages/virtual.md | 20 +++++++++++-------- 2 files changed, 23 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index b4b9b988..89a7cd98 100644 --- a/README.md +++ b/README.md @@ -75,14 +75,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). ```sh - # 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 ``` 2. Run cookiecutter in the desired directory @@ -114,36 +113,13 @@ and how to use the newly created package with some of the tools included. package_name [python_template]: PACKAGE_NAME ``` - we will get a project folder named `PROJECT_SLUG`, structured like this: - - ```sh - PROJECT_SLUG - ├── ... - ├── README.md - ├── pyproject.toml - ├── src - │ └── PACKAGE_NAME - │ └── __init__.py - └── tests - └── test_dummy.py - ``` - - And the `PROJECT_NAME` will appear in the README.md as the human-readable - name of the project. - - ```sh - cat PROJECT_SLUG/README.md - # PROJECT_NAME - ... - ``` - 5. To work on your project, initialise a Git repository and _install_ it in editable mode. ```sh cd PROJECT_SLUG git init - python -m pip install -e ".[dev]" + uv pip install -e ".[dev]" ``` 6. Build your package @@ -175,10 +151,10 @@ cd python-tooling - To create and remove your virtual environment ```sh - 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 @@ -188,7 +164,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: diff --git a/docs/pages/virtual.md b/docs/pages/virtual.md index 6814a577..a0bd4a08 100644 --- a/docs/pages/virtual.md +++ b/docs/pages/virtual.md @@ -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 dependency (and project) management tool. A drop-in replacement for `venv`. This will probably become our 🟢 tool, but for now we are playing cautious as there are some open bugs and features. If you're comfortable using `venv` syntax we'd recommend this. | 🟠 | +| [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. | 🔴 | [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/