From 096356a2310d611371b466c969c81d489cb59a27 Mon Sep 17 00:00:00 2001 From: Jan Trienes Date: Thu, 14 Nov 2024 15:00:51 +0100 Subject: [PATCH] feat: emit post_lock after writing pyproject.toml and pdm.lock in add/update --- news/3285.feature.md | 1 + src/pdm/cli/commands/add.py | 2 +- src/pdm/cli/commands/update.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 news/3285.feature.md diff --git a/news/3285.feature.md b/news/3285.feature.md new file mode 100644 index 0000000000..10846fccc9 --- /dev/null +++ b/news/3285.feature.md @@ -0,0 +1 @@ +Emit `post_lock` after writing pyproject.toml and pdm.lock in add/update diff --git a/src/pdm/cli/commands/add.py b/src/pdm/cli/commands/add.py index b90d7c168c..5f9ab85854 100644 --- a/src/pdm/cli/commands/add.py +++ b/src/pdm/cli/commands/add.py @@ -165,10 +165,10 @@ def do_add( # Update dependency specifiers and lockfile hash. deps_to_update = group_deps if unconstrained else requirements save_version_specifiers(deps_to_update, resolved, save) - 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) + hooks.try_emit("post_lock", resolution=resolved, dry_run=dry_run) if sync: do_sync( project, diff --git a/src/pdm/cli/commands/update.py b/src/pdm/cli/commands/update.py index 7f8f7aae1d..8a4074998a 100644 --- a/src/pdm/cli/commands/update.py +++ b/src/pdm/cli/commands/update.py @@ -187,7 +187,6 @@ def do_update( hooks=hooks, groups=locked_groups, ) - hooks.try_emit("post_lock", resolution=resolved, dry_run=dry_run) if unconstrained: # Need to update version constraints save_version_specifiers(chain.from_iterable(updated_deps.values()), resolved, save) @@ -196,6 +195,7 @@ def do_update( for group, deps in updated_deps.items(): project.add_dependencies(deps, group, selection.dev or False) project.write_lockfile(project.lockfile._data, False) + hooks.try_emit("post_lock", resolution=resolved, dry_run=dry_run) if sync or dry_run: do_sync( project,