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

ci: Use uv for all pip installs #2444

Merged
merged 20 commits into from
Apr 30, 2024
Merged

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Feb 16, 2024

Description

Use uv to try to speed up the installs of all the Python dependencies.

Fall back to using pip for Python 3.8 until astral-sh/uv#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.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* 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.

@matthewfeickert matthewfeickert added CI CI systems, GitHub Actions need-to-backport tmp label until can be backported to patch release branch labels Feb 16, 2024
@matthewfeickert matthewfeickert self-assigned this Feb 16, 2024
@matthewfeickert
Copy link
Member Author

matthewfeickert commented Feb 16, 2024

Need astral-sh/uv#1526 or an alternative for this to work first.

Edit: Can do this for the time being:

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}

    - name: Set the VIRTUAL_ENV variable for uv to work
      run: |
        echo "VIRTUAL_ENV=${Python_ROOT_DIR}" >> $GITHUB_ENV

    - name: Install dependencies
      run: |
        python -m pip install uv
        python -m uv pip install --upgrade <stuff>

which comes from astral-sh/uv#1386 (comment).

@matthewfeickert
Copy link
Member Author

Also needs astral-sh/uv#1531 so will have to wait for the next release of uv (if that PR goes in).

@matthewfeickert
Copy link
Member Author

Given astral-sh/uv#1531 (comment) we also need astral-sh/uv#313 to go in.

@matthewfeickert
Copy link
Member Author

matthewfeickert commented Feb 28, 2024

Okay with astral-sh/uv#1526 in and using the

install "pyhf[extras] @ ."

pattern over

install ".[extras]"

pattern I think this should be good.

edit: No, uv pip is resolving dependencies for tensorflow different than pip does and this breaks.

@matthewfeickert
Copy link
Member Author

Reported failure in astral-sh/uv#2062

@matthewfeickert
Copy link
Member Author

Also blocked by astral-sh/uv#2685

@matthewfeickert matthewfeickert force-pushed the ci/use-uv-to-speed-up-installs branch 2 times, most recently from d5d84c6 to 01f001b Compare April 2, 2024 07:29
@matthewfeickert
Copy link
Member Author

So this is really blocked by papermill given nteract/papermill#789 is in and so just waiting for a papermill v2.5.1 or v2.6.0 release.

@matthewfeickert
Copy link
Member Author

With the release of papermill v2.6.0 (nteract/papermill#785 (comment)) and relaxing to

...
    "papermill>=2.5.0",
    "scrapbook>=0.5.0",
...

astral-sh/uv#2685 is sidestepped, but the issue with TensorFlow dependency resolution in astral-sh/uv#2062 is still blocking.

Copy link

codecov bot commented Apr 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.21%. Comparing base (682ce76) to head (854906d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2444   +/-   ##
=======================================
  Coverage   98.21%   98.21%           
=======================================
  Files          69       69           
  Lines        4543     4543           
  Branches      804      804           
=======================================
  Hits         4462     4462           
  Misses         48       48           
  Partials       33       33           
Flag Coverage Δ
contrib 97.79% <ø> (ø)
doctest 98.08% <ø> (ø)
unittests-3.10 96.23% <ø> (ø)
unittests-3.11 96.23% <ø> (ø)
unittests-3.12 96.23% <ø> (ø)
unittests-3.8 96.25% <ø> (ø)
unittests-3.9 96.27% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pyproject.toml Outdated Show resolved Hide resolved
matthewfeickert added a commit that referenced this pull request Apr 27, 2024
* Loosen the install requirements for papermill, scrapbook, and
  sphinxcontrib-bibtex to use lower bounds instead of
  compatible release constraints.
* Required for PR #2444
Comment on lines +47 to +55
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'
Copy link
Member Author

Choose a reason for hiding this comment

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

A bit of a hack, but until astral-sh/uv#2062 gets resolves, we might as well speed up everything else.

.github/workflows/dependencies-head.yml Outdated Show resolved Hide resolved
@matthewfeickert matthewfeickert marked this pull request as ready for review April 27, 2024 18:58
# Need to use --extra-index-url as 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 \
uv pip install --system \
Copy link
Member Author

Choose a reason for hiding this comment

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

Double check this as pip and uv handle --extra-index-url differently. c.f. scientific-python/upload-nightly-action#76

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this needed to get flipped to

        uv pip install --system \
          --pre \
          --index-url https://pypi.org/simple/ \
          --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
          matplotlib

as uv give priority to --extra-index-url.

$ pip list
Package         Version
--------------- -------------------------
contourpy       1.3.0.dev1
cycler          0.12.1
fonttools       4.51.0
kiwisolver      1.4.5
matplotlib      3.10.0.dev114+g4cbef2d4c0
numpy           2.1.0.dev0
packaging       24.0
pillow          10.3.0
pip             24.0
pyparsing       3.1.2
python-dateutil 2.9.0.post0
setuptools      69.5.1
six             1.16.0
uv              0.1.39
wheel           0.43.0

* uv pip install --upgrade is going to try to upgrade numpy along with
  scipy, so to avoid this, don't use --upgrade when installing scipy
  from the nightly wheel index.
Comment on lines +67 to +68
# 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
Copy link
Member Author

Choose a reason for hiding this comment

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

This was previously forcing an upgrade of numpy with uv as well, but just want to test scipy which should work with numpy v1 or v2, and trying to test numpy v2 will break jax at the moment.

@matthewfeickert
Copy link
Member Author

Okay, I think this is finally working as expected across all workflows now.

@matthewfeickert
Copy link
Member Author

matthewfeickert commented Apr 27, 2024

Some examples of install time drops:

OS Python pip uv pip
Ubuntu 3.12 2m 57 s 38 s
macOS (Intel) 3.12 2m 51 s 50 s
macOS (Apple silicon) 3.12 1m 6 s 16 s

🚀

@matthewfeickert
Copy link
Member Author

I'm going to approve and merge this myself. As always, PRs approved by a single core dev can be reverted as needed by the rest of the dev team.

@matthewfeickert matthewfeickert merged commit 08755e4 into main Apr 30, 2024
26 checks passed
@matthewfeickert matthewfeickert deleted the ci/use-uv-to-speed-up-installs branch April 30, 2024 05:38
@matthewfeickert matthewfeickert removed the need-to-backport tmp label until can be backported to patch release branch label May 30, 2024
matthewfeickert added a commit that referenced this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI CI systems, GitHub Actions
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant