diff --git a/pyproject.toml b/pyproject.toml index 9787c3b..1abca0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" + +[tool.mypy] +ignore_missing_imports = true diff --git a/setup.cfg b/setup.cfg index dd4fe00..7777499 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,6 +16,7 @@ classifiers = packages = tlfi python_requires = >= 3.7 setup_requires = setuptools >= 38.3.0 +install_requires = blessings ~= 1.6 [options.entry_points] console_scripts = diff --git a/tlfi/__main__.py b/tlfi/__main__.py index 88d713e..c210f60 100644 --- a/tlfi/__main__.py +++ b/tlfi/__main__.py @@ -15,17 +15,10 @@ import sys from pathlib import Path from typing import Generator +from blessings import Terminal from bs4 import BeautifulSoup, NavigableString -try: - from blessings import Terminal - t = Terminal() -except ImportError: - class DummyTerminal: - def __getattr__(self, _): - return "" - t = DummyTerminal() - +T = Terminal() TAG_STRIP_RE = re.compile(r"\s+") @@ -84,17 +77,17 @@ def parse_tag(tag) -> str: if tag.name == "span": classes = tag.get("class") or [] if "tlf_cdefinition" in classes: - content = f"{t.yellow}{content}{t.normal}" + content = f"{T.yellow}{content}{T.normal}" if "tlf_cdomaine" in classes: - content = f"{t.red}{content}{t.normal}" + content = f"{T.red}{content}{T.normal}" if "tlf_csyntagme" in classes: - content = f"{t.green}{content}{t.normal}" + content = f"{T.green}{content}{T.normal}" if "tlf_cmot" in classes: - content = f"{t.reverse}{content}{t.normal}" + content = f"{T.reverse}{content}{T.normal}" if tag.name == "b": - content = f"{t.bold}{content}{t.normal}" + content = f"{T.bold}{content}{T.normal}" if tag.name == "i": - content = f"{t.italic}{content}{t.no_italic}" + content = f"{T.italic}{content}{T.no_italic}" return content