From bec27409abe911205f43274af193e03c8fbfb6b5 Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Fri, 23 Aug 2024 13:18:10 +0200 Subject: [PATCH 1/4] Fix string syntax in hook output --- .pre-commit-config.yaml | 2 +- hooks/post_gen_project.py | 65 ++++++++----------- .../make_rich_output.py | 31 ++++++--- 3 files changed, 51 insertions(+), 47 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3a57caec..6686b110 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: prettier # Hooks that are run for scripts - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.1 + rev: v0.6.2 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 097c481a..251f833b 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -1,6 +1,5 @@ #!/bin/env python3 from subprocess import run -from pathlib import Path # Post processing {% if not cookiecutter._render_devdocs %} @@ -14,54 +13,44 @@ # 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 ║ -╚══════════════════════════════════════════════════════════════════════╝ - -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[1mSet-up online services\x1b[0m ┃ +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ +\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=410765;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=222625;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=523544;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]"  - -╔══════════════════════════════════════════════════════════════════════╗ -║ Customizations ║ -╚══════════════════════════════════════════════════════════════════════╝ - -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;;\. - -╔══════════════════════════════════════════════════════════════════════╗ -║ Committment ║ -╚══════════════════════════════════════════════════════════════════════╝ - +\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 +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ \x1b[1mCustomizations\x1b[0m ┃ +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ +Further instructions on using this template can be found in the \x1b]8;id=84943;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html\x1b\\\x1b[4;34mdev docs\x1b[0m\x1b]8;;\x1b\\ +\x1b]8;id=84943;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html\x1b\\\x1b[4;34mincluded in the project\x1b[0m\x1b]8;;\x1b\\. +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ \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=747707;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=341721;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=254084;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..b6b80233 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"\s+$", "", string_literal, flags=re.MULTILINE) + string_literal = f'"""\n\n\n\n\n{string_literal}\n"""' + + print(string_literal) # noqa: T201 if __name__ == "__main__": From 448d66c732937e764574e081d861dfc179e2ddd8 Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Fri, 23 Aug 2024 13:21:42 +0200 Subject: [PATCH 2/4] Fix empty lines --- hooks/post_gen_project.py | 28 +++++++++++++------ .../make_rich_output.py | 4 +-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 251f833b..5afb4a31 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -22,35 +22,47 @@ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ \x1b[1mSet-up online services\x1b[0m ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + \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. -\x1b[1;33m 1 \x1b[0m\x1b]8;id=410765;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 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=222625;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=523544;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 +\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! + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ \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 + \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 + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ \x1b[1mCustomizations\x1b[0m ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -Further instructions on using this template can be found in the \x1b]8;id=84943;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html\x1b\\\x1b[4;34mdev docs\x1b[0m\x1b]8;;\x1b\\ -\x1b]8;id=84943;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html\x1b\\\x1b[4;34mincluded in the project\x1b[0m\x1b]8;;\x1b\\. + +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\\. + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ \x1b[1mCommitment\x1b[0m ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + We expect developers of scverse ecosystem packages to -\x1b[1;33m • \x1b[0m\x1b]8;id=747707;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=341721;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=254084;https://discourse.scverse.org/\x1b\\\x1b[4;34mscverse discourse\x1b[0m\x1b]8;;\x1b\\ + +\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 b6b80233..a7418717 100644 --- a/scripts/src/scverse_template_scripts/make_rich_output.py +++ b/scripts/src/scverse_template_scripts/make_rich_output.py @@ -70,8 +70,8 @@ def main() -> None: 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"\s+$", "", string_literal, flags=re.MULTILINE) - string_literal = f'"""\n\n\n\n\n{string_literal}\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 From 535d546589a8458505e736036295685021e6dd11 Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Fri, 23 Aug 2024 13:23:51 +0200 Subject: [PATCH 3/4] Discard changes to .pre-commit-config.yaml --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6686b110..3a57caec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: prettier # Hooks that are run for scripts - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.2 + rev: v0.6.1 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 188799c1fea442bf9c8273a8fcae44db7363522b Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Fri, 23 Aug 2024 13:24:52 +0200 Subject: [PATCH 4/4] fix import --- hooks/post_gen_project.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 5afb4a31..4cfcd207 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -1,8 +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 %}