Skip to content

Conversation

@smurfix
Copy link
Contributor

@smurfix smurfix commented Dec 21, 2018

This patch allows adding context managers to a command group's common code that are then usable in the group's statements. This reduces code duplication and lets us move code using the group's options closer to the options themselves.

fixes #1245

@davidism davidism added this to the 8.0.0 milestone Aug 9, 2020
This makes it possible to open a resource, make it available to
callbacks and subcommands, then ensure the resource is cleaned up when
the group ends and the context goes out of scope.
@davidism
Copy link
Member

Renamed the method to with_resource because I felt enter_context was confusing as a method on Context. The new name reflects that the resource would be managed with the with statement. Moved the docs to advanced.rst and rewrote them, along with the doc strings for with_resource and call_on_close. ExitStack.__enter__ doesn't have to be called, and doesn't return a different object, so now the implementation only tracks a single attribute called _exit_stack, and calls the close method instead of __exit__.

@davidism davidism merged commit 563b1a7 into pallets:master Aug 10, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run subcommand in context manager

2 participants