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 installer #6363

Merged
merged 13 commits into from
Apr 22, 2024
Merged

CI: Use uv installer #6363

merged 13 commits into from
Apr 22, 2024

Conversation

danielhollas
Copy link
Collaborator

uv is the new cool kid in the town of Python packaging, from the creators of ruff. It currently serves as a (much) faster drop-in replacement for pip.

We've been using it for a couple of repos in AiiDAlab and it works great. For aiida-core, it cuts installation time from ~1m30s to ~10s, so it seems worthwhile.

So far I've only touched jobs in ci-code.yml. If desired, I can make similar changes to other workflows that would benefit (e.g. pre-commit)

@danielhollas danielhollas requested a review from sphuber April 21, 2024 17:55
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Thanks a lot @danielhollas I have been following the uv development closely and it is looking great indeed. Especially since our installation is quite straightforward we shouldn't expect any problems.

So far I've only touched jobs in ci-code.yml. If desired, I can make similar changes to other workflows that would benefit (e.g. pre-commit)

Since the changes pass and there is a significant speed-up, yes please, let's do all other workflows as well 👍

@danielhollas danielhollas force-pushed the uv branch 2 times, most recently from 39c98fa to e895983 Compare April 21, 2024 21:58
@danielhollas
Copy link
Collaborator Author

danielhollas commented Apr 21, 2024

Hmm, this check failure is strange and seems unrelated to this PR?

https://github.com/aiidateam/aiida-core/actions/runs/8775766327/job/24078477856

(detected asyncio module being loaded in verdi during tab completion? But only for version 3.9, not 3.12?)

EDIT: I also don't understand the pre-commit job failure? Maybe uv flake?
https://github.com/aiidateam/aiida-core/actions/runs/8775766331/job/24078477013?pr=6363
(but is the pre-commit workflow even needed given that we use pre-commit.ci app anyway?

run: |
pip install -r requirements/requirements-py-${{ matrix.python-version }}.txt
pip freeze
pip install --dry-run --ignore-installed -r requirements/requirements-py-${{ matrix.python-version }}.txt
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I kept pip here so we have at least some tests that use it.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
@sphuber
Copy link
Contributor

sphuber commented Apr 22, 2024

EDIT: I also don't understand the pre-commit job failure? Maybe uv flake?
https://github.com/aiidateam/aiida-core/actions/runs/8775766331/job/24078477013?pr=6363

It seems to be a straigh-up error in uv indeed. That would be worrying. Not really interested in adding a flaky installer. A quick search comes up with this: astral-sh/uv#2941
Seems it was a real bug in 0.1.30, but should have been fixed in the version you are currently using.

Finally, we should also see if we can use a cache for downlaoded packages. This is currently done through the setup-python action, but not sure if they support uv already.

@danielhollas danielhollas force-pushed the uv branch 3 times, most recently from 879cef5 to 4f1a8e4 Compare April 22, 2024 10:54
@sphuber
Copy link
Contributor

sphuber commented Apr 22, 2024

Things are going well I see 😂

@danielhollas
Copy link
Collaborator Author

danielhollas commented Apr 22, 2024

Things are going well I see 😂

😭 I hate GHA more and more...

Anyway, I think this is now ready. 🎉

It seems to be a straigh-up error in uv indeed. That would be worrying. Not really interested in adding a flaky installer. A quick search comes up with this: astral-sh/uv#2941

Turns out this was largely my error, I was trying to install pre-commit extras with --no-deps, you can easily reproduce this by

uv venv
uv pip install  --no-deps -e .[pre-commit]

pip in this case simply ignores the extras (which tbh is a fishy behaviour), I'll open an issue to uv to catch this. Opened an issue: astral-sh/uv#3184

Finally, we should also see if we can use a cache for downlaoded packages. This is currently done through the setup-python action, but not sure if they support uv already.

Given uv's speed I don't think its worth it, also uv's cache is not really space efficient (uncompressed) so it takes non-trivial amount of time to fetch. See some discussions on this:
astral-sh/uv#2231 (comment)

This comment indicates that having cache might be worthwhile if uv needs to do expensive source dist builds, not sure if that's the case here. astral-sh/uv#1386 (comment)

Anyway, I'd leave that for a follow-up PR. 😛

@danielhollas danielhollas requested a review from sphuber April 22, 2024 12:56
Comment on lines +29 to +30
extras: '[pre-commit]'
from-requirements: 'true'
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize that this was already the case, but why are we installing from requirements and then normally with the extra? I presume because we cannot specify the extra when installing from requirements. But then why not simply get rid of the requirements install. I don't think we need it for the pre-commit step

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought so as well, but if I don't install from requirements first the pre-commit will actually fail, I think because it is missing pytest library. I'll open a separate issue for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opened #6366

Comment on lines -64 to -65
pip install -r requirements/requirements-py-3.10.txt
pip install --no-deps -e .
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this now, I am not sure why it is first installing from requirements and then doing --no-deps -e .. Do you know why? Does installing with -r somehow not install the package itself? That cannot be, can it? Or is it because that doesn't support the -e flag? But then again, why would we need a linked install for CI?

Just asking to understand if it makes sense that we get rid of this double install approach.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does installing with -r somehow not install the package itself? That cannot be, can it?

I just tested that aiida-core indeed does not get installed, which actually makes sense since it is not defined inside the requirements file. So I think the current approach makes sense.

Or is it because that doesn't support the -e flag? But then again, why would we need a linked install for CI?

I also don't think editable install is needed. I am happy to change it, but I think it's better to be done as separate PR, so that here we only focus on uv and don't do any functional changes.

.github/actions/install-aiida-core/action.yml Outdated Show resolved Hide resolved
.github/actions/install-aiida-core/action.yml Outdated Show resolved Hide resolved
Comment on lines +9 to +18
extras:
description: aiida-core extras (including brackets)
default: ''
required: false
# NOTE: Hard-learned lesson: we cannot use type=boolean here, apparently :-(
# https://stackoverflow.com/a/76294014
from-requirements:
description: Install aiida-core dependencies from pre-compiled requirements.txt file
default: 'true'
required: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these not mutually exclusive? If extras are specified, the install cannot be done from a requirements file? If so, we can just get rid of the from-requirements variable right and just check whether extras is not an empty string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not necessarily, see the case of pre-commit above. But we might want to simplify that in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opened #6366

(Don't tell @mbercx)

Co-authored-by: Sebastiaan Huber <[email protected]>
Comment on lines +46 to +48
# If this syntax looks weird to you, dear reader, know that this is
# GHA's way to do ternary operator. :-/
# https://docs.github.com/en/actions/learn-github-actions/expressions#example
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiosity, what part do you find weird? To me the structure (condition) && true || false seems quite logical coming from bash. Then there is the ${{ }} as GHA's outer expression wrapper.

@sphuber sphuber self-requested a review April 22, 2024 18:59
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Thanks a lot @danielhollas Centralizing the install in one action cleans things up nicely as well

@sphuber sphuber merged commit 73a734a into aiidateam:main Apr 22, 2024
20 checks passed
@danielhollas danielhollas deleted the uv branch April 22, 2024 20:20
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.

3 participants