Skip to content

Commit

Permalink
Refactor get_package_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
n3hrox committed Nov 10, 2019
1 parent f4ee4b0 commit e1dfb75
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 81 deletions.
8 changes: 3 additions & 5 deletions dvc/command/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from dvc.version import __version__
from dvc.exceptions import DvcException, NotDvcRepoError
from dvc.system import System
from dvc.utils.pkg import get_package_manager, check_build_patch
from dvc.utils.pkg import get_package_manager

logger = logging.getLogger(__name__)

Expand All @@ -30,16 +30,14 @@ def run(self):
dvc_version = __version__
python_version = platform.python_version()
platform_type = platform.platform()
binary = False
if is_binary():
binary = check_build_patch()
binary = is_binary()
package_manager = get_package_manager()
info = (
"DVC version: {dvc_version}\n"
"Python version: {python_version}\n"
"Platform: {platform_type}\n"
"Binary: {binary}\n"
"Package manager: {package_manager}\n"
"Package type: {package_manager}\n"
).format(
dvc_version=dvc_version,
python_version=python_version,
Expand Down
9 changes: 4 additions & 5 deletions dvc/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,13 @@ def _notify(self):
def _get_update_instructions(self):
instructions = {
"pip": "Run {yellow}pip{reset} install dvc {blue}--upgrade{reset}",
"yum": "Run {yellow}yum{reset} update dvc",
"yay": "Run {yellow}yay{reset} {blue}-S{reset} dvc",
"formula": "Run {yellow}brew{reset} upgrade dvc",
"apt": (
"rpm": "Run {yellow}yum{reset} update dvc",
"osxpkg": "Run {yellow}brew{reset} upgrade dvc",
"deb": (
"Run {yellow}apt-get{reset} install"
" {blue}--only-upgrade{reset} dvc"
),
"binary": (
"exe": (
"To upgrade follow these steps:\n"
"1. Uninstall dvc binary\n"
"2. Go to {blue}https://dvc.org{reset}\n"
Expand Down
1 change: 1 addition & 0 deletions dvc/utils/bulid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PKG = "windows"
52 changes: 3 additions & 49 deletions dvc/utils/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,11 @@ def check_build_patch():

return PKG
except ImportError:
return False
return None


def get_linux():
import distro

def get_package_manager():
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 check_build_patch() == "darwin":
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

if check_build_patch() == "conda":
return "conda"

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
return check_build_patch()
5 changes: 1 addition & 4 deletions scripts/build_posix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ command_exists()
fpm_build()
{
print_info "Building $1..."
git apply "$(pwd)/scripts/$1.patch"
VERSION=$(python -c "import dvc; from dvc import __version__; print(str(__version__))")
fpm -s dir \
-f \
Expand Down Expand Up @@ -103,10 +104,6 @@ build_dvc()
{
print_info "Building dvc binary..."

if [[ "$(uname)" != 'Linux' ]]; then
git apply $(pwd)/scripts/darwin.patch
fi

pyinstaller \
--additional-hooks-dir $(pwd)/scripts/hooks dvc/__main__.py \
--name dvc \
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_windows.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where iscc
if %errorlevel% neq 0 (echo Error: Couldn't find Inno Setup compiler. && goto :error)

echo ====== Installing requirements... ======
call git patch scripts/patches/windows.patch
call git patch scripts\patches\windows.patch
call pip install .[all] || goto :error
call pip install psutil || goto :error
call dvc pull || goto :error
Expand Down
14 changes: 14 additions & 0 deletions scripts/patches/deb.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
dvc/utils/build.py | 1 +
1 file changed, 1 insertion(+)
create mode 100644 dvc/utils/build.py

diff --git a/dvc/utils/build.py b/dvc/utils/build.py
new file mode 100644
index 00000000..ada7a0bb
--- /dev/null
+++ b/dvc/utils/build.py
@@ -0,0 +1 @@
+PKG = "deb"
--
2.17.1
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
From 71707795d27aa848d71780b84e056b4f5735650c Mon Sep 17 00:00:00 2001
From: n3hrox <[email protected]>
Date: Sun, 10 Nov 2019 17:35:10 +0100
Subject: [PATCH] Darwin patch

---
dvc/utils/build.py | 1 +
1 file changed, 1 insertion(+)
Expand All @@ -14,7 +9,6 @@ index 00000000..3d149b9a
--- /dev/null
+++ b/dvc/utils/build.py
@@ -0,0 +1 @@
+PKG = "darwin"
+PKG = "osxpkg"
--
2.17.1

14 changes: 14 additions & 0 deletions scripts/patches/rpm.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
dvc/utils/build.py | 1 +
1 file changed, 1 insertion(+)
create mode 100644 dvc/utils/build.py

diff --git a/dvc/utils/build.py b/dvc/utils/build.py
new file mode 100644
index 00000000..ada7a0bb
--- /dev/null
+++ b/dvc/utils/build.py
@@ -0,0 +1 @@
+PKG = "rpm"
--
2.17.1
15 changes: 5 additions & 10 deletions scripts/patches/windows.patch
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
From 6b53dcffe5e13cb3c196d29a495d8da9bcc26d6d Mon Sep 17 00:00:00 2001
From: n3hrox <[email protected]>
Date: Sun, 10 Nov 2019 15:44:14 +0100
Subject: [PATCH] Windows patch

---
dvc/utils/buid.py | 1 +
dvc/utils/build.py | 1 +
1 file changed, 1 insertion(+)
create mode 100644 dvc/utils/buid.py
create mode 100644 dvc/utils/build.py

diff --git a/dvc/utils/buid.py b/dvc/utils/buid.py
diff --git a/dvc/utils/build.py b/dvc/utils/build.py
new file mode 100644
index 00000000..ada7a0bb
--- /dev/null
+++ b/dvc/utils/buid.py
+++ b/dvc/utils/build.py
@@ -0,0 +1 @@
+PKG = "windows"
+PKG = "exe"
--
2.17.1

0 comments on commit e1dfb75

Please sign in to comment.