Skip to content

Commit

Permalink
Package stat plugin (#730)
Browse files Browse the repository at this point in the history
* add a plugin for reporting on the package versions in a venv. see #725
* changelog entry for #725
* fix lint issue
* add docstring comment on expected response
  • Loading branch information
tonybaloney authored and gaborbernat committed Jan 24, 2018
1 parent 336f4f6 commit 332f4ca
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
2 changes: 2 additions & 0 deletions changelog/725.feature.rst
@@ -0,0 +1,2 @@
Add tox_runenvreport as a possible plugin, allowing the overriding of the default behaviour to execute a command
to get the installed packages within a virtual environment - by @tonybaloney
4 changes: 2 additions & 2 deletions tox/config.py
Expand Up @@ -1090,8 +1090,8 @@ def factor_line(line):
return line

expr, line = m.groups()
if any(included <= self.factors
and not any(x in self.factors for x in excluded)
if any(included <= self.factors and not
any(x in self.factors for x in excluded)
for included, excluded in _split_factor_expr(expr)):
return line

Expand Down
9 changes: 9 additions & 0 deletions tox/hookspecs.py
Expand Up @@ -103,3 +103,12 @@ def tox_runtest_post(venv):
This could be used to have per-venv test reporting of pass/fail status.
"""


@hookspec(firstresult=True)
def tox_runenvreport(venv, action):
""" [experimental] Get the installed packages and versions in this venv
This could be used for alternative (ie non-pip) package managers, this
plugin should return a ``list`` of type ``str``
"""
27 changes: 13 additions & 14 deletions tox/session.py
Expand Up @@ -605,24 +605,23 @@ def subcommand_test(self):
else:
self.installpkg(venv, path)

# write out version dependency information
action = self.newaction(venv, "envreport")
with action:
args = venv.envconfig.list_dependencies_command
output = venv._pcall(args,
cwd=self.config.toxinidir,
action=action)
# the output contains a mime-header, skip it
output = output.split("\n\n")[-1]
packages = output.strip().split("\n")
action.setactivity("installed", ",".join(packages))
envlog = self.resultlog.get_envlog(venv.name)
envlog.set_installed(packages)

self.runenvreport(venv)
self.runtestenv(venv)
retcode = self._summary()
return retcode

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:
packages = self.hook.tox_runenvreport(venv=venv, action=action)
action.setactivity("installed", ",".join(packages))
envlog = self.resultlog.get_envlog(venv.name)
envlog.set_installed(packages)

def runtestenv(self, venv, redirect=False):
if not self.config.option.notest:
if venv.status:
Expand Down
14 changes: 14 additions & 0 deletions tox/venv.py
Expand Up @@ -459,3 +459,17 @@ def tox_runtest(venv, redirect):
venv.test(redirect=redirect)
# Return non-None to indicate the plugin has completed
return True


@hookimpl
def tox_runenvreport(venv, action):
# write out version dependency information
args = venv.envconfig.list_dependencies_command
output = venv._pcall(args,
cwd=venv.envconfig.config.toxinidir,
action=action)
# the output contains a mime-header, skip it
output = output.split("\n\n")[-1]
packages = output.strip().split("\n")
# Return non-None to indicate the plugin has completed
return packages

0 comments on commit 332f4ca

Please sign in to comment.