Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix string syntax in hook output #305

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("""




╔══════════════════════════════════════════════════════════════════════╗
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\\

""")
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
Loading