Skip to content

Commit

Permalink
prefer using with as for action (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored and obestwalter committed May 14, 2018
1 parent 49b915c commit cb2dff1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
19 changes: 7 additions & 12 deletions tox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def __init__(self, session, venv, msg, args):

def __enter__(self):
self.report.logaction_start(self)
return self

def __exit__(self, *args):
self.report.logaction_finish(self)
Expand Down Expand Up @@ -445,8 +446,7 @@ def _makesdist(self):
"#avoiding-expensive-sdist".format(setup)
)
raise SystemExit(1)
action = self.newaction(None, "packaging")
with action:
with self.newaction(None, "packaging") as action:
action.setactivity("sdist-make", setup)
self.make_emptydir(self.config.distdir)
action.popen(
Expand Down Expand Up @@ -497,8 +497,7 @@ def setupenv(self, venv):
if not venv.matching_platform():
venv.status = "platform mismatch"
return # we simply omit non-matching platforms
action = self.newaction(venv, "getenv", venv.envconfig.envdir)
with action:
with self.newaction(venv, "getenv", venv.envconfig.envdir) as action:
venv.status = 0
default_ret_code = 1
envlog = self.resultlog.get_envlog(venv.name)
Expand Down Expand Up @@ -536,14 +535,12 @@ def setupenv(self, venv):
return True

def finishvenv(self, venv):
action = self.newaction(venv, "finishvenv")
with action:
with self.newaction(venv, "finishvenv"):
venv.finish()
return True

def developpkg(self, venv, setupdir):
action = self.newaction(venv, "developpkg", setupdir)
with action:
with self.newaction(venv, "developpkg", setupdir) as action:
try:
venv.developpkg(setupdir, action)
return True
Expand All @@ -560,8 +557,7 @@ def installpkg(self, venv, path):
:rtype: bool
"""
self.resultlog.set_header(installpkg=py.path.local(path))
action = self.newaction(venv, "installpkg", path)
with action:
with self.newaction(venv, "installpkg", path) as action:
try:
venv.installpkg(path, action)
return True
Expand Down Expand Up @@ -635,8 +631,7 @@ def runenvreport(self, venv):
Run an environment report to show which package
versions are installed in the venv
"""
action = self.newaction(venv, "envreport")
with action:
with self.newaction(venv, "envreport") as action:
packages = self.hook.tox_runenvreport(venv=venv, action=action)
action.setactivity("installed", ",".join(packages))
envlog = self.resultlog.get_envlog(venv.name)
Expand Down
3 changes: 1 addition & 2 deletions tox/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ def _getenv(self, testcommand=False):
return env

def test(self, redirect=False):
action = self.session.newaction(self, "runtests")
with action:
with self.session.newaction(self, "runtests") as action:
self.status = 0
self.session.make_emptydir(self.envconfig.envtmpdir)
self.envconfig.envtmpdir.ensure(dir=1)
Expand Down

0 comments on commit cb2dff1

Please sign in to comment.