Skip to content

Commit

Permalink
OTHERS: Fix linting issues (manrajgrover#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
manrajgrover authored Oct 20, 2018
2 parents 617032f + b7df5ef commit 149c0d6
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ cover/

# tests
tests/*.txt

# OS-specific files
.DS_Store
27 changes: 14 additions & 13 deletions halo/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import six
try:
from shutil import get_terminal_size
except:
except ImportError:
from backports.shutil_get_terminal_size import get_terminal_size

from colorama import init
Expand All @@ -17,7 +17,7 @@

def is_supported():
"""Check whether operating system supports main symbols or not.
Returns
-------
boolean
Expand All @@ -31,6 +31,7 @@ def is_supported():

return False


def get_environment():
"""Get the environment in which halo is running
Expand All @@ -43,31 +44,31 @@ def get_environment():
from IPython import get_ipython
except ImportError:
return 'terminal'

try:
shell = get_ipython().__class__.__name__

if shell == 'ZMQInteractiveShell': # Jupyter notebook or qtconsole
if shell == 'ZMQInteractiveShell': # Jupyter notebook or qtconsole
return 'jupyter'
elif shell == 'TerminalInteractiveShell': # Terminal running IPython
elif shell == 'TerminalInteractiveShell': # Terminal running IPython
return 'ipython'
else:
return 'terminal' # Other type (?)
return 'terminal' # Other type (?)

except NameError:
return 'terminal'


def colored_frame(frame, color):
"""Color the frame with given color and returns.
Parameters
----------
frame : str
Frame to be colored
color : str
Color to be applied
Returns
-------
str
Expand All @@ -78,12 +79,12 @@ def colored_frame(frame, color):

def is_text_type(text):
"""Check if given parameter is a string or not
Parameters
----------
text : *
Parameter to be checked for text type
Returns
-------
bool
Expand All @@ -97,20 +98,20 @@ def is_text_type(text):

def decode_utf_8_text(text):
"""Decode the text from utf-8 format
Parameters
----------
text : str
String to be decoded
Returns
-------
str
Decoded string
"""
try:
return codecs.decode(text, 'utf-8')
except:
except (TypeError, ValueError):
return text


Expand Down
12 changes: 6 additions & 6 deletions halo/halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# pylint: disable=unsubscriptable-object
"""Beautiful terminal spinners in Python.
"""
from __future__ import unicode_literals, absolute_import
from __future__ import absolute_import, unicode_literals

import atexit
import functools
import sys
import threading
import time
import functools
import atexit

import cursor
from spinners.spinners import Spinners
from log_symbols.symbols import LogSymbols
from spinners.spinners import Spinners

from halo._utils import colored_frame, is_text_type, decode_utf_8_text, get_terminal_columns, \
get_environment, is_supported
from halo._utils import (colored_frame, decode_utf_8_text, get_environment,
get_terminal_columns, is_supported, is_text_type)


class Halo(object):
Expand Down
2 changes: 1 addition & 1 deletion halo/halo_notebook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import unicode_literals, absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals

import sys
import threading
Expand Down
18 changes: 8 additions & 10 deletions tests/_utils.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
"""Utilities for tests.
"""
import errno
import codecs
import os
import re


def strip_ansi(string):
"""Strip ANSI encoding from given string.
Parameters
----------
string : str
String from which encoding needs to be removed
Returns
-------
str
Expand All @@ -25,37 +23,37 @@ def strip_ansi(string):

def decode_utf_8_text(text):
"""Decodes the text from utf-8 format.
Parameters
----------
text : str
Text to be decoded
Returns
-------
str
Decoded text
"""
try:
return codecs.decode(text, 'utf-8')
except:
except (TypeError, ValueError):
return text


def encode_utf_8_text(text):
"""Encodes the text to utf-8 format
Parameters
----------
text : str
Text to be encoded
Returns
-------
str
Encoded text
"""
try:
return codecs.encode(text, 'utf-8')
except:
except (TypeError, ValueError):
return text
4 changes: 2 additions & 2 deletions tests/test_halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

from spinners.spinners import Spinners

from tests._utils import strip_ansi, encode_utf_8_text, decode_utf_8_text
from halo import Halo
from halo._utils import is_supported, get_terminal_columns
from halo._utils import get_terminal_columns, is_supported
from tests._utils import decode_utf_8_text, encode_utf_8_text, strip_ansi

if sys.version_info.major == 2:
get_coded_text = encode_utf_8_text
Expand Down
6 changes: 3 additions & 3 deletions tests/test_halo_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import os
import re
import sys
import unittest
import time
import unittest

from spinners.spinners import Spinners

from tests._utils import strip_ansi, encode_utf_8_text, decode_utf_8_text
from halo import HaloNotebook
from halo._utils import is_supported, get_terminal_columns
from halo._utils import get_terminal_columns, is_supported
from tests._utils import decode_utf_8_text, encode_utf_8_text, strip_ansi

if sys.version_info.major == 2:
get_coded_text = encode_utf_8_text
Expand Down

0 comments on commit 149c0d6

Please sign in to comment.