Skip to content

Commit 355acea

Browse files
committed
The packages regex and pygments slow down and in big ways increase the size of my zipapp, so this allows a leaner deployment.
1 parent af0b8df commit 355acea

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

Diff for: PyInquirer/utils.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import sys
55
from pprint import pprint
66

7-
from pygments import highlight, lexers, formatters
8-
97
__version__ = '0.1.2'
108

119
PY3 = sys.version_info[0] >= 3
@@ -16,16 +14,20 @@ def format_json(data):
1614

1715

1816
def colorize_json(data):
19-
if PY3:
20-
if isinstance(data, bytes):
21-
data = data.decode('UTF-8')
22-
else:
23-
if not isinstance(data, unicode):
24-
data = unicode(data, 'UTF-8')
25-
colorful_json = highlight(data,
26-
lexers.JsonLexer(),
27-
formatters.TerminalFormatter())
28-
return colorful_json
17+
try:
18+
from pygments import highlight, lexers, formatters
19+
if PY3:
20+
if isinstance(data, bytes):
21+
data = data.decode('UTF-8')
22+
else:
23+
if not isinstance(data, unicode):
24+
data = unicode(data, 'UTF-8')
25+
colorful_json = highlight(data,
26+
lexers.JsonLexer(),
27+
formatters.TerminalFormatter())
28+
return colorful_json
29+
except ModuleNotFoundError:
30+
return data
2931

3032

3133
def print_json(data):

Diff for: requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
prompt_toolkit>=1.0.16,<1.1
22
Pygments>=2.2.0
3-
regex>=2016.11.21

Diff for: requirements_dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pytest-html>=1.10.1
1111
pytest-xdist>=1.15.0
1212
pylint>=1.6.5
1313
ptyprocess==0.5.1
14+
regex>=2016.11.21
1415

1516
# build-tools
1617
pep8>=1.7.0

0 commit comments

Comments
 (0)