Skip to content

Commit 012e3d3

Browse files
committed
Don't set context.vent to a nullcontext
Fixes #30 Signed-off-by: Pedro Algarvio <[email protected]>
1 parent f29381a commit 012e3d3

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

changelog/30.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't set `context.vent` to a `nullcontext`

src/ptscripts/parser.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -692,22 +692,18 @@ def __call__(self, func, options, venv_config: VirtualEnvConfig | None = None):
692692
kwargs[name] = getattr(options, name)
693693

694694
bound = signature.bind_partial(*args, **kwargs)
695-
venv: VirtualEnv | ContextManager[None]
696695
if venv_config:
697696
if "name" not in venv_config:
698697
venv_config["name"] = getattr(options, f"{self.name}_command")
699-
venv = VirtualEnv(ctx=self.context, **venv_config)
700-
elif self.venv_config:
701-
venv = VirtualEnv(ctx=self.context, **self.venv_config)
698+
with VirtualEnv(ctx=self.context, **venv_config) as venv:
699+
previous_venv = self.context.venv
700+
try:
701+
self.context.venv = venv
702+
func(self.context, *bound.args, **bound.kwargs)
703+
finally:
704+
self.context.venv = previous_venv
702705
else:
703-
venv = nullcontext()
704-
with venv:
705-
previous_venv = self.context.venv
706-
try:
707-
self.context.venv = venv
708-
func(self.context, *bound.args, **bound.kwargs)
709-
finally:
710-
self.context.venv = previous_venv
706+
func(self.context, *bound.args, **bound.kwargs)
711707

712708

713709
def command_group(

0 commit comments

Comments
 (0)