Skip to content

Commit

Permalink
🔧 MAINTAIN: pre-build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
delameter committed Oct 15, 2023
1 parent 70db107 commit 8c91654
Show file tree
Hide file tree
Showing 8 changed files with 444 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ pending
- |DOCS| tracers math
- |REMOVE| `log` module
- |FIX| conflict color tokens are allowed as long as original names differ
- |FIX| `Color16`, `Color256`, `ColorRGB` hash computation

.. <@pending:85a1eff>
.. <@pending:70db107>
.. ^ blank line before should be kept
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ disable = true
[tool.hatch.build.targets.sdist]
include = [
"/pytermor",
"/pytermor/dev",
"/tests",
]

Expand Down
4 changes: 2 additions & 2 deletions pytermor/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# (c) 2022-2023. A. Shavykin <0.delameter@gmail.com>
# Licensed under GNU Lesser General Public License v3.0
# -----------------------------------------------------------------------------
__version__ = '2.106.2'
__updated__ = "2023-10-15 13:48:51+03:00"
__version__ = '2.106.3'
__updated__ = "2023-10-16 00:30:56+03:00"
2 changes: 1 addition & 1 deletion pytermor/cval.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# (c) 2022—2023. A. Shavykin <0.delameter@gmail.com>
# -----------------------------------------------------------------------------
# AUTOGENERATED MODULE
# 2023-10-10T12:52:07.122544
# 2023-10-16T00:29:40.255281
"""
Color preset list:
Expand Down
15 changes: 11 additions & 4 deletions scripts/build_cval.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import yaml

from common import PROJECT_ROOT, CONFIG_PATH, TaskRunner
from pytermor import pad
from pytermor import pad, SgrRenderer, cv
from pytermor.common import filtern
from es7s_commons.progressbar import ProgressBar


class IndexBuilder(TaskRunner):
Expand All @@ -41,8 +42,10 @@ class IndexBuilder(TaskRunner):
def __init__(self):
self._names = set()
self._colors_count = 0
self._pbar = ProgressBar(SgrRenderer(), sys.stderr, cv.MAGENTA)

def _run(self) -> int:
self._pbar.init_tasks(len(self.MODE_TO_SORTER_MAP.keys()), 0)
result = {k: "" for k in self.MODE_TO_SORTER_MAP.keys()}
counts = ""
for mode, sorter in self.MODE_TO_SORTER_MAP.items():
Expand All @@ -63,17 +66,19 @@ def _run(self) -> int:
'counts': counts,
**{f"defs_{k}": v for k, v in result.items()}
}))
self._print_fout_result(fout, self.OUTPUT_DEST_PATH)
self._pbar._echo(self._render_fout_result(fout, self.OUTPUT_DEST_PATH), persist=True)
return self._colors_count

def _run_callback(self, colors_count: int):
print(f"Colors processed: {colors_count}", file=sys.stdout)
self._pbar._echo(f"Colors processed: {colors_count}", persist=True)
self._pbar.close()

def _run_mode(self, mode: str, sorter: t.Callable):
self._pbar.next_task(mode)
config_path = join(CONFIG_PATH, mode + ".yml")
with open(config_path, "rt") as f:
config = yaml.safe_load(f)
self._print_fin_result(f, config_path)
self._pbar._echo(self._render_fin_result(f, config_path), persist=True)
self._colors_mode_class = config.get("class")
self._deferred = config.get("_deferred")

Expand All @@ -87,12 +92,14 @@ def _run_mode(self, mode: str, sorter: t.Callable):
)

color_values = set()
self._pbar.init_steps(len(colors))
for color in colors:
self._colors_count += 1
self._colors_mode_count += 1

var_name = color.get("var_name")
code = str(color.get("code"))
self._pbar.next_step(var_name)
color16_equiv = None
if mode == "xterm_256" and (color16_equiv := color.get("color16_equiv")):
color16_equiv = color.get("color16_equiv")
Expand Down
16 changes: 8 additions & 8 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@


def warning(string: str | pt.IRenderable):
get_stdout().write(pt.render(pt.Fragment("[WARN] ", pt.Styles.WARNING_LABEL) + pt.Text(string, pt.Styles.WARNING)))
get_stdout().write(pt.render(pt.Fragment("[WARN] ", pt.Styles.WARNING_LABEL) + pt.Text(string+'\n', pt.Styles.WARNING)))

def error(string: str | pt.IRenderable):
get_stdout().write(pt.render(pt.Fragment("[ERROR] ", pt.Styles.ERROR) + string))
get_stdout().write(pt.render(pt.Fragment("[ERROR] ", pt.Styles.ERROR) + string+'\n'))
exit(1)


Expand All @@ -43,16 +43,16 @@ def _run(self, *args, **kwargs):
def _run_callback(self, *args, **kwargs):
pass

def _print_fin_result(self, fin: TextIO, filepath: str):
self.__print_file_result(fin, filepath, "Read", "<-", 'yellow')
def _render_fin_result(self, fin: TextIO, filepath: str):
return self.__render_file_result(fin, filepath, "Read", "<-", 'yellow')

def _print_fout_result(self, fout: TextIO, filepath: str):
self.__print_file_result(fout, filepath, "Wrote", "->", 'green')
def _render_fout_result(self, fout: TextIO, filepath: str):
return self.__render_file_result(fout, filepath, "Wrote", "->", 'green')

def __print_file_result(self, f: TextIO, filepath: str, act: str, arr: str, sizecolor: str):
def __render_file_result(self, f: TextIO, filepath: str, act: str, arr: str, sizecolor: str):
size = pt.format_si(f.tell(), unit="b", auto_color=False)
size = Text(size, sizecolor, width=8)
get_stdout().write(pt.render(SimpleTable(width=100).pass_row(f"{act:<5s}", size, arr, Fragment(filepath, "blue"))))
return pt.render(SimpleTable(width=100).pass_row(f"{act:<5s}", size, arr, Fragment(filepath, "blue")))


def get_stdout():
Expand Down
Loading

0 comments on commit 8c91654

Please sign in to comment.