From 39a15a669a2997c0b2bbd89dae943b5341dcf0fa Mon Sep 17 00:00:00 2001 From: Lars Yencken Date: Wed, 21 Aug 2013 19:33:09 +1000 Subject: [PATCH] Make Pygments a soft dependency. --- cheat | 19 ++++++++++++++----- setup.py | 1 - 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cheat b/cheat index 2f5062d..9f78aaa 100755 --- a/cheat +++ b/cheat @@ -2,10 +2,14 @@ import os import sys -from pygments import highlight -from pygments.util import ClassNotFound -from pygments.lexers import get_lexer_for_filename, TextLexer -from pygments.formatters import TerminalFormatter +try: + from pygments import highlight + from pygments.util import ClassNotFound + from pygments.lexers import get_lexer_for_filename, TextLexer + from pygments.formatters import TerminalFormatter + USE_PYGMENTS = True +except ImportError: + USE_PYGMENTS = False def cheat_directories(): @@ -63,7 +67,12 @@ def main(): # print the cheatsheet if it exists if keyphrase in cheatsheets: filename = os.path.join(cheatsheets[keyphrase], keyphrase) - pretty_print(filename) + if USE_PYGMENTS: + pretty_print(filename) + else: + with open(filename) as istream: + for l in istream: + sys.stdout.write(l) # if it does not, say so else: diff --git a/setup.py b/setup.py index 4b10199..f4fd1c8 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,5 @@ setup(name='cheat', packages=['cheatsheets'], package_data={'cheatsheets': [f for f in os.listdir('cheatsheets') if '.' not in f]}, - install_requires=['Pygments>=1.6'], scripts=['cheat'] )