From 0786a706975c448989ad3c515523d84fa88373fe Mon Sep 17 00:00:00 2001 From: kss682 Date: Tue, 5 Nov 2019 00:15:56 +0530 Subject: [PATCH] Package added with get_package_manager function and other utils. import changed accordingly in version Solves issue #2672 --- dvc/command/version.py | 4 ++-- dvc/utils/pkg.py | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 dvc/utils/pkg.py diff --git a/dvc/command/version.py b/dvc/command/version.py index a123bfafed..7cf00c7516 100644 --- a/dvc/command/version.py +++ b/dvc/command/version.py @@ -18,7 +18,7 @@ from dvc.version import __version__ from dvc.exceptions import DvcException, NotDvcRepoError from dvc.system import System -from dvc.updater import Updater +from dvc.utils.pkg import get_package_manager logger = logging.getLogger(__name__) @@ -31,7 +31,7 @@ def run(self): python_version = platform.python_version() platform_type = platform.platform() binary = is_binary() - package_manager = Updater("dvc/")._get_package_manager() + package_manager = get_package_manager() info = ( "DVC version: {dvc_version}\n" "Python version: {python_version}\n" diff --git a/dvc/utils/pkg.py b/dvc/utils/pkg.py new file mode 100644 index 0000000000..a35bd73063 --- /dev/null +++ b/dvc/utils/pkg.py @@ -0,0 +1,51 @@ +from dvc.utils import is_binary + + +def get_linux(): + import distro + + if not is_binary(): + return "pip" + + package_managers = { + "rhel": "yum", + "centos": "yum", + "fedora": "yum", + "amazon": "yum", + "opensuse": "yum", + "ubuntu": "apt", + "debian": "apt", + } + + return package_managers.get(distro.id()) + + +def get_darwin(): + if not is_binary(): + if __file__.startswith("/usr/local/Cellar"): + return "formula" + else: + return "pip" + return None + + +def get_windows(): + return None if is_binary() else "pip" + + +def get_package_manager(): + import platform + from dvc.exceptions import DvcException + + m = { + "Windows": get_windows(), + "Darwin": get_darwin(), + "Linux": get_linux(), + } + + system = platform.system() + func = m.get(system) + if func is None: + raise DvcException("not supported system '{}'".format(system)) + + return func