From 61c31b90f08d44bc0213f9c2f6102f834930d511 Mon Sep 17 00:00:00 2001 From: droserasprout Date: Wed, 20 Mar 2024 21:39:29 +0000 Subject: [PATCH] deploy: 7c84a7cd44f45f56e1f9ea9e96e00045a176e0aa --- docs.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/docs.py b/docs.py index bbffb2d6d..49cff4c4c 100755 --- a/docs.py +++ b/docs.py @@ -15,6 +15,7 @@ import subprocess import sys import time +from collections import defaultdict from collections.abc import Callable from collections.abc import Iterator from contextlib import ExitStack @@ -42,6 +43,8 @@ from dipdup.cli import green_echo from dipdup.cli import red_echo from dipdup.config import DipDupConfig +from dipdup.project import TEMPLATES +from dipdup.project import answers_from_replay from dipdup.project import get_default_answers from dipdup.sys import set_up_logging @@ -519,5 +522,83 @@ def markdownlint() -> None: exit(1) +# FIXME: It's a full-copilot script to fix the changelog once, quickly. Rewrite or remove it. +@main.command('merge-changelog', help='Print changelog grouped by minor versions') +def merge_changelog() -> None: + group_order = ( + 'Added', + 'Fixed', + 'Changed', + 'Deprecated', + 'Removed', + 'Performance', + 'Security', + 'Other', + ) + + changelog_path = Path('CHANGELOG.md') + changelog = changelog_path.read_text().split('')[0].strip() + + changelog_tree: defaultdict[str, defaultdict[str, list[str]]] = defaultdict(lambda: defaultdict(list)) + curr_version, curr_group = '', '' + + for line in changelog.split('\n'): + line = line.strip() + + if line.startswith('## '): + curr_version = line.split('[', 1)[1].split(']')[0] + curr_version = '.'.join(curr_version.split('.')[:2]) + elif line.startswith('### '): + curr_group = line[4:] + elif line.startswith('- '): + changelog_tree[curr_version][curr_group].append(line) + + for version in sorted(changelog_tree.keys()): + if not version.startswith('7.'): + continue + + print(f'## {version}\n') + for group in group_order: + if not changelog_tree[version][group]: + continue + + print(f'### {group}\n') + for line in sorted(changelog_tree[version][group]): + print(line) + print() + + +@main.command('dump-demos', help='Dump Markdown table of available demo projects') +def dump_demos() -> None: + green_echo('=> Dumping demos table') + lines: list[str] = [] + demos: list[tuple[str, str, str]] = [] + + replays = Path('src/dipdup/projects').glob('**/replay.yaml') + for replay_path in replays: + replay = answers_from_replay(replay_path) + package, description = replay['package'], replay['description'] + if package in TEMPLATES['other']: + network = '' + elif package in TEMPLATES['evm']: + network = 'EVM' + elif package in TEMPLATES['tezos']: + network = 'Tezos' + demos.append((package, network, description)) + + # NOTE: Sort by blockchain first, then by package name + demos = sorted(demos, key=lambda x: (x[1], x[0])) + + lines = [ + '', + '| name | network | description |', + '|-|-|-|', + *(f'| {name} | {network} | {description} |' for name, network, description in demos), + '', + ] + + Path('docs/8.examples/_demos_table.md').write_text('\n'.join(lines)) + + if __name__ == '__main__': main()