From 08755e45ed134cbe6e5e6e238b7b5011700080b3 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Tue, 30 Apr 2024 00:38:18 -0500 Subject: [PATCH] ci: Use uv for all pip installs (#2444) * Use 'uv pip' for all calls to 'pip install' and 'pip uninstall' in CI workflows. - c.f. https://github.com/astral-sh/uv/ - Still use pip for Python 3.8 until https://github.com/astral-sh/uv/issues/2062 is resolved. * Apply subtle changes to install commands in .github/workflows/dependencies-head.yml. - 'uv pip install --upgrade' will try to upgrade all dependencies of the target package as well, which for the dependencies-head workflow isn't the goal. So remove the '--upgrade' from calls that also install from the scientific-python-nightly-wheels package index when testing only particular packages. - 'up pip' and 'pip' have different behavior with regards to --extra-index-url, as 'uv pip' gives --extra-index-url priority over --index-url, where 'pip' does not give priority to either. Use this with 'uv pip' to give priority to the scientific-python-nightly-wheels package index. * Add uv to the 'develop' extras. --- .github/workflows/bump-version.yml | 5 +- .github/workflows/ci-windows.yml | 5 +- .github/workflows/ci.yml | 9 +++ .github/workflows/dependencies-head.yml | 64 ++++++++++--------- .github/workflows/docs.yml | 7 +- .../workflows/lower-bound-requirements.yml | 5 +- .github/workflows/notebooks.yml | 5 +- .github/workflows/publish-package.yml | 9 +-- .github/workflows/release_tests.yml | 9 +-- .readthedocs.yaml | 2 +- pyproject.toml | 1 + 11 files changed, 72 insertions(+), 49 deletions(-) diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index 8083fa8a43..cfd178cac4 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -204,8 +204,9 @@ jobs: - name: Install Python dependencies run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip install tbump + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip install --system tbump python -m pip list - name: Setup Git user to push new tag diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index c9f3e8e68b..696fadc5a4 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -29,8 +29,9 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade '.[all,test]' + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip install --system --upgrade '.[all,test]' - name: List installed Python packages run: python -m pip list diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d1c3f3217..82a92e10fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,15 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies + if: matrix.python-version != '3.8' + run: | + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip install --system --upgrade ".[all,test]" + + # c.f. https://github.com/astral-sh/uv/issues/2062 + - name: Install dependencies (Python 3.8) + if: matrix.python-version == '3.8' run: | python -m pip install --upgrade pip setuptools wheel python -m pip install --upgrade ".[all,test]" diff --git a/.github/workflows/dependencies-head.yml b/.github/workflows/dependencies-head.yml index 96f1863760..849cf6fea4 100644 --- a/.github/workflows/dependencies-head.yml +++ b/.github/workflows/dependencies-head.yml @@ -29,8 +29,9 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip --no-cache-dir --quiet install --upgrade --pre ".[all,test]" + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip --no-cache --quiet install --system --upgrade --pre ".[all,test]" python -m pip list - name: List release candidates, alpha, and beta releases @@ -57,14 +58,14 @@ jobs: with: python-version: ${{ matrix.python-version }} - # Use nightly SciPy wheels from Anaconda's PyPI - # c.f. https://twitter.com/ralfgommers/status/1419917265781334025 - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip --no-cache-dir --quiet install --upgrade ".[all,test]" - python -m pip uninstall --yes scipy - python -m pip install --upgrade --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple scipy + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip --no-cache --quiet install --system --upgrade ".[all,test]" + uv pip uninstall --system scipy + # uv wants to upgrade dependencies (numpy) to a dev release too, so don't --upgrade + uv pip install --system --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple scipy python -m pip list - name: Test with pytest @@ -87,11 +88,12 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip --no-cache-dir --quiet install --upgrade ".[all,test]" - python -m pip uninstall --yes iminuit - python -m pip install --upgrade cython - python -m pip install --upgrade git+https://github.com/scikit-hep/iminuit.git + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip --no-cache --quiet install --system --upgrade ".[all,test]" + uv pip uninstall --system iminuit + uv pip install --system --upgrade cython + uv pip install --system --upgrade git+https://github.com/scikit-hep/iminuit.git python -m pip list - name: Test with pytest run: | @@ -113,10 +115,11 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip --no-cache-dir --quiet install --upgrade ".[all,test]" - python -m pip uninstall --yes uproot - python -m pip install --upgrade git+https://github.com/scikit-hep/uproot5.git + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip --no-cache --quiet install --system --upgrade ".[all,test]" + uv pip uninstall --system uproot + uv pip install --system --upgrade git+https://github.com/scikit-hep/uproot5.git python -m pip list - name: Test with pytest run: | @@ -140,16 +143,18 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip --no-cache-dir --quiet install --upgrade ".[all,test]" - python -m pip uninstall --yes matplotlib - # Need to use --extra-index-url as dependencies aren't on scientific-python-nightly-wheels package index. + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip --no-cache --quiet install --system --upgrade ".[all,test]" + uv pip uninstall --system matplotlib + # Need to use --extra-index-url as all dependencies aren't on scientific-python-nightly-wheels package index. # Need to use --pre as dev releases will need priority over stable releases. - python -m pip install \ - --upgrade \ + # Note that uv and pip differ on --extra-index-url priority + # c.f. https://github.com/scientific-python/upload-nightly-action/issues/76 + uv pip install --system \ --pre \ - --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \ - --extra-index-url https://pypi.org/simple/ \ + --index-url https://pypi.org/simple/ \ + --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \ matplotlib - name: List installed Python packages @@ -175,10 +180,11 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip --no-cache-dir --quiet install --upgrade ".[all,test]" - python -m pip uninstall --yes pytest - python -m pip install --upgrade git+https://github.com/pytest-dev/pytest.git + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip --no-cache --quiet install --system --upgrade ".[all,test]" + uv pip uninstall --system pytest + uv pip install --system --upgrade git+https://github.com/pytest-dev/pytest.git python -m pip list - name: Test with pytest run: | diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 155100d0ed..0bb1bc4315 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -28,9 +28,10 @@ jobs: - name: Install Python dependencies run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip --quiet install --upgrade .[docs,test] - python -m pip install yq + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip --quiet install --system --upgrade ".[docs,test]" + uv pip install --system yq python -m pip list - name: Install apt-get dependencies diff --git a/.github/workflows/lower-bound-requirements.yml b/.github/workflows/lower-bound-requirements.yml index 96b5c6a3d8..e9ebdbaa86 100644 --- a/.github/workflows/lower-bound-requirements.yml +++ b/.github/workflows/lower-bound-requirements.yml @@ -26,8 +26,9 @@ jobs: - name: Install dependencies and force lowest bound run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip --no-cache-dir install --constraint tests/constraints.txt ".[all,test]" + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip --no-cache install --system --constraint tests/constraints.txt ".[all,test]" - name: List installed Python packages run: python -m pip list diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index 7ab2b048f8..8278f2abdc 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -28,9 +28,10 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools wheel + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel # FIXME: c.f. https://github.com/scikit-hep/pyhf/issues/2104 - python -m pip install --upgrade ".[all,test]" 'jupyter-client<8.0.0' + uv pip install --system --upgrade ".[all,test]" 'jupyter-client<8.0.0' - name: List installed Python packages run: python -m pip list diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index cd5d4a9ba7..38b455e8b5 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -43,19 +43,20 @@ jobs: - name: Install python-build and twine run: | - python -m pip install --upgrade pip - python -m pip install build twine + python -m pip install uv + uv pip install --system --upgrade pip + uv pip install --system build twine python -m pip list - name: Build a sdist and wheel if: github.event_name != 'schedule' run: | - python -m build . + python -m build --installer uv . - name: Build a sdist and wheel and check for warnings if: github.event_name == 'schedule' run: | - PYTHONWARNINGS=error,default::DeprecationWarning python -m build . + PYTHONWARNINGS=error,default::DeprecationWarning python -m build --installer uv . - name: Verify untagged commits have dev versions if: "!startsWith(github.ref, 'refs/tags/')" diff --git a/.github/workflows/release_tests.yml b/.github/workflows/release_tests.yml index 83b42ef02a..2d3f2e8bd5 100644 --- a/.github/workflows/release_tests.yml +++ b/.github/workflows/release_tests.yml @@ -36,9 +36,10 @@ jobs: - name: Install from PyPI run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip install --pre 'pyhf[backends,xmlio]' - python -m pip install pytest + python -m pip install uv + uv pip install --system --upgrade pip setuptools wheel + uv pip install --system --pre 'pyhf[backends,xmlio]' + uv pip install --system pytest python -m pip list - name: Canary test public API @@ -48,6 +49,6 @@ jobs: # FIXME: c.f. https://github.com/proycon/codemetapy/issues/24 - name: Verify requirements in codemeta.json run: | - python -m pip install jq "codemetapy>=2.3.0" + uv pip install --system jq "codemetapy>=2.3.0" codemetapy --inputtype python --no-extras pyhf > codemeta_generated.json diff <(jq -S .softwareRequirements codemeta.json) <(jq -S .softwareRequirements codemeta_generated.json) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index bd5f4ea9cd..6ff1c4c8b8 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -21,7 +21,7 @@ sphinx: # If using Sphinx, optionally build your docs in additional formats such as PDF and ePub formats: all -# python -m pip install .[docs] +# python -m pip install '.[docs]' python: install: - method: pip diff --git a/pyproject.toml b/pyproject.toml index 7af3b92123..8aad3f9850 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -134,6 +134,7 @@ develop = [ "pre-commit", "nox", "codemetapy>=2.3.0", + "uv>=0.1.39" ] [tool.hatch.version]