mirror of https://github.com/cheat/cheat.git
Make Pygments a soft dependency.
This commit is contained in:
parent
c6bb350a13
commit
39a15a669a
19
cheat
19
cheat
|
@ -2,10 +2,14 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pygments import highlight
|
try:
|
||||||
from pygments.util import ClassNotFound
|
from pygments import highlight
|
||||||
from pygments.lexers import get_lexer_for_filename, TextLexer
|
from pygments.util import ClassNotFound
|
||||||
from pygments.formatters import TerminalFormatter
|
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():
|
def cheat_directories():
|
||||||
|
@ -63,7 +67,12 @@ def main():
|
||||||
# print the cheatsheet if it exists
|
# print the cheatsheet if it exists
|
||||||
if keyphrase in cheatsheets:
|
if keyphrase in cheatsheets:
|
||||||
filename = os.path.join(cheatsheets[keyphrase], keyphrase)
|
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
|
# if it does not, say so
|
||||||
else:
|
else:
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -12,6 +12,5 @@ setup(name='cheat',
|
||||||
packages=['cheatsheets'],
|
packages=['cheatsheets'],
|
||||||
package_data={'cheatsheets': [f for f in os.listdir('cheatsheets')
|
package_data={'cheatsheets': [f for f in os.listdir('cheatsheets')
|
||||||
if '.' not in f]},
|
if '.' not in f]},
|
||||||
install_requires=['Pygments>=1.6'],
|
|
||||||
scripts=['cheat']
|
scripts=['cheat']
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue