diff --git a/changelog/725.feature.rst b/changelog/725.feature.rst new file mode 100644 index 000000000..930032142 --- /dev/null +++ b/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 diff --git a/tox/config.py b/tox/config.py index ec9dc6c26..ad72bdf30 100755 --- a/tox/config.py +++ b/tox/config.py @@ -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 diff --git a/tox/hookspecs.py b/tox/hookspecs.py index d139f4094..ec177b7a8 100644 --- a/tox/hookspecs.py +++ b/tox/hookspecs.py @@ -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`` + """ diff --git a/tox/session.py b/tox/session.py index 747cf802c..a73c8f5f8 100644 --- a/tox/session.py +++ b/tox/session.py @@ -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: diff --git a/tox/venv.py b/tox/venv.py index 84e95016b..2850a77c2 100755 --- a/tox/venv.py +++ b/tox/venv.py @@ -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