From 9385c8166256bc85c5c4b985fab6b749d070ba68 Mon Sep 17 00:00:00 2001 From: Taybin Rutkin Date: Tue, 26 Oct 2021 14:17:46 -0400 Subject: [PATCH] Remove outdated colorclass library (#204) * Remove outdated colorclass library * remove unnecessary list comprehension * update documentation --- docs/userguide/cli.rst | 1 - faust/cli/agents.py | 4 +-- faust/cli/base.py | 45 ---------------------------- faust/cli/model.py | 8 ++--- faust/cli/models.py | 4 +-- faust/cli/tables.py | 2 +- faust/cli/worker.py | 4 +-- requirements/requirements.txt | 1 - tests/integration/cli/test_agents.py | 6 ---- tests/integration/cli/test_model.py | 9 ------ tests/integration/cli/test_models.py | 6 ---- tests/integration/conftest.py | 9 +----- tests/unit/cli/test_base.py | 18 ----------- 13 files changed, 12 insertions(+), 105 deletions(-) diff --git a/docs/userguide/cli.rst b/docs/userguide/cli.rst index 4a1832f51..d6ca1cb50 100644 --- a/docs/userguide/cli.rst +++ b/docs/userguide/cli.rst @@ -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 /. diff --git a/faust/cli/agents.py b/faust/cli/agents.py index fb99c9211..b5c08503a 100644 --- a/faust/cli/agents.py +++ b/faust/cli/agents.py @@ -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: diff --git a/faust/cli/base.py b/faust/cli/base.py index e93994143..456c701b7 100644 --- a/faust/cli/base.py +++ b/faust/cli/base.py @@ -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 @@ -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 @@ -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", @@ -463,7 +455,6 @@ def _prepare_cli( workdir: str, datadir: str, json: bool, - no_color: bool, loop: str, ) -> None: """Faust command-line interface.""" @@ -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()) @@ -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): @@ -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] @@ -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 @@ -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. @@ -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 @@ -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)) diff --git a/faust/cli/model.py b/faust/cli/model.py index 2945eb077..81dd9d6ff 100644 --- a/faust/cli/model.py +++ b/faust/cli/model.py @@ -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, ) @@ -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: @@ -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: diff --git a/faust/cli/models.py b/faust/cli/models.py index 06225cee7..03b94cc63 100644 --- a/faust/cli/models.py +++ b/faust/cli/models.py @@ -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: diff --git a/faust/cli/tables.py b/faust/cli/tables.py index e4e1156ce..1b7c558f2 100644 --- a/faust/cli/tables.py +++ b/faust/cli/tables.py @@ -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, diff --git a/faust/cli/worker.py b/faust/cli/worker.py index 6b2a571cf..4e857869a 100644 --- a/faust/cli/worker.py +++ b/faust/cli/worker.py @@ -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 @@ -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.""" diff --git a/requirements/requirements.txt b/requirements/requirements.txt index dfe8382e5..99bc31ff4 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -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 diff --git a/tests/integration/cli/test_agents.py b/tests/integration/cli/test_agents.py index 7eba2f338..e25cacec4 100644 --- a/tests/integration/cli/test_agents.py +++ b/tests/integration/cli/test_agents.py @@ -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 diff --git a/tests/integration/cli/test_model.py b/tests/integration/cli/test_model.py index dc80d2ef5..7f2e4b037 100644 --- a/tests/integration/cli/test_model.py +++ b/tests/integration/cli/test_model.py @@ -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): @@ -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 diff --git a/tests/integration/cli/test_models.py b/tests/integration/cli/test_models.py index ea4ac8feb..69c9c412b 100644 --- a/tests/integration/cli/test_models.py +++ b/tests/integration/cli/test_models.py @@ -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 diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 25f3ccc9a..e7ad51ea0 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -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",) @@ -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) diff --git a/tests/unit/cli/test_base.py b/tests/unit/cli/test_base.py index aee9f8b54..155891efe 100644 --- a/tests/unit/cli/test_base.py +++ b/tests/unit/cli/test_base.py @@ -201,7 +201,6 @@ def Test__prepare_cli(): workdir="/foo", datadir="/data", json=True, - no_color=False, loop="foo", ) @@ -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 @@ -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()) @@ -242,7 +239,6 @@ def Test__prepare_cli(): workdir="/foo", datadir="/data", json=True, - no_color=False, loop="foo", ) dac.assert_called_once_with() @@ -256,7 +252,6 @@ def Test__prepare_cli(): workdir="/foo", datadir="/data", json=False, - no_color=True, loop="foo", ) eac.assert_not_called() @@ -269,7 +264,6 @@ def Test__prepare_cli(): workdir=None, datadir=None, json=False, - no_color=True, loop="foo", ) finally: @@ -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)