packages
parameter for the pre_install
and post_install
hooks is given as an exhausted generator
#3190
Closed
1 task done
Labels
🐛 bug
Something isn't working
Ran into a regression while migrating a plugin to 2.19 where the
pre_install
andpost_install
hooks'packages
parameter is always an exhausted generator. Looks like it's due to the recent changes to the sync internals in cdb025c. Full details in the "Root Cause" section.Steps to reproduce
Plugin
Example project
Actual behavior
The
packages
parameter is exhausted and will produce no elements when iterated over.Root Cause
The
packages
variable, which replaced the previouscandidates
dict
, is now a generator:pdm/src/pdm/cli/actions.py
Line 284 in 16933a1
... which is passed to the
BaseSynchronizer
constructor then iterated over and exhausted.pdm/src/pdm/cli/actions.py
Line 296 in 16933a1
pdm/src/pdm/installers/base.py
Line 63 in 16933a1
The now exhausted generator object is then passed to the hooks:
pdm/src/pdm/cli/actions.py
Lines 300 to 302 in 16933a1
... where trying to iterator over it (
packages
) in the hooks will yield zero elements.Also worth pointing out that
self.packages
is assigned to this same exhausted generator object. Maybe this is intentional in this case? I'm not too familiar with pdm's internals.pdm/src/pdm/installers/base.py
Line 81 in 16933a1
Expected behavior
The
pre_install
andpost_install
hooks should be passed alist[Package]
as documented or some other form of non-emptyMutableSequence
, such that the previous behaviour of being able to mutate thecandidates
dict inflight is preserved.A straight forward fix would be to consume the generator into a
list
before passing it to theBaseSynchronizer
constructor and hooks.Environment Information
The text was updated successfully, but these errors were encountered: