various tweaks

Bad Soren let these sit around for a while, so I don't know what they
are or what they were for anymore!
This commit is contained in:
Soren I. Bjornstad
2021-09-10 10:59:41 -05:00
parent 90ea549c36
commit f4e8888101
5 changed files with 82 additions and 14 deletions

View File

@@ -216,7 +216,7 @@ class BuildCommand(CliCommand):
for idx, step in enumerate(steps, 1):
# Explain what we're doing. Use first line of the builder's docstring
# as a summary, if present.
if hasattr(step, '__doc__'):
if hasattr(step, '__doc__') and step.__doc__ is not None:
short_description = step.__doc__.strip().split('\n')[0].rstrip('.')
print(f"tzk: Step {idx}/{len(steps)}: {short_description}")
else:

View File

@@ -12,6 +12,7 @@ information about the defined products without actually running any build steps.
from contextlib import contextmanager
import functools
import json
import os
from pathlib import Path
import re
@@ -124,8 +125,8 @@ def new_output_folder():
"""
Create a new temporary folder to hold intermediate steps of the product being built.
The path to this temporary folder will be stored in the 'public_wiki_folder'
key of the builders.build_state dictionary. Future build steps can access
The path to this temporary folder will be stored in the ``public_wiki_folder``
key of the ``builders.build_state`` dictionary. Future build steps can access
the work in progress here. A cleaner is registered to delete this folder
when all steps complete, so any finished product should be copied out by a
later build step once it is complete.
@@ -421,7 +422,7 @@ def replace_private_people(initialer: Callable[[str], str] = None) -> None:
@tzk_builder
def set_tiddler_values(mappings: Dict[str, str]) -> None:
"""
Set the 'text' field of selected config or other tiddlers to arbitrary new values.
Set the ``text`` field of selected config or other tiddlers to arbitrary new values.
This can be used to make customizations that can't easily be done with feature
flags or other wikitext solutions within the wiki -- for instance, changing the
@@ -524,3 +525,33 @@ def shell(shell_command: str) -> None:
info(f"Command exited with return code 0:\n{output}")
else:
info(f"Command exited with return code 0 (no output).")
@tzk_builder
def editionify(target_folder: str, description: str) -> None:
"""
Copy the output folder to a target location and set its edition description.
This generates a TiddlyWiki edition based on the temporary output. By
copying it into an appropriate location or setting the environment variable
:envvar:`TIDDLYWIKI_EDITION_PATH` to the parent directory of the edition's folder,
it's possible to quickly generate new TiddlyWikis based on the edition
"template" (``tiddlywiki --init EDITION_NAME``, where the ``EDITION_NAME`` is the
name of the folder).
:param target_folder: The folder to copy the output folder to.
Note that the output folder will be merged into this folder
if it exists.
:param description: The description of this edition to use in the new edition's
``tiddlywiki.info`` file.
"""
shutil.copytree(
build_state['public_wiki_folder'],
target_folder,
dirs_exist_ok=True
)
with (Path(target_folder) / "tiddlywiki.info").open("r") as f:
tinfo = json.load(f)
tinfo['description'] = description
with (Path(target_folder) / "tiddlywiki.info").open("w") as f:
json.dump(tinfo, f)

View File

@@ -53,7 +53,7 @@ _public_export_filt = r"""
-[prefix[$:/temp]]
-[prefix[$:/state]]
-[prefix[$:/sib/StorySaver/saved]]
-[prefix[$:/sib/checkify/]]
-[prefix[$:/checkify/]]
-[[$:/config/zettelkasten/Build/KillPhrases]]
"""

View File

@@ -105,7 +105,13 @@ def _init_tw(wiki_name: str) -> None:
except FileExistsError:
pass
with pushd(wiki_name):
subprocess.check_call((_tw_path(), "--init"))
old_edition_path = os.environ.get('TIDDLYWIKI_EDITION_PATH')
os.environ['TIDDLYWIKI_EDITION_PATH'] = str(Path(__file__).parent / "editions")
try:
subprocess.check_call((_tw_path(), "--init", "tzk"))
finally:
if old_edition_path:
os.environ['TIDDLYWIKI_EDITION_PATH'] = old_edition_path
def _add_filesystem_plugins(wiki_name: str) -> None:
@@ -148,7 +154,9 @@ def _initial_commit() -> None:
print("tzk: Committing changes to repository...")
git.exec("add", "-A")
git.exec("commit", "-m", "Initial commit")
output = git.read("commit", "-m", "Initial commit")
# Print just a summary since there are going to be a lot of files.
print('\n'.join(output.split('\n')[0:2]))
def install(wiki_name: str, tw_version_spec: str, author: Optional[str]):