Thanks to visit codestin.com
Credit goes to github.com

Skip to content

CI: Use 'uv tool run' for build and twine #101

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

Merged
merged 1 commit into from
Sep 30, 2024
Merged

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Sep 30, 2024

  • Use the astral-sh/setup-uv GitHub Action to setup the latest uv.
    • This GitHub Action can be left unpinned as it should be updated regularly.
  • Use uv tool run --from build pyproject-build to run build as the PyPI project name is build but the executable it provides is named pyproject-build.
  • Use uv tool run twine to run twine.

c.f. https://docs.astral.sh/uv/reference/cli/#uv-tool-run

Time comparison between python -m build, python -m build --installer=uv, and uv tool run --from build pyproject-build:

$ docker run --rm -ti python:3.12 bash
root@cfbfbb22a859:/# curl -LsSf https://astral.sh/uv/install.sh | sh
downloading uv 0.4.17 x86_64-unknown-linux-gnu
installing to /root/.cargo/bin
  uv
  uvx
everything's installed!

To add $HOME/.cargo/bin to your PATH, either restart your shell or run:

    source $HOME/.cargo/env (sh, bash, zsh)
    source $HOME/.cargo/env.fish (fish)
root@cfbfbb22a859:/# . /root/.cargo/env
root@cfbfbb22a859:/# uv venv && . .venv/bin/activate
Using CPython 3.12.6 interpreter at: /usr/local/bin/python
Creating virtual environment at: .venv
(.venv) root@cfbfbb22a859:/# git clone https://github.com/scientific-python/upload-nightly-action.git && cd upload-nightly-action
Cloning into 'upload-nightly-action'...
remote: Enumerating objects: 244, done.
remote: Counting objects: 100% (99/99), done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 244 (delta 67), reused 53 (delta 35), pack-reused 145 (from 1)
Receiving objects: 100% (244/244), 107.50 KiB | 1.85 MiB/s, done.
Resolving deltas: 100% (110/110), done.
(.venv) root@cfbfbb22a859:/upload-nightly-action# uv pip install build
Resolved 3 packages in 277ms
Prepared 3 packages in 93ms
Installed 3 packages in 6ms
 + build==1.2.2
 + packaging==24.1
 + pyproject-hooks==1.2.0
(.venv) root@cfbfbb22a859:/upload-nightly-action# rm -rf dist && time python -m build --outdir ./dist ./tests/test_package
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - hatchling
* Getting build dependencies for sdist...
* Building sdist...
* Building wheel from sdist
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - hatchling
* Getting build dependencies for wheel...
* Building wheel...
Successfully built test_package-0.0.1.tar.gz and test_package-0.0.1-py3-none-any.whl

real	0m6.277s
user	0m5.020s
sys	0m0.444s
(.venv) root@cfbfbb22a859:/upload-nightly-action# rm -rf dist && time python -m build --installer=uv --outdir ./dist ./tests/test_package
* Creating isolated environment: venv+uv...
* Using external uv from /root/.cargo/bin/uv
* Installing packages in isolated environment:
  - hatchling
* Getting build dependencies for sdist...
* Building sdist...
* Building wheel from sdist
* Creating isolated environment: venv+uv...
* Using external uv from /root/.cargo/bin/uv
* Installing packages in isolated environment:
  - hatchling
* Getting build dependencies for wheel...
* Building wheel...
Successfully built test_package-0.0.1.tar.gz and test_package-0.0.1-py3-none-any.whl

real	0m1.012s
user	0m0.553s
sys	0m0.152s
(.venv) root@cfbfbb22a859:/upload-nightly-action# deactivate 
root@cfbfbb22a859:/upload-nightly-action# rm -rf .venv
root@cfbfbb22a859:/upload-nightly-action# rm -rf dist && time uv tool run --from build pyproject-build --installer=uv --outdir dist ./tests/test_package
* Creating isolated environment: venv+uv...
* Using external uv from /root/.cargo/bin/uv
* Installing packages in isolated environment:
  - hatchling
* Getting build dependencies for sdist...
* Building sdist...
* Building wheel from sdist
* Creating isolated environment: venv+uv...
* Using external uv from /root/.cargo/bin/uv
* Installing packages in isolated environment:
  - hatchling
* Getting build dependencies for wheel...
* Building wheel...
Successfully built test_package-0.0.1.tar.gz and test_package-0.0.1-py3-none-any.whl

real	0m0.626s
user	0m0.499s
sys	0m0.145s
root@cfbfbb22a859:/upload-nightly-action#

* Use the astral-sh/setup-uv GitHub Action to setup the latest uv.
   - This GitHub Action can be left unpinned as it should be updated
     regularly.
* Use 'uv tool run --from build pyproject-build' to run build as the PyPI
  project name is 'build' but the executable it provides is named
  'pyproject-build'.
* Use 'uv tool run twine' to run twine.
@matthewfeickert matthewfeickert requested a review from a team September 30, 2024 21:04
@matthewfeickert matthewfeickert self-assigned this Sep 30, 2024
Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Happy to move to UV personally 👍


- name: Build v0.0.1 wheel and sdist
run: |
python -m build --outdir ./dist _action_path/tests/test_package
uv tool run --from build pyproject-build --installer=uv --outdir ./dist _action_path/tests/test_package
Copy link
Member Author

Choose a reason for hiding this comment

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

I do know that uvx exists and is an alias for uv tool run, but I decided to keep it more explicit for now.

Copy link
Member

Choose a reason for hiding this comment

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

yep also not sure about their plans in the future so fine with that 👍

@matthewfeickert matthewfeickert merged commit 459d161 into main Sep 30, 2024
4 checks passed
@matthewfeickert matthewfeickert deleted the ci/use-uv branch September 30, 2024 21:22
python -m pip install build twine
python -m pip list
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
Copy link
Member

Choose a reason for hiding this comment

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

We pin everything to hashes in here, please do so with this one, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants