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

docs: update tutorial to use uv #518

Merged
merged 11 commits into from
Feb 14, 2025
Merged

docs: update tutorial to use uv #518

merged 11 commits into from
Feb 14, 2025

Conversation

Saransh-cpp
Copy link
Member

@Saransh-cpp Saransh-cpp commented Feb 11, 2025

Removed conda and introduced uv for everything.
Reviewed the tutorial on a Windows machine.

Closes #477

tutorial.md Outdated Show resolved Hide resolved
tutorial.md Outdated Show resolved Hide resolved
tutorial.md Outdated Show resolved Hide resolved
tutorial.md Outdated Show resolved Hide resolved
tutorial.md Outdated Show resolved Hide resolved
tutorial.md Outdated Show resolved Hide resolved
@Saransh-cpp Saransh-cpp marked this pull request as ready for review February 12, 2025 11:52
@samcunliffe samcunliffe requested review from matt-graham and a team and removed request for samcunliffe February 12, 2025 13:07
Copy link
Member

@samcunliffe samcunliffe left a comment

Choose a reason for hiding this comment

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

Thanks so much for picking this up!

I'm probably not a good reviewer though: I only have access to macOS and Ubuntu.

(Kinda related: should we think about running the tutorial again in the next ARC Festival of ...? I guess that's more of a question to the ether.)

tutorial.md Outdated
conda create -y -n python-tooling -c conda-forge cookiecutter git gh pre-commit tox
uv tool install cookiecutter
uv tool install pre-commit
uv tool install tox
Copy link
Member

Choose a reason for hiding this comment

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

Do they really need tox and pre-commit?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't! Thanks!

@samcunliffe samcunliffe requested a review from a team February 12, 2025 13:11
Copy link
Member

@paddyroddy paddyroddy left a comment

Choose a reason for hiding this comment

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

A few comments

tutorial.md Outdated

and ideally also,
Additionally, [pre-commit](https://pre-commit.com/) and [tox](https://tox.wiki) are required to complete some of the follow on steps for using the package generated with the template, so while they are not strictly needed, you will get more out of the tutorial if you have them installed. For the follow on exercises you will also need an [account set up on GitHub](https://github.com/join) if you don't already have one.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Additionally, [pre-commit](https://pre-commit.com/) and [tox](https://tox.wiki) are required to complete some of the follow on steps for using the package generated with the template, so while they are not strictly needed, you will get more out of the tutorial if you have them installed. For the follow on exercises you will also need an [account set up on GitHub](https://github.com/join) if you don't already have one.
Additionally, [pre-commit](https://pre-commit.com/) and [tox](https://tox.wiki) are required to complete some of the follow along steps for using the package generated with the template, so while they are not strictly needed, you will get more out of the tutorial if you have them installed. For the follow along exercises you will also need an [account set up on GitHub](https://github.com/join) if you don't already have one.

Copy link
Collaborator

@matt-graham matt-graham Feb 12, 2025

Choose a reason for hiding this comment

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

"Follow on" is correct here for the sense of "things following on from" which is what I intended when I originally wrote this in the context of running this as a tutorial at the festival. "Follow along" would I think change the meaning

Copy link
Member

Choose a reason for hiding this comment

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

When reading it, I genuinely wasn't sure what was intended. If it's that use case then I think we should use following.

tutorial.md Outdated Show resolved Hide resolved
tutorial.md Outdated
Comment on lines 31 to 33
uv tool install cookiecutter
uv tool install pre-commit
uv tool install tox
Copy link
Member

Choose a reason for hiding this comment

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

Can these be one line?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not with one uv command - uv tool install --help gives usage as

Usage: uv tool install [OPTIONS] <PACKAGE>

and trying with multiple package names gives an error.

It might be possible to stack multiple commands on a line using separators but I'm not sure if this would be easy to do in a way that will work across operating system / shells and also would probably be less readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need pre-commit and tox so that should solve it.

tutorial.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@matt-graham matt-graham left a comment

Choose a reason for hiding this comment

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

Thanks @Saransh-cpp for the updates, this mostly looks great to me. I've tested setting up uv on Windows and installing the tools as explained in the text and it all worked fine. I've added a few comments - main one is that I think the section on installing dependencies may need reworking a bit to make it clearer that Git and GitHub CLI will need to be installed separately, as previously conda was also being used to install these.

tutorial.md Outdated

and ideally also,
Additionally, [pre-commit](https://pre-commit.com/) and [tox](https://tox.wiki) are required to complete some of the follow on steps for using the package generated with the template, so while they are not strictly needed, you will get more out of the tutorial if you have them installed. For the follow on exercises you will also need an [account set up on GitHub](https://github.com/join) if you don't already have one.
Copy link
Collaborator

@matt-graham matt-graham Feb 12, 2025

Choose a reason for hiding this comment

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

"Follow on" is correct here for the sense of "things following on from" which is what I intended when I originally wrote this in the context of running this as a tutorial at the festival. "Follow along" would I think change the meaning

tutorial.md Outdated
Comment on lines 31 to 33
uv tool install cookiecutter
uv tool install pre-commit
uv tool install tox
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not with one uv command - uv tool install --help gives usage as

Usage: uv tool install [OPTIONS] <PACKAGE>

and trying with multiple package names gives an error.

It might be possible to stack multiple commands on a line using separators but I'm not sure if this would be easy to do in a way that will work across operating system / shells and also would probably be less readable.

tutorial.md Outdated Show resolved Hide resolved
tutorial.md Outdated Show resolved Hide resolved
Saransh-cpp and others added 3 commits February 12, 2025 14:36
Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>
tutorial.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@matt-graham matt-graham left a comment

Choose a reason for hiding this comment

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

Thanks @Saransh-cpp for the updates, all looks good to me 😍!

Copy link
Member

@samcunliffe samcunliffe left a comment

Choose a reason for hiding this comment

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

Aaah down on 289 we're telling them to use tox. So perhaps we should tell them to install tox around there.

uv tool install tox

... ? Ditto pre-commit down at 312.
(Sorry @Saransh-cpp I gave you a wrong comment 🙃 )

But perhaps installing them should come later around the relevant section of the tutorial?


An alternative to Conda is the [`venv` module](https://docs.python.org/3/library/venv.html) built-in to the Python standard library. This has the advantage of being available in any Python (3.3+) environment, but unlike Conda will not by itself allow you to use a different Python version from the system level install. In contrast to Conda which by default creates all environments in a shared user-level directory (if using Miniconda, by default in a directory `miniconda3/envs` in your user or home directory), the `venv` module requires being passed a path in which to create the directory containing the files associated with the virtual environment. A common pattern is to store the virtual environment files in a directory `.venv` within the root directory of the project repository. This can be achieved by running
Alternatively, you can use the [`venv` module](https://docs.python.org/3/library/venv.html), which is slower and has fewer features, when compared to `uv`, but is built-in to the Python standard library. `venv` has the advantage of being available in any Python (3.3+) environment, but unlike `uv` will not by itself allow you to use a different Python version from the system level install. A common pattern is to store the virtual environment files in a directory `.venv` within the root directory of the project repository. This can be achieved by running
Copy link
Member

Choose a reason for hiding this comment

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

I just ran through these for sanity as a fresh user in macOS.

The only stumbling point is from here on, it's not clear that we should preferentially be using UV.

That Is, if I skip or skim read the "Alternatively..." part and then try to python -m pip install X I will get:

(python-template) teaching@scafell python-template % python -m pip install numpy
/Users/teaching/python-template/.venv/bin/python: No module named pip

Obviously because I didn't install pip in my venv. But I should be running uv pip install all the time.

Should we cull some of the information that follows? Or put it into a <details></details> block to hide it away?

I think we want to end the </details> block around

263 Once you have created and activated a virtual environment for the project, ...

Because the uv users (who will be in the majority?) will also need to install their own package into the uv venv.

@Saransh-cpp
Copy link
Member Author

Saransh-cpp commented Feb 13, 2025

Aaah also down on 289 we're ...

Line 266 teaches them to install the dev and test dependencies for the package, and tox + pre-commit are bundled within those groups (which should actually use uv, fixing this too) 😉

I think this is getting shadowed by the whole venv stuff, which yes, should be in a </details> block. I'll update it. Thanks!

@samcunliffe
Copy link
Member

Line 266 teaches them to install the dev and test dependencies for the package, and tox + pre-commit are bundled within those groups (which should actually use uv, fixing this too) 😉

Oh, great!

Copy link
Member

@samcunliffe samcunliffe left a comment

Choose a reason for hiding this comment

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

Perfect. Cheers!

@Saransh-cpp Saransh-cpp merged commit e5d3bf0 into main Feb 14, 2025
13 checks passed
@Saransh-cpp Saransh-cpp deleted the saransh/update-tutorial branch February 14, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the tutorial to not use conda (switch to uv?)
4 participants