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: Utilize uv lockfile for reproducible test environments #6640

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

Conversation

danielhollas
Copy link
Collaborator

@danielhollas danielhollas commented Nov 25, 2024

This PR removes the requirement files in requirements/ folder and replaces them with a single universal lockfile uv.lock. "universal" in this case means that it contains resolved package versions for all supported python versions and operating systems. More on the uv lockfiles can be found in their docs: https://docs.astral.sh/uv/concepts/projects/layout/#the-lockfile

When modifying the dependencies in pyproject.toml, the lockfile needs to be updated by running

uv lock

(Note that using e.g. uv add, uv remove or uv sync updates the lockfile automatically)

This relative simplicity compared to the previous custom solution allows for much easier development and I could delete a lot of custom YAML in CI. To check whether the lockfile is up to date, one can simply run

uv lock --locked

This command is run automatically as a pre-commit hook whenever pyproject.toml is changed.

Note

Developers don't necessarily need to use the lockfile locally, nor are they required to have uv installed, unless they need to modify dependencies in pyproject.toml

@danielhollas danielhollas changed the title WIP: See if we can use uv lockfile See if we can use uv lockfile Nov 28, 2024
In this implementation, the hook will only check
whether the lockfile is compatible with pyproject.toml,
it will not try to automatically update it, since that
should be decided by the developer.
- name: Install dependencies from uv lock
# NOTE: We're also asserting that the lockfile is up to date
if: ${{ inputs.from-lock == 'true' }}
run: uv sync --locked --extra pre-commit
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NOTE: By default we're installing with pre-commit optional dependencies (extras), which transitively includes other extras, see pyproject.toml I think this is the best solution to make things work for now.

@@ -2,9 +2,7 @@
# currently active dependency manager (DM) to trigger an automatic review
# request from the DM upon changes. Please see AEP-002 for details:
# https://github.com/aiidateam/AEP/tree/master/002_dependency_management
setup.* @aiidateam/dependency-manager
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like @aiidateam/dependency-manager doesn't exist? Should I assign @agoscinski explicitly?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add both me and @agoscinski, or if you also want to maintain this ;) I think after this PR, the dependency management can be future simplified.

utils/dependency_management.py @aiidateam/dependency-manager
.github/workflows/dm.yml @aiidateam/dependency-manager
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file does not exist.

@danielhollas danielhollas marked this pull request as ready for review November 28, 2024 20:42
@danielhollas danielhollas changed the title See if we can use uv lockfile CI: Utilize uv lockfile for reproducible test environments Nov 28, 2024
@danielhollas
Copy link
Collaborator Author

@agoscinski @unkcpz I think this PR is mostly ready now, let me know what you think!

The only thing missing is developer documentation: I would suggest moving the Dependency Management Wiki article to the repo in a separate PR.

Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.94%. Comparing base (ef60b66) to head (10cd62a).
Report is 146 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6640      +/-   ##
==========================================
+ Coverage   77.51%   77.94%   +0.44%     
==========================================
  Files         560      563       +3     
  Lines       41444    41659     +215     
==========================================
+ Hits        32120    32466     +346     
+ Misses       9324     9193     -131     

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

@unkcpz
Copy link
Member

unkcpz commented Nov 29, 2024

The only thing missing is developer documentation: I would suggest moving the Dependency Management Wiki article to the repo in a separate PR.

Sure, go ahead with a separate PR, thanks!

@khsrali
Copy link
Contributor

khsrali commented Nov 29, 2024

@danielhollas nice, thanks a lot!
suppose I have an entry in my pyproject.toml as such:
'plumpy@git+https://github.com/khsrali/plumpy.git@allow-async-upload-download#egg=plumpy',

would this be understood and accepted by uv lock?

@danielhollas
Copy link
Collaborator Author

@khsrali I tried it and it works without a problem. :-)
btw: I don't think you need the #egg=plumpy part at the and of the URL, and uv strips it anyways.

Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

unless they need to modify dependencies in pyproject.toml

I don't understand how this will work. I think if we run uv lock from different machine, the lock file is generated using the environment where the command is run. Which means two people will have two different lock file generated. Is this leading to large number of lines change?

@@ -96,15 +64,15 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Setup environment
run: .github/workflows/setup.sh
run: source .venv/bin/activate && .github/workflows/setup.sh
Copy link
Member

Choose a reason for hiding this comment

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

Where is this .venv created from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is created by uv sync automatically in the install-aiida-core action above.

@danielhollas
Copy link
Collaborator Author

I think if we run uv lock from different machine, the lock file is generated using the environment where the command is run.

uv should generate a universal lock file independent of your current python version or OS. At least that is my understanding, would be good if you can verify. I have generated the lock here on Linux and Python 3.12

Also you can try using the lock file I generated by running uv sync. It should work regardless of your python 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.

3 participants