From 8a36bb0debee98cbe8799a14bf815f2a1a75acfb Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Fri, 23 Aug 2024 18:13:12 +0200 Subject: [PATCH] Fix string syntax in hook output (#305) * Fix string syntax in hook output * Fix empty lines * Discard changes to .pre-commit-config.yaml * fix import --- hooks/post_gen_project.py | 54 ++++++++++--------- .../make_rich_output.py | 31 ++++++++--- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 097c481a..4cfcd207 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -1,9 +1,9 @@ #!/bin/env python3 from subprocess import run +{% if not cookiecutter._render_devdocs %} from pathlib import Path # Post processing -{% if not cookiecutter._render_devdocs %} Path("docs/template_usage.md").unlink() {% endif %} @@ -14,54 +14,56 @@ # The following output was generated using rich # The formatted output is included here directly, because I don't want # rich as another dependency for initalizing the repo. -# See .make_rich_output.py for more details. +# Regenerate using `cd scripts; hatch run python -m scverse_template_scripts.make_rich_output` print(""" -╔══════════════════════════════════════════════════════════════════════╗ -║ Set-up online services ║ -╚══════════════════════════════════════════════════════════════════════╝ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ \x1b[1mSet-up online services\x1b[0m ┃ +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -Your repository is now ready. However, to use all features of the  -template you will need to set up the following online services. Clicking +\x1b[1mYour repository is now ready.\x1b[0m\x1b[1m \x1b[0m\x1b[1mHowever, to use all features of the \x1b[0m +\x1b[1mtemplate you will need to set up the following online services.\x1b[0m Clicking on the links will take you to the respective sections of the developer documentation. The developer documentation is also shipped as part of the template in docs/developer_docs.md. - 1 ]8;id=633754;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#pre-commit-checks\pre-commit.ci]8;;\ to check for inconsistencies and to enforce a code - style - 2 ]8;id=858259;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#documentation-on-readthedocs\readthedocs.org]8;;\ to build and host documentation - 3 ]8;id=497293;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#coverage-tests-with-codecov\codecov]8;;\ to generate test coverage reports +\x1b[1;33m 1 \x1b[0m\x1b]8;id=994867;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#pre-commit-checks\x1b\\\x1b[4;34mpre-commit.ci\x1b[0m\x1b]8;;\x1b\\ to check for inconsistencies and to enforce a code +\x1b[1;33m \x1b[0mstyle +\x1b[1;33m 2 \x1b[0m\x1b]8;id=697682;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#documentation-on-readthedocs\x1b\\\x1b[4;34mreadthedocs.org\x1b[0m\x1b]8;;\x1b\\ to build and host documentation +\x1b[1;33m 3 \x1b[0m\x1b]8;id=723197;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#coverage-tests-with-codecov\x1b\\\x1b[4;34mcodecov\x1b[0m\x1b]8;;\x1b\\ to generate test coverage reports All CI checks should pass, you are ready to start developing your new tool! -╔══════════════════════════════════════════════════════════════════════╗ -║ Install the package ║ -╚══════════════════════════════════════════════════════════════════════╝ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ \x1b[1mInstall the package\x1b[0m ┃ +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ To run tests or build the documentation locally, you need to install your package and its dependencies. You can do so with -pip install ".[test,dev,doc]"  +\x1b[40m \x1b[0m +\x1b[40m \x1b[0m\x1b[97;40mpip\x1b[0m\x1b[97;40m \x1b[0m\x1b[97;40minstall\x1b[0m\x1b[97;40m \x1b[0m\x1b[93;40m".[test,dev,doc]"\x1b[0m\x1b[40m \x1b[0m\x1b[40m \x1b[0m +\x1b[40m \x1b[0m -╔══════════════════════════════════════════════════════════════════════╗ -║ Customizations ║ -╚══════════════════════════════════════════════════════════════════════╝ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ \x1b[1mCustomizations\x1b[0m ┃ +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -Further instructions on using this template can be found in the ]8;id=447180;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html\dev docs]8;;\ -]8;id=447180;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html\included in the project]8;;\. +Further instructions on using this template can be found in the \x1b]8;id=736137;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html\x1b\\\x1b[4;34mdev docs\x1b[0m\x1b]8;;\x1b\\ +\x1b]8;id=736137;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html\x1b\\\x1b[4;34mincluded in the project\x1b[0m\x1b]8;;\x1b\\. -╔══════════════════════════════════════════════════════════════════════╗ -║ Committment ║ -╚══════════════════════════════════════════════════════════════════════╝ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ \x1b[1mCommitment\x1b[0m ┃ +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ We expect developers of scverse ecosystem packages to - • ]8;id=169559;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#writing-tests\write unit tests]8;;\ - • ]8;id=20647;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#writing-documentation\provide documentation]8;;\, including tutorials where applicable - • support users through github and the ]8;id=496112;https://discourse.scverse.org/\scverse discourse]8;;\ +\x1b[1;33m • \x1b[0m\x1b]8;id=213267;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#writing-tests\x1b\\\x1b[4;34mwrite unit tests\x1b[0m\x1b]8;;\x1b\\ +\x1b[1;33m • \x1b[0m\x1b]8;id=972096;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#writing-documentation\x1b\\\x1b[4;34mprovide documentation\x1b[0m\x1b]8;;\x1b\\, including tutorials where applicable +\x1b[1;33m • \x1b[0msupport users through github and the \x1b]8;id=997067;https://discourse.scverse.org/\x1b\\\x1b[4;34mscverse discourse\x1b[0m\x1b]8;;\x1b\\ """) diff --git a/scripts/src/scverse_template_scripts/make_rich_output.py b/scripts/src/scverse_template_scripts/make_rich_output.py index 5e28731b..a7418717 100644 --- a/scripts/src/scverse_template_scripts/make_rich_output.py +++ b/scripts/src/scverse_template_scripts/make_rich_output.py @@ -1,5 +1,8 @@ from __future__ import annotations +import io +import re + from rich.console import Console from rich.markdown import Markdown @@ -51,14 +54,26 @@ def main() -> None: - with open("report.txt", "w") as report_file: - console = Console( - file=report_file, - width=72, - force_terminal=True, - color_system="standard", - ) - console.print(Markdown(message)) + file = io.StringIO() + console = Console( + file=file, + width=72, + force_terminal=True, + color_system="standard", + ) + console.print(Markdown(message)) + + string_literal = repr(file.getvalue()) + + # make single line string literal into multiline string literal + if '"""' in string_literal: + msg = "Error: Unexpected triple-quotes in rich output" + raise AssertionError(msg) + string_literal = string_literal[1:-1].replace(r"\n", "\n") + string_literal = re.sub(r"[ ]+$", "", string_literal, flags=re.MULTILINE) + string_literal = f'"""\n\n\n\n\n{string_literal}"""' + + print(string_literal) # noqa: T201 if __name__ == "__main__":