Remove references to pygments+babel being optional
This commit is contained in:
parent
3644dc0619
commit
161777d679
1 changed files with 25 additions and 51 deletions
|
|
@ -20,6 +20,7 @@ import logging
|
||||||
import argparse
|
import argparse
|
||||||
import importlib
|
import importlib
|
||||||
import functools
|
import functools
|
||||||
|
import babel.numbers as bn
|
||||||
|
|
||||||
# set the SIGPIPE handler to kill the program instead of
|
# set the SIGPIPE handler to kill the program instead of
|
||||||
# ending in a write error when a broken pipe occurs
|
# ending in a write error when a broken pipe occurs
|
||||||
|
|
@ -292,7 +293,6 @@ def load_lexers():
|
||||||
global context
|
global context
|
||||||
# load available pygments lexers
|
# load available pygments lexers
|
||||||
lexers = []
|
lexers = []
|
||||||
try:
|
|
||||||
global get_lexer_by_name
|
global get_lexer_by_name
|
||||||
from pygments.lexers import get_lexer_by_name
|
from pygments.lexers import get_lexer_by_name
|
||||||
|
|
||||||
|
|
@ -306,9 +306,6 @@ def load_lexers():
|
||||||
from pygments.formatters import TerminalFormatter
|
from pygments.formatters import TerminalFormatter
|
||||||
|
|
||||||
from pygments.lexers import get_all_lexers
|
from pygments.lexers import get_all_lexers
|
||||||
except ImportError:
|
|
||||||
logging.warning("the pygments module has not been found, syntax coloring is not available")
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
for lexer in get_all_lexers():
|
for lexer in get_all_lexers():
|
||||||
try:
|
try:
|
||||||
|
|
@ -411,23 +408,11 @@ def color_scale( name, text ):
|
||||||
nb = "".join([i for i in filter(allowed.__contains__, text)])
|
nb = "".join([i for i in filter(allowed.__contains__, text)])
|
||||||
|
|
||||||
# interpret as decimal
|
# interpret as decimal
|
||||||
# First, try with the babel module, if available
|
|
||||||
# if not, use python itself,
|
|
||||||
# if thoses fails, try to `eval` the string
|
|
||||||
# (this allow strings like "1/2+0.9*2")
|
|
||||||
f = None
|
f = None
|
||||||
try:
|
|
||||||
# babel is a specialized module
|
|
||||||
import babel.numbers as bn
|
|
||||||
try:
|
try:
|
||||||
f = float(bn.parse_decimal(nb))
|
f = float(bn.parse_decimal(nb))
|
||||||
except bn.NumberFormatError:
|
except bn.NumberFormatError:
|
||||||
pass
|
pass
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
f = float(nb)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
if f is not None:
|
if f is not None:
|
||||||
# normalize with scale if it's a number
|
# normalize with scale if it's a number
|
||||||
f = (f - context["scale"][0]) / (context["scale"][1]-context["scale"][0])
|
f = (f - context["scale"][0]) / (context["scale"][1]-context["scale"][0])
|
||||||
|
|
@ -832,11 +817,6 @@ def _args_parse(argv, usage=""):
|
||||||
help="A regular expression")
|
help="A regular expression")
|
||||||
|
|
||||||
pygments_warn=" You can use a language name to activate syntax coloring (see `-r all` for a list)."
|
pygments_warn=" You can use a language name to activate syntax coloring (see `-r all` for a list)."
|
||||||
try:
|
|
||||||
import pygments
|
|
||||||
except ImportError:
|
|
||||||
pygments_warn=" (WARNING: python3-pygments is not available, \
|
|
||||||
install it if you want to be able to use syntax coloring)"
|
|
||||||
|
|
||||||
parser.add_argument("color", metavar="COLOR", type=str, nargs='?',
|
parser.add_argument("color", metavar="COLOR", type=str, nargs='?',
|
||||||
default="red",
|
default="red",
|
||||||
|
|
@ -856,12 +836,6 @@ def _args_parse(argv, usage=""):
|
||||||
(cycle the colors at each match)")
|
(cycle the colors at each match)")
|
||||||
|
|
||||||
babel_warn=" (numbers will be parsed according to your locale)"
|
babel_warn=" (numbers will be parsed according to your locale)"
|
||||||
try:
|
|
||||||
# babel is a specialized module
|
|
||||||
import babel.numbers
|
|
||||||
except ImportError:
|
|
||||||
babel_warn=" (WARNING: python3-babel is not available, install it \
|
|
||||||
if you want to be able to parse numbers according to your locale)"
|
|
||||||
|
|
||||||
parser.add_argument("-l", "--scale", metavar="SCALE",
|
parser.add_argument("-l", "--scale", metavar="SCALE",
|
||||||
help="When using the 'scale' colormap, parse matches as decimal numbers \
|
help="When using the 'scale' colormap, parse matches as decimal numbers \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue