-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mod] makes pygments optional in the code
- Loading branch information
1 parent
1055678
commit 6db0114
Showing
5 changed files
with
57 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,13 @@ | |
import re | ||
import sys | ||
|
||
from pygments.token import Comment, Text, String, Keyword, Name, Operator | ||
from pygments.lexer import RegexLexer, bygroups | ||
|
||
from baron.utils import python_version | ||
|
||
from redbaron.private_config import DEBUG | ||
from redbaron.private_config import DEBUG, HAS_PYGMENTS | ||
|
||
if HAS_PYGMENTS: | ||
from pygments.token import Comment, Text, String, Keyword, Name, Operator | ||
from pygments.lexer import RegexLexer, bygroups | ||
This comment has been minimized.
Sorry, something went wrong.
ibizaman
Collaborator
|
||
|
||
if python_version == 3: | ||
from io import StringIO | ||
|
@@ -65,18 +66,22 @@ def truncate(text, n): | |
return "".join(truncated) | ||
|
||
|
||
class HelpLexer(RegexLexer): | ||
name = 'Lexer for RedBaron .help() method output' | ||
|
||
tokens = { | ||
'root': [ | ||
(r"#.*$", Comment), | ||
(r"('([^\\']|\\.)*'|\"([^\\\"]|\\.)*\")", String), | ||
(r"(None|False|True)", String), | ||
(r'(\*)( \w+Node)', bygroups(Operator, Keyword)), | ||
(r'\w+Node', Name.Function), | ||
(r'(\*|=|->|\(|\)|\.\.\.)', Operator), | ||
(r'\w+', Text), | ||
(r'\s+', Text), | ||
] | ||
} | ||
if HAS_PYGMENTS: | ||
class HelpLexer(RegexLexer): | ||
name = 'Lexer for RedBaron .help() method output' | ||
|
||
tokens = { | ||
'root': [ | ||
(r"#.*$", Comment), | ||
(r"('([^\\']|\\.)*'|\"([^\\\"]|\\.)*\")", String), | ||
(r"(None|False|True)", String), | ||
(r'(\*)( \w+Node)', bygroups(Operator, Keyword)), | ||
(r'\w+Node', Name.Function), | ||
(r'(\*|=|->|\(|\)|\.\.\.)', Operator), | ||
(r'\w+', Text), | ||
(r'\s+', Text), | ||
] | ||
} | ||
else: | ||
class HelpLexer(object): | ||
pass |
and what about defining something like
Instead of adding a
if
everywhere?