mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 09:35:44 +00:00
adding latest
This commit is contained in:
16
TODO.todo
16
TODO.todo
@@ -8,13 +8,17 @@ Functionality:
|
|||||||
check pypi for latest version and compare to current
|
check pypi for latest version and compare to current
|
||||||
✔ `TEMBO_CONFIG` should follow same pattern as other env vars and be a python string when read in @done(21-10-24 05:31)
|
✔ `TEMBO_CONFIG` should follow same pattern as other env vars and be a python string when read in @done(21-10-24 05:31)
|
||||||
|
|
||||||
|
Bug:
|
||||||
|
☐ tokens
|
||||||
|
Say we have input0 and input3 in file path
|
||||||
|
and we have input1 and input2 in template
|
||||||
|
it only recognises this as 2 inputs total, not four.
|
||||||
|
passing in tembo new meeting a b will work and input0=input1, input3=input2
|
||||||
|
|
||||||
VSCode:
|
VSCode:
|
||||||
☐ Look at <https://github.com/CodeWithSwastik/vscode-ext>
|
☐ Look at <https://github.com/CodeWithSwastik/vscode-ext>
|
||||||
|
|
||||||
Logging:
|
Logging:
|
||||||
☐ How to raise + debug an exception?
|
|
||||||
☐ Document how to raise a logger.critical instead of exception
|
|
||||||
in a try, except you can just do logger.critical(exec_info=1) to print the stack
|
|
||||||
|
|
||||||
Documentation:
|
Documentation:
|
||||||
☐ Document usage of Panaetius in a module
|
☐ Document usage of Panaetius in a module
|
||||||
@@ -28,6 +32,12 @@ Documentation:
|
|||||||
☐ Document how to do docstrings in python. Don't document `__init__` do it in class.
|
☐ Document how to do docstrings in python. Don't document `__init__` do it in class.
|
||||||
Should update the default gist to hide the `__init__` messages
|
Should update the default gist to hide the `__init__` messages
|
||||||
☐ Document using jinja2 briefly and link to Tembo (link to <https://zetcode.com/python/jinja/>)
|
☐ Document using jinja2 briefly and link to Tembo (link to <https://zetcode.com/python/jinja/>)
|
||||||
|
|
||||||
|
Logging:
|
||||||
|
☐ How to raise + debug an exception?
|
||||||
|
☐ Document how to raise a logger.critical instead of exception
|
||||||
|
in a try, except you can just do logger.critical(exec_info=1) to print the stack
|
||||||
|
|
||||||
Tembo:
|
Tembo:
|
||||||
☐ Document creating new Tembo config
|
☐ Document creating new Tembo config
|
||||||
☐ ~/tembo needs creating
|
☐ ~/tembo needs creating
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import jinja2
|
|||||||
import pendulum
|
import pendulum
|
||||||
|
|
||||||
from tembo import logger, CONFIG
|
from tembo import logger, CONFIG
|
||||||
from tembo.exceptions import MismatchedTokenError
|
|
||||||
|
|
||||||
|
|
||||||
class PageCreator:
|
class PageCreator:
|
||||||
@@ -70,8 +69,8 @@ class ScopedPageCreator(PageCreator):
|
|||||||
self.filename = ""
|
self.filename = ""
|
||||||
self.extension = ""
|
self.extension = ""
|
||||||
# TODO: rename these to input tokens + more sensible
|
# TODO: rename these to input tokens + more sensible
|
||||||
self.path_input_tokens: Tuple[int, int] = (0, 0)
|
self.path_input_token_counts = {"config": 0, "user": 0}
|
||||||
self.template_input_tokens: Tuple[int, int] = (0, 0)
|
self.template_input_token_counts = {"config": 0, "user": 0}
|
||||||
|
|
||||||
def create_page(
|
def create_page(
|
||||||
self,
|
self,
|
||||||
@@ -97,10 +96,6 @@ class ScopedPageCreator(PageCreator):
|
|||||||
path = pathlib.Path(
|
path = pathlib.Path(
|
||||||
self._substitute_tokens(str(path), user_input, name, "path")
|
self._substitute_tokens(str(path), user_input, name, "path")
|
||||||
)
|
)
|
||||||
if sum(self.path_input_tokens) > 0:
|
|
||||||
_highest_input_token_in_path = max(self.path_input_tokens)
|
|
||||||
else:
|
|
||||||
_highest_input_token_in_path = 0
|
|
||||||
|
|
||||||
# get the template file
|
# get the template file
|
||||||
if template_filename is not None:
|
if template_filename is not None:
|
||||||
@@ -109,51 +104,34 @@ class ScopedPageCreator(PageCreator):
|
|||||||
template_contents = self._substitute_tokens(
|
template_contents = self._substitute_tokens(
|
||||||
template_contents, user_input, name, "template"
|
template_contents, user_input, name, "template"
|
||||||
)
|
)
|
||||||
if sum(self.template_input_tokens) > 0:
|
|
||||||
_highest_input_token_in_template = max(self.template_input_tokens)
|
|
||||||
else:
|
|
||||||
_highest_input_token_in_template = 0
|
|
||||||
else:
|
else:
|
||||||
template_contents = ""
|
template_contents = ""
|
||||||
|
|
||||||
self.__check_input_token_mismatch(
|
self.__check_input_token_mismatch()
|
||||||
_highest_input_token_in_path, _highest_input_token_in_template
|
|
||||||
)
|
|
||||||
return ScopedPage(path, template_contents)
|
return ScopedPage(path, template_contents)
|
||||||
|
|
||||||
def __check_input_token_mismatch(
|
def __check_input_token_mismatch(self) -> None:
|
||||||
self, _highest_input_token_in_path: int, _highest_input_token_in_template: int
|
_max_config_input_token_count = max(
|
||||||
) -> None:
|
self.path_input_token_counts["config"],
|
||||||
_highest_input_token_count = max(
|
self.template_input_token_counts["config"],
|
||||||
_highest_input_token_in_path, _highest_input_token_in_template
|
|
||||||
)
|
)
|
||||||
if _highest_input_token_in_path < _highest_input_token_count:
|
_max_user_input_token_count = max(
|
||||||
|
self.path_input_token_counts["user"],
|
||||||
|
self.template_input_token_counts["user"],
|
||||||
|
)
|
||||||
|
if _max_user_input_token_count < _max_config_input_token_count:
|
||||||
logger.critical(
|
logger.critical(
|
||||||
"Your config/template specifies %s input tokens, you gave %s "
|
"Your config/template specifies %s input tokens, you gave %s "
|
||||||
"- exiting",
|
"- exiting",
|
||||||
_highest_input_token_count,
|
_max_config_input_token_count,
|
||||||
self.path_input_tokens[0],
|
_max_user_input_token_count,
|
||||||
)
|
)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
if _highest_input_token_in_path > _highest_input_token_count:
|
if _max_user_input_token_count > _max_config_input_token_count:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Your config/template specifies %s input tokens, you gave %s",
|
"Your config/template specifies %s input tokens, you gave %s",
|
||||||
_highest_input_token_count,
|
_max_config_input_token_count,
|
||||||
self.path_input_tokens[0],
|
_max_user_input_token_count,
|
||||||
)
|
|
||||||
if _highest_input_token_in_template < _highest_input_token_count:
|
|
||||||
logger.critical(
|
|
||||||
"Your config/template specifies %s input tokens, you gave %s "
|
|
||||||
"- exiting",
|
|
||||||
_highest_input_token_count,
|
|
||||||
self.template_input_tokens[0],
|
|
||||||
)
|
|
||||||
raise SystemExit(1)
|
|
||||||
if _highest_input_token_in_template > _highest_input_token_count:
|
|
||||||
logger.warning(
|
|
||||||
"Your config/template specifies %s input tokens, you gave %s",
|
|
||||||
_highest_input_token_count,
|
|
||||||
self.template_input_tokens[0],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _substitute_tokens(
|
def _substitute_tokens(
|
||||||
@@ -196,9 +174,11 @@ class ScopedPageCreator(PageCreator):
|
|||||||
# if the regex matches, save the number of input tokens found
|
# if the regex matches, save the number of input tokens found
|
||||||
if input_token_type == "path": # noqa: bandit 105
|
if input_token_type == "path": # noqa: bandit 105
|
||||||
# TODO: change this to a dict instead of tuple
|
# TODO: change this to a dict instead of tuple
|
||||||
self.path_input_tokens = (len(input_extraction), 0)
|
self.path_input_token_counts["config"] = len(input_extraction)
|
||||||
|
self.path_input_token_counts["user"] = 0
|
||||||
if input_token_type == "template": # noqa: bandit 105
|
if input_token_type == "template": # noqa: bandit 105
|
||||||
self.template_input_tokens = (len(input_extraction), 0)
|
self.template_input_token_counts["config"] = len(input_extraction)
|
||||||
|
self.template_input_token_counts["user"] = 0
|
||||||
# if there aren't any tokens in the string, return the string
|
# if there aren't any tokens in the string, return the string
|
||||||
return tokenified_string
|
return tokenified_string
|
||||||
|
|
||||||
@@ -206,9 +186,11 @@ class ScopedPageCreator(PageCreator):
|
|||||||
if len(user_input) > 0:
|
if len(user_input) > 0:
|
||||||
# save the number of input tokens, and the number of user inputs
|
# save the number of input tokens, and the number of user inputs
|
||||||
if input_token_type == "path": # noqa: bandit 105
|
if input_token_type == "path": # noqa: bandit 105
|
||||||
self.path_input_tokens = (len(input_extraction), len(user_input))
|
self.path_input_token_counts["config"] = len(input_extraction)
|
||||||
|
self.path_input_token_counts["user"] = len(user_input)
|
||||||
elif input_token_type == "template": # noqa: bandit 105
|
elif input_token_type == "template": # noqa: bandit 105
|
||||||
self.template_input_tokens = (len(input_extraction), len(user_input))
|
self.template_input_token_counts["config"] = len(input_extraction)
|
||||||
|
self.template_input_token_counts["user"] = len(user_input)
|
||||||
|
|
||||||
# sbustitute the input token for the user's input
|
# sbustitute the input token for the user's input
|
||||||
for extracted_input, input_value in zip(input_extraction, user_input):
|
for extracted_input, input_value in zip(input_extraction, user_input):
|
||||||
|
|||||||
Reference in New Issue
Block a user