Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
1,098 additions
and
534 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# built-in | ||
from pathlib import Path | ||
from typing import Iterator | ||
|
||
import pygments | ||
from pygments.formatters import TerminalFormatter | ||
from pygments.lexers import PythonLexer | ||
|
||
|
||
COLORS = dict( | ||
red='\033[91m', | ||
green='\033[92m', | ||
yellow='\033[93m', | ||
blue='\033[94m', | ||
magenta='\033[95m', | ||
end='\033[0m', | ||
) | ||
NOCOLORS = dict( | ||
red='', | ||
green='', | ||
yellow='', | ||
blue='', | ||
magenta='', | ||
end='', | ||
) | ||
|
||
|
||
def highlight(source: str) -> str: | ||
source = pygments.highlight( | ||
code=source, | ||
lexer=PythonLexer(), | ||
formatter=TerminalFormatter(), | ||
) | ||
return source.rstrip() | ||
|
||
|
||
def get_paths(path: Path) -> Iterator[Path]: | ||
"""Recursively yields python files. | ||
""" | ||
if not path.exists(): | ||
raise FileNotFoundError(str(path)) | ||
if path.is_file(): | ||
if path.suffix == '.py': | ||
yield path | ||
return | ||
for subpath in path.iterdir(): | ||
if subpath.name[0] == '.': | ||
continue | ||
if subpath.name == '__pycache__': | ||
continue | ||
yield from get_paths(subpath) |
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
Oops, something went wrong.