mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 09:55:43 +00:00
adding example and template_file as optional in config
This commit is contained in:
@@ -24,7 +24,8 @@ Documentation:
|
|||||||
Functionality:
|
Functionality:
|
||||||
✔ Move any `tembo.CONFIG` calls out of `pages.py` and ensure these are passed in from the cli. @done(21-10-28 19:44)
|
✔ Move any `tembo.CONFIG` calls out of `pages.py` and ensure these are passed in from the cli. @done(21-10-28 19:44)
|
||||||
✔ Make `config scope` a dict in `cli.py`. @done(21-10-28 19:44)
|
✔ Make `config scope` a dict in `cli.py`. @done(21-10-28 19:44)
|
||||||
☐ Add the `--example` output to the miscounted token message so the user knows the correct command to use.
|
✔ Make example optional @done(21-10-29 00:15)
|
||||||
|
✔ Add the `--example` output to the miscounted token message so the user knows the correct command to use. @done(21-10-29 00:15)
|
||||||
✔ Page options dataclass @done(21-10-28 20:09)
|
✔ Page options dataclass @done(21-10-28 20:09)
|
||||||
☐ Replace loggers with `click.echo` for command outputs. Keep logging messages for actual logging messages?
|
☐ Replace loggers with `click.echo` for command outputs. Keep logging messages for actual logging messages?
|
||||||
☐ Use the python runner Duty
|
☐ Use the python runner Duty
|
||||||
@@ -39,6 +40,9 @@ VSCode:
|
|||||||
☐ Document build error: <https://github.com/pyenv/pyenv/issues/1095>
|
☐ Document build error: <https://github.com/pyenv/pyenv/issues/1095>
|
||||||
PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.8.11
|
PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.8.11
|
||||||
☐ Freeze a click app: <https://stackoverflow.com/questions/45090083/freeze-a-program-created-with-pythons-click-pacage>
|
☐ Freeze a click app: <https://stackoverflow.com/questions/45090083/freeze-a-program-created-with-pythons-click-pacage>
|
||||||
|
☐ If python 3.9 can be used with Pyinstaller, rewrite the code to use the latest Python features
|
||||||
|
dict.update -> |=
|
||||||
|
walrus :=
|
||||||
|
|
||||||
Tests:
|
Tests:
|
||||||
☐ Write tests! @2d
|
☐ Write tests! @2d
|
||||||
|
|||||||
47
tembo/cli.py
47
tembo/cli.py
@@ -62,32 +62,38 @@ def new(scope, inputs, dry_run, example):
|
|||||||
raise SystemExit(1) from type_error
|
raise SystemExit(1) from type_error
|
||||||
|
|
||||||
# get the scope information from the tembo config.yml
|
# get the scope information from the tembo config.yml
|
||||||
try:
|
config_scope = {}
|
||||||
config_scope = {
|
for option in [
|
||||||
option: str(user_scope[option])
|
"name",
|
||||||
for option in [
|
"example",
|
||||||
"name",
|
"path",
|
||||||
"example",
|
"filename",
|
||||||
"path",
|
"extension",
|
||||||
"filename",
|
"template_filename",
|
||||||
"extension",
|
]:
|
||||||
"template_filename",
|
try:
|
||||||
]
|
config_scope.update(
|
||||||
for user_scope in tembo.CONFIG.scopes
|
{
|
||||||
if user_scope["name"] == scope
|
option: str(user_scope[option])
|
||||||
}
|
for user_scope in tembo.CONFIG.scopes
|
||||||
except KeyError as key_error:
|
if user_scope["name"] == scope
|
||||||
# raise error if any non optional keys are missing
|
}
|
||||||
tembo.logger.critical("Key %s not found in config.yml - exiting", key_error)
|
)
|
||||||
raise SystemExit(1) from key_error
|
except KeyError as key_error:
|
||||||
|
if key_error.args[0] in ["example", "template_filename"]:
|
||||||
|
config_scope.update({key_error.args[0]: None})
|
||||||
|
continue
|
||||||
|
tembo.logger.critical(
|
||||||
|
"Key %s not found in config. yml - exiting", key_error
|
||||||
|
)
|
||||||
|
raise SystemExit(1) from key_error
|
||||||
# print the example to the user
|
# print the example to the user
|
||||||
if example:
|
if example:
|
||||||
tembo.logger.info(
|
tembo.logger.info(
|
||||||
"Example for 'tembo new %s': %s",
|
"Example for 'tembo new %s': %s",
|
||||||
config_scope["name"],
|
config_scope["name"],
|
||||||
config_scope["example"]
|
config_scope["example"]
|
||||||
if isinstance(config_scope[0][1], str)
|
if isinstance(config_scope["example"], str)
|
||||||
else "No example in config.yml",
|
else "No example in config.yml",
|
||||||
)
|
)
|
||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
@@ -99,6 +105,7 @@ def new(scope, inputs, dry_run, example):
|
|||||||
filename=config_scope["filename"],
|
filename=config_scope["filename"],
|
||||||
extension=config_scope["extension"],
|
extension=config_scope["extension"],
|
||||||
name=config_scope["name"],
|
name=config_scope["name"],
|
||||||
|
example=config_scope["example"],
|
||||||
user_input=inputs,
|
user_input=inputs,
|
||||||
template_filename=config_scope["template_filename"],
|
template_filename=config_scope["template_filename"],
|
||||||
template_path=tembo.CONFIG.template_path,
|
template_path=tembo.CONFIG.template_path,
|
||||||
|
|||||||
@@ -20,9 +20,10 @@ class PageCreatorOptions:
|
|||||||
filename: str
|
filename: str
|
||||||
extension: str
|
extension: str
|
||||||
name: str
|
name: str
|
||||||
|
example: str | None
|
||||||
user_input: Collection[str]
|
user_input: Collection[str]
|
||||||
template_filename: str | None = None
|
template_filename: str | None
|
||||||
template_path: str | None = None
|
template_path: str | None
|
||||||
|
|
||||||
|
|
||||||
class PageCreator:
|
class PageCreator:
|
||||||
@@ -108,7 +109,7 @@ class ScopedPageCreator(PageCreator):
|
|||||||
self._all_input_tokens = self._get_input_tokens(
|
self._all_input_tokens = self._get_input_tokens(
|
||||||
options.template_filename, options.template_path
|
options.template_filename, options.template_path
|
||||||
)
|
)
|
||||||
self._verify_input_tokens(options.user_input)
|
self._verify_input_tokens(options.user_input, options.example)
|
||||||
|
|
||||||
# get the path of the scoped page
|
# get the path of the scoped page
|
||||||
path = self._convert_to_path(
|
path = self._convert_to_path(
|
||||||
@@ -148,13 +149,23 @@ class ScopedPageCreator(PageCreator):
|
|||||||
all_input_tokens.extend(re.findall(r"(\{input\d*\})", tokenified_string))
|
all_input_tokens.extend(re.findall(r"(\{input\d*\})", tokenified_string))
|
||||||
return sorted(all_input_tokens)
|
return sorted(all_input_tokens)
|
||||||
|
|
||||||
def _verify_input_tokens(self, user_input: Collection[str]) -> None:
|
def _verify_input_tokens(
|
||||||
|
self, user_input: Collection[str], example: str | None
|
||||||
|
) -> None:
|
||||||
if len(self._all_input_tokens) != len(user_input):
|
if len(self._all_input_tokens) != len(user_input):
|
||||||
tembo.logger.critical(
|
if example is not None:
|
||||||
"Your tembo.config/template specifies %s input tokens, you gave %s",
|
tembo.logger.critical(
|
||||||
len(self._all_input_tokens),
|
"Your tembo.config/template specifies %s input tokens, you gave %s. Example command: %s",
|
||||||
len(user_input),
|
len(self._all_input_tokens),
|
||||||
)
|
len(user_input),
|
||||||
|
example,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
tembo.logger.critical(
|
||||||
|
"Your tembo.config/template specifies %s input tokens, you gave %s.",
|
||||||
|
len(self._all_input_tokens),
|
||||||
|
len(user_input),
|
||||||
|
)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
def _get_template_contents(
|
def _get_template_contents(
|
||||||
@@ -332,17 +343,17 @@ if __name__ == "__main__":
|
|||||||
# "scratchpad.md.tpl",
|
# "scratchpad.md.tpl",
|
||||||
# )
|
# )
|
||||||
# )
|
# )
|
||||||
test_page_with_template = c.create_page(
|
# test_page_with_template = c.create_page(
|
||||||
"~/tembo",
|
# "~/tembo",
|
||||||
"{name}/{d:A}/{d:DD-MM-YYYY}-{d:dddd}-{d:A}",
|
# "{name}/{d:A}/{d:DD-MM-YYYY}-{d:dddd}-{d:A}",
|
||||||
"file-{input0}-{name}",
|
# "file-{input0}-{name}",
|
||||||
".md",
|
# ".md",
|
||||||
"meeting",
|
# "meeting",
|
||||||
("last",),
|
# ("last",),
|
||||||
"scratchpad.md.tpl",
|
# "scratchpad.md.tpl",
|
||||||
)
|
# )
|
||||||
print(test_page_with_template)
|
# print(test_page_with_template)
|
||||||
test_page_with_template.save_to_disk(False)
|
# test_page_with_template.save_to_disk(False)
|
||||||
# print(
|
# print(
|
||||||
# c.create_page(
|
# c.create_page(
|
||||||
# "~/tembo",
|
# "~/tembo",
|
||||||
|
|||||||
Reference in New Issue
Block a user