Skip to content

Conversation

fabcor-maxiv
Copy link
Contributor

This will let the pre-commit hooks ensure that Poetry's lockfile is kept up-to-date and that it is exported to a pip requirements.txt file.

GitHub: fix #1268

@fabcor-maxiv
Copy link
Contributor Author

I feel like maybe this should be discussed, so I keep it as draft for a bit. In particular it feels like attempts at using some of those Poetry pre-commit hooks have been made in the past, and I can assume it was not entirely successful, so maybe there is some background info that I am missing.

@marcus-oscarsson
Copy link
Member

Hm, yes. I suspect so as well

@fabcor-maxiv
Copy link
Contributor Author

I am wondering how we could move this forward...

What could be an issue here?

Updates to requirements.txt would happen only when poetry.lock changes. Typically changes to poetry.lock happen only when Dependabot does it, or when we do changes to the dependency list in pyproject.toml. So all in all, it feels like we can keep the Dependabot part under control, and on the other hand changing the dependency list in pyproject.toml is relatively rare that one of the more experienced contributors can easily intervene if things get messy. If I checked everything correctly, the pre-commit hooks should do most of the work and will inform correctly when files are not in sync.

Maybe I could document this a bit...

@fabcor-maxiv
Copy link
Contributor Author

@oldfielj-ansto If I am not mistaken, you were the one to introduce pre-commit hooks and Poetry. Maybe you have some opinion on this...

rev: 1.8.3
hooks:
- id: poetry-check
args:
Copy link
Member

Choose a reason for hiding this comment

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

What does this hook do, does it check if the lock file is up to date or does it also update and commit it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can tell it runs poetry check --lock. The documentation is not super clear on what this does, I assume there is an issue in the documentation, because the behavior does not match the documentation.

Anyway what actually happens in this hook is that it checks that:

  1. the content of pyproject.toml is valid (from the point of view of Poetry)
  2. there is a poetry.lock file
  3. the content of poetry.lock is in sync with pyproject.toml

The next hook runs poetry lock --no-update, which does syncs the lock file. The hook will fail if the hook changes the file, this is important to have on the CI side, for the case when someone commits without running the hooks locally.

Then the third hook does the export to requirements.txt. The hook will fail if the hook changes the file, this is important to have on the CI side, for the case when someone commits without running the hooks locally.

There is some redundancy between the first two steps, and I assume we can simplify over time, depending on how things go.

@marcus-oscarsson
Copy link
Member

It would probably nice with some documentation :)

@fabcor-maxiv fabcor-maxiv force-pushed the poetry-export-pip-requirements-txt branch 2 times, most recently from 09cd803 to da74f7f Compare July 4, 2024 09:45
@fabcor-maxiv
Copy link
Contributor Author

It would probably nice with some documentation :)

I added a bit of documentation. Mostly in comments in .pre-commit-config.yaml, let me know if you think I should add more documentation and/or move it somewhere else.

@fabcor-maxiv fabcor-maxiv force-pushed the poetry-export-pip-requirements-txt branch from da74f7f to 4686d7a Compare July 4, 2024 12:42
@marcus-oscarsson marcus-oscarsson force-pushed the poetry-export-pip-requirements-txt branch from 4686d7a to 935c2d5 Compare July 8, 2024 06:40
@fabcor-maxiv fabcor-maxiv marked this pull request as ready for review July 8, 2024 07:59
@fabcor-maxiv fabcor-maxiv force-pushed the poetry-export-pip-requirements-txt branch from 935c2d5 to bb49ef0 Compare July 8, 2024 08:03
@marcus-oscarsson marcus-oscarsson force-pushed the poetry-export-pip-requirements-txt branch from bb49ef0 to 785cf90 Compare July 8, 2024 15:37
@marcus-oscarsson
Copy link
Member

How come that the status checks are pending for such a long time ?

@fabcor-maxiv
Copy link
Contributor Author

fabcor-maxiv commented Jul 8, 2024

How come that the status checks are pending for such a long time ?

Merging #1289 broke the GitHub Actions workflows completely. See mxcube/mxcubecore#960

@marcus-oscarsson marcus-oscarsson force-pushed the poetry-export-pip-requirements-txt branch from 785cf90 to 8ce28bc Compare July 8, 2024 16:10
@marcus-oscarsson
Copy link
Member

@fabcor-maxiv: Yes, I think its fixed now. Seems like the poetry-export hook reacts to something I guess its the update of certifi

@fabcor-maxiv fabcor-maxiv force-pushed the poetry-export-pip-requirements-txt branch from 8ce28bc to 98129aa Compare July 9, 2024 07:24
@fabcor-maxiv
Copy link
Contributor Author

Seems like the poetry-export hook reacts to something I guess its the update of certifi

Oh, nice! That is very good that the issue is caught, that is what we want. : )

I forced the pre-commit hook to regenerate the exported requirements.txt (pre-commit run -a).

@fabcor-maxiv fabcor-maxiv self-assigned this Aug 8, 2024
@fabcor-maxiv fabcor-maxiv force-pushed the poetry-export-pip-requirements-txt branch 2 times, most recently from bde2d5b to 32b6b30 Compare August 8, 2024 14:26
This will let the pre-commit hooks ensure
that Poetry's lockfile is kept up-to-date
and that it is exported to a pip `requirements.txt` file.

GitHub: fix mxcube#1268
@fabcor-maxiv fabcor-maxiv force-pushed the poetry-export-pip-requirements-txt branch from 32b6b30 to 4c4a544 Compare August 8, 2024 14:32
@fabcor-maxiv
Copy link
Contributor Author

fabcor-maxiv commented Aug 8, 2024

This is now rebased, it takes into account the newly added dependency (argon2-cffi #1327).

@marcus-oscarsson marcus-oscarsson merged commit 31409e2 into mxcube:develop Aug 12, 2024
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.

Export Python dependencies as *pip* requirements.txt
2 participants