Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap with drop-in API replacement working on Windows as well #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ package:
source:
url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz
sha256: f69135080b2668b662822633312c2180002c10111597af9631bb02e042755b6c
patches:
- patches/0001-Switch-to-blessed.patch
- patches/0002-Do-not-use-signal-on-Windows.patch
- patches/0003-Use-default-value-for-time-formatting-on-Windows.patch
- patches/0004-Replace-CRLF-with-LF.patch

build:
noarch: python
Expand All @@ -17,6 +22,8 @@ build:
- gpustat = gpustat:main

requirements:
build:
- m2-patch # [win]
host:
- python >=3.5
- pip
Expand All @@ -26,7 +33,7 @@ requirements:
- python >=3.5
- nvidia-ml
- psutil
- blessings >=1.6
- blessed >=1.6
- six >=1.7

test:
Expand All @@ -51,3 +58,4 @@ about:
extra:
recipe-maintainers:
- hadim
- vnlitvinov
40 changes: 40 additions & 0 deletions recipe/patches/0001-Switch-to-blessed.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
From 8265e2bfb4f22d370ac9d65dde08318dc2081bbc Mon Sep 17 00:00:00 2001
From: Vasily Litvinov <[email protected]>
Date: Tue, 24 Nov 2020 16:24:42 +0300
Subject: [PATCH 1/4] Switch to blessed

Signed-off-by: Litvinov <[email protected]>
---
gpustat/__main__.py | 2 +-
gpustat/core.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gpustat/__main__.py b/gpustat/__main__.py
index 127973e..76704f0 100644
--- a/gpustat/__main__.py
+++ b/gpustat/__main__.py
@@ -5,7 +5,7 @@ from __future__ import print_function
import sys
import time

-from blessings import Terminal
+from blessed import Terminal

from gpustat import __version__
from .core import GPUStatCollection
diff --git a/gpustat/core.py b/gpustat/core.py
index 6e762aa..73d3534 100644
--- a/gpustat/core.py
+++ b/gpustat/core.py
@@ -22,7 +22,7 @@ from six.moves import cStringIO as StringIO

import psutil
import pynvml as N
-from blessings import Terminal
+from blessed import Terminal

NOT_SUPPORTED = 'Not Supported'
MB = 1024 * 1024
--
2.29.2.windows.2

31 changes: 31 additions & 0 deletions recipe/patches/0002-Do-not-use-signal-on-Windows.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 328216a1558c0ffd0fb9b2d13b9469946a566286 Mon Sep 17 00:00:00 2001
From: Vasily Litvinov <[email protected]>
Date: Tue, 24 Nov 2020 16:36:23 +0300
Subject: [PATCH 2/4] Do not use signal on Windows

Signed-off-by: Vasily Litvinov <[email protected]>
---
gpustat/__main__.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gpustat/__main__.py b/gpustat/__main__.py
index 76704f0..984dae1 100644
--- a/gpustat/__main__.py
+++ b/gpustat/__main__.py
@@ -59,9 +59,10 @@ def main(*argv):
if not argv:
argv = list(sys.argv)

- # attach SIGPIPE handler to properly handle broken pipe
- import signal
- signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+ if sys.platform != 'win32':
+ # attach SIGPIPE handler to properly handle broken pipe
+ import signal
+ signal.signal(signal.SIGPIPE, signal.SIG_DFL)

# arguments to gpustat
import argparse
--
2.29.2.windows.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From a1d8dde8849cd9bfd089fd667fe9e20e9122f9e8 Mon Sep 17 00:00:00 2001
From: Vasily Litvinov <[email protected]>
Date: Tue, 24 Nov 2020 16:48:07 +0300
Subject: [PATCH 3/4] Use default value for time formatting on Windows

Signed-off-by: Vasily Litvinov <[email protected]>
---
gpustat/core.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gpustat/core.py b/gpustat/core.py
index 73d3534..73d4e0b 100644
--- a/gpustat/core.py
+++ b/gpustat/core.py
@@ -450,7 +450,11 @@ class GPUStatCollection(object):

# header
if show_header:
- time_format = locale.nl_langinfo(locale.D_T_FMT)
+ try:
+ time_format = locale.nl_langinfo(locale.D_T_FMT)
+ except AttributeError:
+ # nl_langinfo is missing on Windows, use locale-dependent format
+ time_format = '%c'

header_template = '{t.bold_white}{hostname:{width}}{t.normal} '
header_template += '{timestr} '
--
2.29.2.windows.2

26 changes: 26 additions & 0 deletions recipe/patches/0004-Replace-CRLF-with-LF.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 8ebc2fb1977eccc188c86d9582e1212f7bbe29c0 Mon Sep 17 00:00:00 2001
From: Vasily Litvinov <[email protected]>
Date: Tue, 24 Nov 2020 17:01:34 +0300
Subject: [PATCH 4/4] Replace CRLF with LF

Signed-off-by: Vasily Litvinov <[email protected]>
---
gpustat/test_gpustat.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gpustat/test_gpustat.py b/gpustat/test_gpustat.py
index 35244e3..8ef9bd2 100644
--- a/gpustat/test_gpustat.py
+++ b/gpustat/test_gpustat.py
@@ -173,7 +173,7 @@ def remove_ansi_codes(s):
import re
s = re.compile(r'\x1b[^m]*m').sub('', s)
s = re.compile(r'\x0f').sub('', s)
- return s
+ return s.replace('\r\n', '\n')


class TestGPUStat(unittest.TestCase):
--
2.29.2.windows.2