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

Add conan version as separated command #13999

Merged
merged 6 commits into from
May 31, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions conan/cli/commands/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from conan.cli.commands.list import print_serial
from conan.cli.command import conan_command
from conan.cli.formatters import default_json_formatter
from conan import conan_version
import platform
import sys


@conan_command(group="Consumer", formatters={"text": print_serial, "json": default_json_formatter})
def version(conan_api, parser, *args):
"""
Give information about the Conan client version.
"""

return {'version': str(conan_version),
'python': {
'version': platform.python_version().replace('\n', ''),
'sys_version': sys.version.replace('\n', ''),
}
}

52 changes: 52 additions & 0 deletions conans/test/integration/command_v2/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from conans.test.utils.tools import TestClient
from conan import __version__
import json
import platform
import sys


def _python_version():
return platform.python_version().replace("\n", "")


def _sys_version():
return sys.version.replace("\n", "")


def test_version_json():
"""
Conan version command should be able to output a json with the version and python version.
"""
t = TestClient()
t.run("version --format=json")
js = json.loads(t.stdout)
assert js["version"] == __version__
assert js["python"]["version"] == _python_version()
assert js["python"]["sys_version"] == _sys_version()


def test_version_text():
"""
Conan version command should be able to output a raw text with the version and python version.
"""
t = TestClient()
t.run("version --format=text")
_validate_text_output(t.out)


def test_version_raw():
"""
Conan version command should be able to output a raw text with the version and python version,
when no format is specified.
"""
t = TestClient()
t.run("version")
_validate_text_output(t.out)


def _validate_text_output(output):
lines = output.splitlines()
assert f'version: {__version__}' in lines
assert 'python' in lines
assert f' version: {_python_version()}' in lines
assert f' sys_version: {_sys_version()}' in lines