Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plugins to attach data to --version #3234

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/3234.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow plugins attaching additional information to ``--version`` via ``tox_append_version_info`` method in the plugin
module - by :user:`gaborbernat`.
9 changes: 9 additions & 0 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ Extensions points
.. automodule:: tox.plugin.spec
:members:

A plugin can define its plugin module a:

.. code-block:: python

def tox_append_version_info() -> str:
return "magic"

and this message will be appended to the output of the ``--version`` flag.

Adoption of a plugin under tox-dev Github organization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 3 additions & 1 deletion src/tox/session/cmd/version_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ def get_version_info() -> str:
out.append("registered plugins:")
for module, egg_info in plugin_info:
source = getattr(module, "__file__", repr(module))
out.append(f" {egg_info.project_name}-{egg_info.version} at {source}")
info = module.tox_append_version_info() if hasattr(module, "tox_append_version_info") else ""
with_info = f" {info}" if info else ""
out.append(f" {egg_info.project_name}-{egg_info.version} at {source}{with_info}")
return "\n".join(out)
13 changes: 8 additions & 5 deletions tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ def test_version_without_plugin(tox_project: ToxProjectCreator) -> None:
def test_version_with_plugin(tox_project: ToxProjectCreator, mocker: MockFixture) -> None:
dist = [
(
mocker.create_autospec("types.ModuleType", __file__=f"{i}-path"),
SimpleNamespace(project_name=i, version=v),
)
for i, v in (("B", "1.0"), ("A", "2.0"))
mocker.create_autospec("types.ModuleType", __file__="B-path", tox_append_version_info=lambda: "magic"),
SimpleNamespace(project_name="B", version="1.0"),
),
(
mocker.create_autospec("types.ModuleType", __file__="A-path"),
SimpleNamespace(project_name="A", version="2.0"),
),
]
mocker.patch.object(MANAGER.manager, "list_plugin_distinfo", return_value=dist)

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

assert lines[1:] == [
"registered plugins:",
" B-1.0 at B-path",
" B-1.0 at B-path magic",
" A-2.0 at A-path",
]