mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 15:28:27 +01:00
Merge pull request #3006 from Suor/version-newline
ui: fix extra newline in dvc version
This commit is contained in:
+17
-27
@@ -27,23 +27,13 @@ class CmdVersion(CmdBaseNoRepo):
|
||||
def run(self):
|
||||
from dvc.repo import Repo
|
||||
|
||||
dvc_version = __version__
|
||||
python_version = platform.python_version()
|
||||
platform_type = platform.platform()
|
||||
binary = is_binary()
|
||||
info = (
|
||||
"DVC version: {dvc_version}\n"
|
||||
"Python version: {python_version}\n"
|
||||
"Platform: {platform_type}\n"
|
||||
"Binary: {binary}\n"
|
||||
"Package: {package}\n"
|
||||
).format(
|
||||
dvc_version=dvc_version,
|
||||
python_version=python_version,
|
||||
platform_type=platform_type,
|
||||
binary=binary,
|
||||
package=PKG,
|
||||
)
|
||||
info = [
|
||||
"DVC version: {}".format(__version__),
|
||||
"Python version: {}".format(platform.python_version()),
|
||||
"Platform: {}".format(platform.platform()),
|
||||
"Binary: {}".format(is_binary()),
|
||||
"Package: {}".format(PKG),
|
||||
]
|
||||
|
||||
try:
|
||||
repo = Repo()
|
||||
@@ -54,9 +44,14 @@ class CmdVersion(CmdBaseNoRepo):
|
||||
# later decides to enable shared cache mode with
|
||||
# `dvc config cache.shared group`.
|
||||
if os.path.exists(repo.cache.local.cache_dir):
|
||||
info += "Cache: {cache}\n".format(
|
||||
cache=self.get_linktype_support_info(repo)
|
||||
info.append(
|
||||
"Cache: {}".format(self.get_linktype_support_info(repo))
|
||||
)
|
||||
if psutil:
|
||||
fs_type = self.get_fs_type(repo.cache.local.cache_dir)
|
||||
info.append(
|
||||
"Filesystem type (cache directory): {}".format(fs_type)
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Unable to detect supported link types, as cache "
|
||||
@@ -66,19 +61,14 @@ class CmdVersion(CmdBaseNoRepo):
|
||||
"check.".format(relpath(repo.cache.local.cache_dir))
|
||||
)
|
||||
|
||||
if psutil:
|
||||
info += (
|
||||
"Filesystem type (cache directory): {fs_cache}\n"
|
||||
).format(fs_cache=self.get_fs_type(repo.cache.local.cache_dir))
|
||||
except NotDvcRepoError:
|
||||
root_directory = os.getcwd()
|
||||
|
||||
if psutil:
|
||||
info += ("Filesystem type (workspace): {fs_root}").format(
|
||||
fs_root=self.get_fs_type(os.path.abspath(root_directory))
|
||||
)
|
||||
fs_root = self.get_fs_type(os.path.abspath(root_directory))
|
||||
info.append("Filesystem type (workspace): {}".format(fs_root))
|
||||
|
||||
logger.info(info)
|
||||
logger.info("\n".join(info))
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
|
||||
+34
-43
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
import pytest
|
||||
@@ -6,54 +7,44 @@ from dvc.command.version import psutil
|
||||
from dvc.main import main
|
||||
|
||||
|
||||
def test_info_in_repo(repo_dir, dvc_repo, caplog):
|
||||
# adding a file so that dvc creates `.dvc/cache`, that is needed for proper
|
||||
# supported link types check.
|
||||
assert main(["add", repo_dir.FOO]) == 0
|
||||
def test_info_in_repo(tmp_dir, dvc, caplog):
|
||||
# Create `.dvc/cache`, that is needed to check supported link types.
|
||||
os.mkdir(dvc.cache.local.cache_dir)
|
||||
assert main(["version"]) == 0
|
||||
|
||||
assert re.search(re.compile(r"DVC version: \d+\.\d+\.\d+"), caplog.text)
|
||||
assert re.search(re.compile(r"Python version: \d\.\d\.\d"), caplog.text)
|
||||
assert re.search(re.compile(r"Platform: .*"), caplog.text)
|
||||
assert re.search(re.compile(r"Binary: (True|False)"), caplog.text)
|
||||
assert re.search(re.compile(r"Package: .*"), caplog.text)
|
||||
assert re.search(
|
||||
re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text
|
||||
assert re.search(r"DVC version: \d+\.\d+\.\d+", caplog.text)
|
||||
assert re.search(r"Python version: \d\.\d\.\d", caplog.text)
|
||||
assert re.search(r"Platform: .*", caplog.text)
|
||||
assert re.search(r"Binary: (True|False)", caplog.text)
|
||||
assert re.search(r"Package: .*", caplog.text)
|
||||
assert re.search(r"(Cache: (.*link - (True|False)(,\s)?){3})", caplog.text)
|
||||
|
||||
|
||||
@pytest.mark.skipif(psutil is None, reason="No psutil.")
|
||||
def test_fs_info_in_repo(tmp_dir, dvc, caplog):
|
||||
os.mkdir(dvc.cache.local.cache_dir)
|
||||
assert main(["version"]) == 0
|
||||
|
||||
assert "Filesystem type (cache directory): " in caplog.text
|
||||
assert "Filesystem type (workspace): " in caplog.text
|
||||
|
||||
|
||||
def test_info_outside_of_repo(tmp_dir, caplog):
|
||||
assert main(["version"]) == 0
|
||||
|
||||
assert re.search(r"DVC version: \d+\.\d+\.\d+", caplog.text)
|
||||
assert re.search(r"Python version: \d\.\d\.\d", caplog.text)
|
||||
assert re.search(r"Platform: .*", caplog.text)
|
||||
assert re.search(r"Binary: (True|False)", caplog.text)
|
||||
assert re.search(r"Package: .*", caplog.text)
|
||||
assert not re.search(
|
||||
r"(Cache: (.*link - (True|False)(,\s)?){3})", caplog.text
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skipif(psutil is None, reason="No psutil.")
|
||||
def test_fs_info_in_repo(dvc_repo, caplog):
|
||||
def test_fs_info_outside_of_repo(tmp_dir, caplog):
|
||||
assert main(["version"]) == 0
|
||||
|
||||
assert re.search(
|
||||
re.compile(r"Filesystem type \(cache directory\): .*"), caplog.text
|
||||
)
|
||||
assert re.search(
|
||||
re.compile(r"Filesystem type \(workspace\): .*"), caplog.text
|
||||
)
|
||||
|
||||
|
||||
def test_info_outside_of_repo(repo_dir, caplog):
|
||||
assert main(["version"]) == 0
|
||||
|
||||
assert re.search(re.compile(r"DVC version: \d+\.\d+\.\d+"), caplog.text)
|
||||
assert re.search(re.compile(r"Python version: \d\.\d\.\d"), caplog.text)
|
||||
assert re.search(re.compile(r"Platform: .*"), caplog.text)
|
||||
assert re.search(re.compile(r"Binary: (True|False)"), caplog.text)
|
||||
assert re.search(re.compile(r"Package: .*"), caplog.text)
|
||||
assert not re.search(
|
||||
re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skipif(psutil is None, reason="No psutil.")
|
||||
def test_fs_info_outside_of_repo(repo_dir, caplog):
|
||||
assert main(["version"]) == 0
|
||||
|
||||
assert re.search(
|
||||
re.compile(r"Filesystem type \(workspace\): .*"), caplog.text
|
||||
)
|
||||
assert not re.search(
|
||||
re.compile(r"Filesystem type \(cache directory\): .*"), caplog.text
|
||||
)
|
||||
assert "Filesystem type (cache directory): " not in caplog.text
|
||||
assert "Filesystem type (workspace): " in caplog.text
|
||||
|
||||
Reference in New Issue
Block a user