Skip to content

Commit

Permalink
Remove outdated colorclass library (faust-streaming#204)
Browse files Browse the repository at this point in the history
* Remove outdated colorclass library

* remove unnecessary list comprehension

* update documentation
  • Loading branch information
taybin authored Oct 26, 2021
1 parent 4c1efbd commit 9385c81
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 105 deletions.
1 change: 0 additions & 1 deletion docs/userguide/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ Example:
--json / --no-json Prefer data to be emitted in json format.
-D, --datadir DIRECTORY Directory to keep application state.
-W, --workdir DIRECTORY Working directory to change to after start.
--no-color / --color Enable colors in output.
--debug / --no-debug Enable debugging output, and the blocking
detector.
-q, --quiet / --no-quiet Silence output to <stdout>/<stderr>.
Expand Down
4 changes: 2 additions & 2 deletions faust/cli/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def agents(self, *, local: bool = False) -> Sequence[AgentT]:
def agent_to_row(self, agent: AgentT) -> Sequence[str]:
"""Convert agent fields to terminal table row."""
return [
self.bold_tail(self._name(agent)),
self._name(agent),
self._topic(agent),
self.dark(self._help(agent)),
self._help(agent),
]

def _name(self, agent: AgentT) -> str:
Expand Down
45 changes: 0 additions & 45 deletions faust/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import click
from click import echo
from colorclass import Color, disable_all_colors, enable_all_colors
from mode import Service, ServiceT, Worker
from mode.utils import text
from mode.utils.compat import want_bytes
Expand Down Expand Up @@ -152,7 +151,6 @@ class State:
workdir: Optional[str] = None
datadir: Optional[str] = None
json: bool = False
no_color: bool = False
loop: Optional[str] = None
logfile: Optional[str] = None
loglevel: Optional[int] = None
Expand Down Expand Up @@ -228,12 +226,6 @@ def _callback(
default=DEBUG,
help="Enable debugging output, and the blocking detector.",
),
option(
"--no-color/--color",
"--no_color/--color",
default=False,
help="Enable colors in output.",
),
option(
"--workdir",
"-W",
Expand Down Expand Up @@ -463,7 +455,6 @@ def _prepare_cli(
workdir: str,
datadir: str,
json: bool,
no_color: bool,
loop: str,
) -> None:
"""Faust command-line interface."""
Expand All @@ -474,7 +465,6 @@ def _prepare_cli(
state.workdir = workdir
state.datadir = datadir
state.json = json
state.no_color = no_color
state.loop = loop

root = cast(_FaustRootContextT, ctx.find_root())
Expand All @@ -489,12 +479,6 @@ def _prepare_cli(
# WARNING: Note that the faust.app module *MUST not* have
# been imported before setting the envvar.
os.environ["F_DATADIR"] = datadir
if not no_color and terminal.isatty(sys.stdout):
enable_all_colors()
else:
disable_all_colors()
if json:
disable_all_colors()


class Command(abc.ABC):
Expand All @@ -521,7 +505,6 @@ class Command(abc.ABC):
workdir: str
datadir: str
json: bool
no_color: bool
logfile: str
_loglevel: Optional[str]
_blocking_timeout: Optional[float]
Expand Down Expand Up @@ -596,7 +579,6 @@ def __init__(self, ctx: click.Context, *args: Any, **kwargs: Any) -> None:
self.workdir = self.state.workdir
self.datadir = self.state.datadir
self.json = self.state.json
self.no_color = self.state.no_color
self.logfile = self.state.logfile
self.stdout = root.stdout or sys.stdout
self.stderr = root.stderr or sys.stderr
Expand Down Expand Up @@ -691,7 +673,6 @@ def tabulate(
headers: Sequence[str] = None,
wrap_last_row: bool = True,
title: str = "",
title_color: str = "blue",
**kwargs: Any,
) -> str:
"""Create an ANSI representation of a table of two-row tuples.
Expand All @@ -708,7 +689,6 @@ def tabulate(
return self._tabulate_json(data, headers=headers)
if headers:
data = [headers] + list(data)
title = self.bold(self.color(title_color, title))
table = self.table(data, title=title, **kwargs)
if wrap_last_row:
# slow, but not big data
Expand All @@ -730,31 +710,6 @@ def table(
"""Format table data as ANSI/ASCII table."""
return terminal.table(data, title=title, target=sys.stdout, **kwargs)

def color(self, name: str, text: str) -> str:
"""Return text having a certain color by name.
Examples::
>>> self.color('blue', 'text_to_color')
>>> self.color('hiblue', text_to_color')
See Also:
:pypi:`colorclass`: for a list of available colors.
"""
return Color(f"{{{name}}}{text}{{/{name}}}")

def dark(self, text: str) -> str:
"""Return cursor text."""
return self.color("autoblack", text)

def bold(self, text: str) -> str:
"""Return text in bold."""
return self.color("b", text)

def bold_tail(self, text: str, *, sep: str = ".") -> str:
"""Put bold emphasis on the last part of a ``foo.bar.baz`` string."""
head, fsep, tail = text.rpartition(sep)
return fsep.join([head, self.bold(tail)])

def _table_wrap(self, table: terminal.Table, text: str) -> str:
max_width = max(table.column_max_width(1), 10)
return "\n".join(wrap(text, max_width))
Expand Down
8 changes: 4 additions & 4 deletions faust/cli/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def run(self, name: str) -> None:
self.say(
self.tabulate(
self.model_fields(model),
headers=[self.bold(h) for h in self.headers],
headers=self.headers,
title=self._name(model),
wrap_last_row=False,
)
Expand All @@ -69,7 +69,7 @@ def field(self, field: FieldDescriptorT) -> Sequence[str]:
return [
field.field,
self._type(field.type),
self.dark("*" if field.required else repr(field.default)),
"*" if field.required else repr(field.default),
]

def _type(self, typ: Any) -> str:
Expand All @@ -78,8 +78,8 @@ def _type(self, typ: Any) -> str:
def model_to_row(self, model: Type[ModelT]) -> Sequence[str]:
"""Convert model to terminal table row."""
return [
self.bold_tail(self._name(model)),
self.dark(self._help(model)),
self._name(model),
self._help(model),
]

def _name(self, model: Type[ModelT]) -> str:
Expand Down
4 changes: 2 additions & 2 deletions faust/cli/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def models(self, builtins: bool) -> Sequence[Type[ModelT]]:
def model_to_row(self, model: Type[ModelT]) -> Sequence[str]:
"""Convert model fields to terminal table columns."""
return [
self.bold_tail(self._name(model)),
self.dark(self._help(model)),
self._name(model),
self._help(model),
]

def _name(self, model: Type[ModelT]) -> str:
Expand Down
2 changes: 1 addition & 1 deletion faust/cli/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def run(self) -> None:
self.say(
self.tabulate(
[
(self.bold(table.name), self.dark(table.help or DEFAULT_TABLE_HELP))
(table.name, table.help or DEFAULT_TABLE_HELP)
for table in self.app.tables.values()
],
title=self.title,
Expand Down
4 changes: 2 additions & 2 deletions faust/cli/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def banner(self, worker: Worker) -> str:

def _format_banner_table(self, data: TableDataT) -> str:
table = self.table(
[(self.bold(x), str(y)) for x, y in data],
[(x, str(y)) for x, y in data],
title=self._banner_title(),
)
table.inner_heading_row_border = False
Expand Down Expand Up @@ -176,7 +176,7 @@ def _driver_versions(self, app: AppT) -> List[str]:

def faust_ident(self) -> str:
"""Return Faust version information as ANSI string."""
return self.color("hiblue", f"{FAUST} v{faust_version}")
return f"{FAUST} v{faust_version}"

def platform(self) -> str:
"""Return platform identifier as ANSI string."""
Expand Down
1 change: 0 additions & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ aiohttp>=3.5.2,<4.0
aiohttp_cors>=0.7,<2.0
aiokafka>=0.7.1,<0.8.0
click>=6.7,<8.0
colorclass>=2.2,<3.0
mode-streaming==0.1.0
opentracing>=1.3.0,<=2.4.0
terminaltables>=3.1,<4.0
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/cli/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ def test_tabulated(faust):
assert b"@app.mul" in stdout


def test_colors(faust_color):
exitcode, stdout, stderr = faust_color("agents", "--local")
assert not exitcode
assert b"@app.mul" in stdout


def test_json_no_local(faust_json):
exitcode, agents, stderr = faust_json("agents")
assert not exitcode
Expand Down
9 changes: 0 additions & 9 deletions tests/integration/cli/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def test_tabulated(self, faust):
assert not exitcode
assert b"typing.List" in stdout

def test_colors(self, faust_color):
exitcode, stdout, stderr = faust_color("model", "app.Arena")
assert b"typing.List" in stdout


class Test_Point:
def test_json(self, faust_json):
Expand All @@ -32,8 +28,3 @@ def test_tabulated(self, faust):
exitcode, stdout, stderr = faust("model", "app.Point")
assert not exitcode
assert b"int" in stdout

def test_colors(self, faust_color):
exitcode, stdout, stderr = faust_color("model", "app.Point")
assert not exitcode
assert b"int" in stdout
6 changes: 0 additions & 6 deletions tests/integration/cli/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ def test_tabulated(faust):
assert b"Arena" in stdout


def test_colors(faust_color):
exitcode, stdout, stderr = faust_color("models", "--builtins")
assert not exitcode
assert b"Point" in stdout


def test_json_no_local(faust_json):
exitcode, models, stderr = faust_json("models")
assert not exitcode
Expand Down
9 changes: 1 addition & 8 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def main_path() -> Path:


def _create_faust_cli(
executable: Path, *partial_args: str, color: bool = False, json: bool = False
executable: Path, *partial_args: str, json: bool = False
) -> Callable[..., CommandReturns]:
if not color:
partial_args += ("--no-color",)
if json:
partial_args += ("--json",)

Expand Down Expand Up @@ -62,8 +60,3 @@ def faust(main_path: Path) -> Callable[..., CommandReturns]:
@pytest.fixture
def faust_json(main_path: Path):
return _create_faust_cli(main_path, json=True)


@pytest.fixture
def faust_color(main_path: Path) -> Callable[..., CommandReturns]:
return _create_faust_cli(main_path, color=True)
18 changes: 0 additions & 18 deletions tests/unit/cli/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ def Test__prepare_cli():
workdir="/foo",
datadir="/data",
json=True,
no_color=False,
loop="foo",
)

Expand All @@ -211,7 +210,6 @@ def Test__prepare_cli():
assert state.workdir == "/foo"
assert state.datadir == "/data"
assert state.json
assert not state.no_color
assert state.loop == "foo"

root.side_effects = True
Expand All @@ -228,7 +226,6 @@ def Test__prepare_cli():
workdir="/foo",
datadir="/data",
json=False,
no_color=False,
loop="foo",
)
chdir.assert_called_with(Path("/foo").absolute())
Expand All @@ -242,7 +239,6 @@ def Test__prepare_cli():
workdir="/foo",
datadir="/data",
json=True,
no_color=False,
loop="foo",
)
dac.assert_called_once_with()
Expand All @@ -256,7 +252,6 @@ def Test__prepare_cli():
workdir="/foo",
datadir="/data",
json=False,
no_color=True,
loop="foo",
)
eac.assert_not_called()
Expand All @@ -269,7 +264,6 @@ def Test__prepare_cli():
workdir=None,
datadir=None,
json=False,
no_color=True,
loop="foo",
)
finally:
Expand Down Expand Up @@ -426,18 +420,6 @@ def test_table(self, *, command):
assert t is table.return_value
table.assert_called_once_with(data, title="foo", target=sys.stdout)

def test_color(self, *, command):
assert command.color("blue", "text")

def test_dark(self, *, command):
assert command.dark("text")

def test_bold(self, *, command):
assert command.bold("text")

def test_bold_tail(self, *, command):
assert command.bold_tail("foo.bar.baz")

def test_table_wrap(self, *, command):
table = command.table([["A", "B", "C"]])
assert command._table_wrap(table, "fooawqe" * 100)
Expand Down

0 comments on commit 9385c81

Please sign in to comment.