diff options
author | Anthony Shaw <anthony.p.shaw@gmail.com> | 2018-01-24 12:04:10 +1100 |
---|---|---|
committer | Gábor Bernát <gaborjbernat@gmail.com> | 2018-01-24 01:04:10 +0000 |
commit | 332f4ca0680cbf80c10a9df5e5cfafc7e0b7c2c4 (patch) | |
tree | 501b3bd1500894159dd3fb822563207cdeecc139 | |
parent | 336f4f6bd8b53223f940fc5cfc43b1bbd78d4699 (diff) | |
download | tox-git-332f4ca0680cbf80c10a9df5e5cfafc7e0b7c2c4.tar.gz |
Package stat plugin (#730)
* 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
-rw-r--r-- | changelog/725.feature.rst | 2 | ||||
-rwxr-xr-x | tox/config.py | 4 | ||||
-rw-r--r-- | tox/hookspecs.py | 9 | ||||
-rw-r--r-- | tox/session.py | 27 | ||||
-rwxr-xr-x | tox/venv.py | 14 |
5 files changed, 40 insertions, 16 deletions
diff --git a/changelog/725.feature.rst b/changelog/725.feature.rst new file mode 100644 index 00000000..93003214 --- /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 ec9dc6c2..ad72bdf3 100755 --- a/tox/config.py +++ b/tox/config.py @@ -1090,8 +1090,8 @@ class SectionReader: 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 d139f409..ec177b7a 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 747cf802..a73c8f5f 100644 --- a/tox/session.py +++ b/tox/session.py @@ -605,24 +605,23 @@ class Session: 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 84e95016..2850a77c 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 |