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

Emit post_lock after writing pyproject.toml and pdm.lock #3285

Closed
1 task done
jantrienes opened this issue Nov 13, 2024 · 0 comments · Fixed by #3291
Closed
1 task done

Emit post_lock after writing pyproject.toml and pdm.lock #3285

jantrienes opened this issue Nov 13, 2024 · 0 comments · Fixed by #3291
Labels
⭐ enhancement Improvements for existing features 💝 good first issue Good for newcomers

Comments

@jantrienes
Copy link
Contributor

jantrienes commented Nov 13, 2024

Feature Description

We are trying to automatically generate platform-specific lockfiles whenever changes to the pyproject.toml were made. We tried using the post_lock lifecycle hook:

[tool.pdm.scripts]
post_lock = {composite = [
    "pdm lock --skip=post_lock --platform=manylinux_2_36_x86_64 --lockfile=pdm.lock.amd64 --with cpu",
    "pdm lock --skip=post_lock --platform=manylinux_2_36_aarch64 --lockfile=pdm.lock.arm64",
]}

However, this does not work for pdm add, because the post_lock event is emitted before the new pyproject.toml is written, meaning that the above pdm lock commands still operate on the "old" pyproject.toml file.

hooks.try_emit("post_lock", resolution=resolved, dry_run=dry_run)
if not dry_run:
project.add_dependencies(deps_to_update, group, selection.dev or False)
project.write_lockfile(project.lockfile._data, False)
if sync:
do_sync(

As a workaround, we are using the post_install hook. This works, but this hook is also emitted in "clean" installs when no changes were made to the dependencies, triggering unnecessary lockfile generations.

Problem and Solution

Having the lockfile written to the disk before calling the post_lock hook would enable this functionality and make PDM's adoption easier for workflows that use platform-specific lockfiles.

Additional Context

I think this is analogous to #1224.

Are you willing to contribute to the development of this feature?

  • Yes, I am willing to contribute to the development of this feature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement Improvements for existing features 💝 good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants