Skip to content

Commit 5356d96

Browse files
authored
Allow plugins to attach data to --version (#3234)
1 parent 717e27f commit 5356d96

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

docs/changelog/3234.feature.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Allow plugins attaching additional information to ``--version`` via ``tox_append_version_info`` method in the plugin
2+
module - by :user:`gaborbernat`.

docs/plugins.rst

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ Extensions points
1414
.. automodule:: tox.plugin.spec
1515
:members:
1616

17+
A plugin can define its plugin module a:
18+
19+
.. code-block:: python
20+
21+
def tox_append_version_info() -> str:
22+
return "magic"
23+
24+
and this message will be appended to the output of the ``--version`` flag.
25+
1726
Adoption of a plugin under tox-dev Github organization
1827
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1928

src/tox/session/cmd/version_flag.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ def get_version_info() -> str:
4343
out.append("registered plugins:")
4444
for module, egg_info in plugin_info:
4545
source = getattr(module, "__file__", repr(module))
46-
out.append(f" {egg_info.project_name}-{egg_info.version} at {source}")
46+
info = module.tox_append_version_info() if hasattr(module, "tox_append_version_info") else ""
47+
with_info = f" {info}" if info else ""
48+
out.append(f" {egg_info.project_name}-{egg_info.version} at {source}{with_info}")
4749
return "\n".join(out)

tests/test_version.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ def test_version_without_plugin(tox_project: ToxProjectCreator) -> None:
2626
def test_version_with_plugin(tox_project: ToxProjectCreator, mocker: MockFixture) -> None:
2727
dist = [
2828
(
29-
mocker.create_autospec("types.ModuleType", __file__=f"{i}-path"),
30-
SimpleNamespace(project_name=i, version=v),
31-
)
32-
for i, v in (("B", "1.0"), ("A", "2.0"))
29+
mocker.create_autospec("types.ModuleType", __file__="B-path", tox_append_version_info=lambda: "magic"),
30+
SimpleNamespace(project_name="B", version="1.0"),
31+
),
32+
(
33+
mocker.create_autospec("types.ModuleType", __file__="A-path"),
34+
SimpleNamespace(project_name="A", version="2.0"),
35+
),
3336
]
3437
mocker.patch.object(MANAGER.manager, "list_plugin_distinfo", return_value=dist)
3538

@@ -42,6 +45,6 @@ def test_version_with_plugin(tox_project: ToxProjectCreator, mocker: MockFixture
4245

4346
assert lines[1:] == [
4447
"registered plugins:",
45-
" B-1.0 at B-path",
48+
" B-1.0 at B-path magic",
4649
" A-2.0 at A-path",
4750
]

0 commit comments

Comments
 (0)