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

♻️ refactor!: replace PDM, pipx, pyenv and more with uv #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fepegar
Copy link
Owner

@fepegar fepegar commented Dec 22, 2024

Replace multiple tools with uv for a more streamlined experience.

@fepegar fepegar changed the title ♻️ refactor!: replace PDM, pipx, pyenv and more with uv >>> ⏰ 2h ♻️ refactor!: replace PDM, pipx, pyenv and more with uv Dec 23, 2024
Copy link

@jzazo jzazo left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! We can have the discussion here or in source repo :)

@@ -11,7 +11,6 @@ ENV HOROVOD_GPU_ALLREDUCE=NCCL

RUN apt-get -qq update \
&& apt-get -qq install --no-install-recommends \
python3-minimal python3-dev python3-pip python3-venv python-is-python3 pipx \
Copy link

Choose a reason for hiding this comment

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

why remove these?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Are they needed? uv should be able to manage Python, venvs and tools installation (pipx -> uv tool install).

sed -i 's/plugins=(git)/plugins=(git pdm)/' ~/.zshrc
pdm config virtualenvs.in-project true
echo "UV INSTALL"
curl -LsSf https://astral.sh/uv/install.sh | sh
Copy link

Choose a reason for hiding this comment

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

Running unsigned scripts is insecure should not be used in prod environments, why not install with pipx? That's why I install python in the base image and pipx...

Copy link
Owner Author

Choose a reason for hiding this comment

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

That URL redirects to https://github.com/astral-sh/uv/releases/latest/download/uv-installer.sh, which simply downloads the binaries (uv and uvx) from the latest release, for the target platform. We could do that ourselves, without the script.

Another option is simply

COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

@@ -12,8 +12,7 @@ git config --global alias.mt mergetool
git config --global alias.pl pull --rebase

echo "INSTALLING COMMITIZEN"
pipx install commitizen
pipx inject commitizen cz-conventional-gitmoji
uv tool install --with cz-conventional-gitmoji commitizen
Copy link

Choose a reason for hiding this comment

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

needs changing if we install with pipx. Let's agree first.

@@ -22,5 +21,4 @@ if [ ! -d .git ]; then
echo "Initializing Git..."
git init
fi
pipx install pre-commit
pre-commit install --install-hooks
uvx --with pre-commit-uv -- pre-commit install --install-hooks
Copy link

Choose a reason for hiding this comment

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

I am lazy, can you explain this?

Copy link
Owner Author

Choose a reason for hiding this comment

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

See #1 (comment).

We're saying "install x and also pre-commit-uv in a temporary environment, and run x args, where x is pre-commit and args is install --install-hooks.

Comment on lines +13 to +14
- name: Install uv
uses: astral-sh/setup-uv@v5
Copy link

Choose a reason for hiding this comment

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

not a fan of untrusted github actions, can you use these in enterprise github?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm not sure what you mean. Is there a list of trusted actions? I think it would work.


The only required dependency is [uv](https://docs.astral.sh/uv/getting-started/installation/).
Copy link

Choose a reason for hiding this comment

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

I do like that uv installs python if required, this is nice.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes! Also they've just taken over python-build-standalone themselves.

Copy link
Owner Author

Choose a reason for hiding this comment

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

(which is where uv downloads Python from)

@@ -1,27 +1,27 @@
#!/usr/bin/env bash

echo "RUNNING PRE-COMMIT HOOKS"
pre-commit run --all
uvx -- pre-commit run --all
Copy link

Choose a reason for hiding this comment

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

what's the difference between uvx and uv run?

Copy link
Owner Author

@fepegar fepegar Dec 24, 2024

Choose a reason for hiding this comment

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

I think uv run thing is a bit like doing this:

uv python install  # ensure Python is installed (latest specified in pyproject.toml, or the one pinned in .python-version
uv lock  # ensure the lock file is in sync with pyproject.toml
uv sync  # ensure the venv exists and is in sync with the lock file
source .venv/bin/activate
thing
deactivate

uvx is the same as uv tool run. uv tool run thing would be something like:

uv venv /tmp/some_dir/.venv    # uses the latest installed Python
cd /tmp/some_dir
uv add thing
source .venv/bin/activate
thing
deactivate

Not exactly what goes on, but hopefully that helps. In this case, thing is the name of the entry script and the package. Otherwise you'd do something like uv tool run --from my_package my_command. The dashes -- are not needed, by I think they make things more readable sometimes.

If a tool is installed (with uv tool install), uv tool run (or uvx) will use the installed version.

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.

2 participants