-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conan version as separated command (#13999)
* Add conan version command Signed-off-by: Uilian Ries <uilianries@gmail.com> * Print python version as well Signed-off-by: Uilian Ries <uilianries@gmail.com> * don't reinvent the wheel - print_serial Signed-off-by: Uilian Ries <uilianries@gmail.com> * adjust tests Signed-off-by: Uilian Ries <uilianries@gmail.com> * strip new lines Signed-off-by: Uilian Ries <uilianries@gmail.com> * better format for testing conan version Signed-off-by: Uilian Ries <uilianries@gmail.com> --------- Signed-off-by: Uilian Ries <uilianries@gmail.com>
- Loading branch information
1 parent
0839bc7
commit e1f4c62
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', ''), | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |