diff --git a/dvc/command/version.py b/dvc/command/version.py index 02d38e81fb..cd600022f7 100644 --- a/dvc/command/version.py +++ b/dvc/command/version.py @@ -10,7 +10,7 @@ from dvc.exceptions import DvcException, NotDvcRepoError from dvc.scm.base import SCMError from dvc.system import System -from dvc.utils import is_binary, relpath +from dvc.utils import relpath from dvc.utils.pkg import PKG from dvc.version import __version__ @@ -27,13 +27,18 @@ class CmdVersion(CmdBaseNoRepo): def run(self): from dvc.repo import Repo + package = PKG + if PKG is None: + package = "" + else: + package = f"({PKG})" + info = [ - f"DVC version: {__version__}", - f"Python version: {platform.python_version()}", - f"Platform: {platform.platform()}", - f"Binary: {is_binary()}", - f"Package: {PKG}", - f"Supported remotes: {self.get_supported_remotes()}", + f"DVC version: {__version__} {package}", + "---------------------------------", + f"Platform: Python {platform.python_version()} on " + f"{platform.platform()}", + f"Supports: {self.get_supported_remotes()}", ] try: @@ -46,13 +51,13 @@ def run(self): # `dvc config cache.shared group`. if os.path.exists(repo.cache.local.cache_dir): info.append( - "Cache: {}".format(self.get_linktype_support_info(repo)) + "Cache types: {}".format( + self.get_linktype_support_info(repo) + ) ) if psutil: fs_type = self.get_fs_type(repo.cache.local.cache_dir) - info.append( - f"Filesystem type (cache directory): {fs_type}" - ) + info.append(f"Cache directory: {fs_type}") else: logger.warning( "Unable to detect supported link types, as cache " @@ -68,11 +73,11 @@ def run(self): root_directory = os.getcwd() info.append("Repo: dvc, git (broken)") else: - info.append("Repo: {}".format(_get_dvc_repo_info(repo))) + if psutil: + fs_root = self.get_fs_type(os.path.abspath(root_directory)) + info.append(f"Workspace directory: {fs_root}") - if psutil: - fs_root = self.get_fs_type(os.path.abspath(root_directory)) - info.append(f"Filesystem type (workspace): {fs_root}") + info.append("Repo: {}".format(_get_dvc_repo_info(repo))) logger.info("\n".join(info)) return 0 @@ -80,7 +85,7 @@ def run(self): @staticmethod def get_fs_type(path): partition = { - pathlib.Path(part.mountpoint): (part.fstype, part.device) + pathlib.Path(part.mountpoint): (part.fstype + " on " + part.device) for part in psutil.disk_partitions(all=True) } @@ -115,7 +120,9 @@ def get_linktype_support_info(repo): os.unlink(dst) except DvcException: status = "not supported" - cache.append(f"{name} - {status}") + + if status == "supported": + cache.append(name) os.remove(src) return ", ".join(cache) @@ -129,6 +136,12 @@ def get_supported_remotes(): if not tree_cls.get_missing_deps(): supported_remotes.append(tree_cls.scheme) + if len(supported_remotes) == len(TREES): + return "All remotes" + + if len(supported_remotes) == 1: + return supported_remotes + return ", ".join(supported_remotes) diff --git a/tests/func/test_version.py b/tests/func/test_version.py index 9c31b3f84c..c55955db40 100644 --- a/tests/func/test_version.py +++ b/tests/func/test_version.py @@ -16,15 +16,10 @@ def test_info_in_repo(scm_init, 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 re.search(r"Supported remotes: .*", caplog.text) - assert re.search( - r"(Cache: (.*link - (not )?supported(,\s)?){3})", caplog.text - ) + assert re.search(r"DVC version: \d+\.\d+\.\d+\+.*", caplog.text) + assert re.search(r"Platform: Python \d\.\d\.\d on .*", caplog.text) + assert re.search(r"Supports: .*", caplog.text) + assert re.search(r"Cache types: .*", caplog.text) if scm_init: assert "Repo: dvc, git" in caplog.text @@ -58,26 +53,20 @@ 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 + assert re.search(r"Cache directory: .* on .*", caplog.text) + assert re.search(r"Workspace directory: .* on .*", 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 re.search(r"Supported remotes: .*", caplog.text) - assert not re.search(r"(Cache: (.*link - (not )?(,\s)?){3})", caplog.text) + assert re.search(r"DVC version: \d+\.\d+\.\d+\+.*", caplog.text) + assert re.search(r"Platform: Python \d\.\d\.\d on .*", caplog.text) + assert re.search(r"Supports: .*", caplog.text) + assert not re.search(r"Cache types: .*", caplog.text) assert "Repo:" not in caplog.text @pytest.mark.skipif(psutil is None, reason="No psutil.") def test_fs_info_outside_of_repo(tmp_dir, caplog): assert main(["version"]) == 0 - - assert "Filesystem type (cache directory): " not in caplog.text - assert "Filesystem type (workspace): " in caplog.text