Skip to content

Commit

Permalink
Colorise
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauko Quiroga committed Sep 30, 2021
1 parent cee5632 commit 9df95a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
36 changes: 29 additions & 7 deletions openfisca_tasks/_check_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import textwrap
from typing import Sequence

import termcolor
from typing_extensions import Literal

EXIT_OK: Literal[0]
Expand All @@ -14,6 +15,24 @@
EXIT_KO: Literal[1]
EXIT_KO = 1

WORK: str
WORK = termcolor.colored("[/]", "cyan")

WARN: str
WARN = termcolor.colored("[i]", "yellow")

FAIL: str
FAIL = termcolor.colored("[!]", "red")

BAR: str
BAR = termcolor.colored("|", "green")

ETA: str
ETA = termcolor.colored("✓", "green")

ACC: str
ACC = termcolor.colored("·", "green")

FILES: Sequence[str]
FILES = \
subprocess \
Expand Down Expand Up @@ -153,7 +172,7 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
since, expires = keywords

message = [
f"[i] {module}.{node.name}:{lineno} =>",
f"{WARN} {module}.{node.name}:{lineno} =>",
f"Deprecated since: {since}.",
f"Expiration status: {expires}",
f"(current: {self.version}).",
Expand All @@ -165,7 +184,7 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
# will exit with an error.
if self._isthis(expires):
self.exit = EXIT_KO
sys.stdout.write("\r[!]")
sys.stdout.write(f"\r{FAIL}")

sys.stdout.write("\n")

Expand All @@ -180,7 +199,7 @@ def _node(self, file: str) -> ast.Module:
return ast.parse(source, file, "exec")

def __init_progress__(self) -> None:
sys.stdout.write(f"[/] 0% |{'·' * 50}|\r")
sys.stdout.write(f"{WORK} 0% {BAR}{ACC * 50}{BAR}\r")

def __push_progress__(self) -> None:
doner: int
Expand All @@ -192,11 +211,14 @@ def __push_progress__(self) -> None:
space += [' ', ''][doner >= 10]

sys.stdout.write(
f"[/] {doner}% {space}|"
f"{'█' * (doner // 2)}"
f"{'·' * (50 - doner // 2)}"
"|\r"
f"{WORK} {doner}% {space}{BAR}"
f"{ETA * (doner // 2)}"
f"{ACC * (50 - doner // 2)}"
f"{BAR}\r"
)

import time
time.sleep(.1)

def __wipe_progress__(self) -> None:
sys.stdout.write(f"{' ' * 100}\r")
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'openfisca-country-template >= 3.10.0, < 4.0.0',
'openfisca-extension-template >= 1.2.0rc0, < 2.0.0',
'pytest-cov >= 2.6.1, < 3.0.0',
'termcolor == 1.1.0',
'typing-extensions == 3.10.0.2',
] + api_requirements

Expand Down

0 comments on commit 9df95a5

Please sign in to comment.