Skip to content

Commit

Permalink
Fix string syntax in hook output (#305)
Browse files Browse the repository at this point in the history
* Fix string syntax in hook output

* Fix empty lines

* Discard changes to .pre-commit-config.yaml

* fix import
  • Loading branch information
flying-sheep authored Aug 23, 2024
1 parent d37a7dd commit 8a36bb0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
54 changes: 28 additions & 26 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -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 %}

Expand All @@ -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("""
╔══════════════════════════════════════════════════════════════════════╗
[1mSet-up online services[0m
╚══════════════════════════════════════════════════════════════════════╝
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
\x1b[1mSet-up online services\x1b[0m
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
[1mYour repository is now ready. However, to use all features of the [0m
[1mtemplate you will need to set up the following online services.[0m 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;33m 1 [0m]8;id=633754;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#pre-commit-checks\[94mpre-commit.ci[0m]8;;\ to check for inconsistencies and to enforce a code
[1;33m [0mstyle
[1;33m 2 [0m]8;id=858259;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#documentation-on-readthedocs\[94mreadthedocs.org[0m]8;;\ to build and host documentation
[1;33m 3 [0m]8;id=497293;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#coverage-tests-with-codecov\[94mcodecov[0m]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!
╔══════════════════════════════════════════════════════════════════════╗
[1mInstall the package[0m
╚══════════════════════════════════════════════════════════════════════╝
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
\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
╔══════════════════════════════════════════════════════════════════════╗
[1mCustomizations[0m
╚══════════════════════════════════════════════════════════════════════╝
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
\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\[94mdev docs[0m]8;;\
]8;id=447180;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html\[94mincluded in the project[0m]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\\.
╔══════════════════════════════════════════════════════════════════════╗
[1mCommittment[0m
╚══════════════════════════════════════════════════════════════════════╝
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
\x1b[1mCommitment\x1b[0m
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
We expect developers of scverse ecosystem packages to
[1;33m • [0m]8;id=169559;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#writing-tests\[94mwrite unit tests[0m]8;;\
[1;33m • [0m]8;id=20647;https://cookiecutter-scverse-instance.readthedocs.io/en/latest/developer_docs.html#writing-documentation\[94mprovide documentation[0m]8;;\, including tutorials where applicable
[1;33m • [0msupport users through github and the ]8;id=496112;https://discourse.scverse.org/\[94mscverse discourse[0m]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\\
""")
31 changes: 23 additions & 8 deletions scripts/src/scverse_template_scripts/make_rich_output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

import io
import re

from rich.console import Console
from rich.markdown import Markdown

Expand Down Expand Up @@ -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__":
Expand Down

0 comments on commit 8a36bb0

Please sign in to comment.