mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 05:55:44 +00:00
adding latest
This commit is contained in:
40
TODO.todo
40
TODO.todo
@@ -8,30 +8,40 @@ Functionality:
|
||||
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)
|
||||
|
||||
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:
|
||||
☐ Look at <https://github.com/CodeWithSwastik/vscode-ext>
|
||||
|
||||
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:
|
||||
☐ Document usage of Panaetius in a module
|
||||
Using the logger, initialising with the config path etc
|
||||
✘ Uses Pendulum tokens: https://pendulum.eustace.io/docs/#tokens @cancelled(21-10-24 05:32)
|
||||
☐ Uses `strftime` tokens: <https://strftime.org>
|
||||
☐ Document latest typing.
|
||||
Documentation:
|
||||
☐ Document usage of Panaetius in a module
|
||||
Using the logger, initialising with the config path etc
|
||||
✘ Uses Pendulum tokens: https://pendulum.eustace.io/docs/#tokens @cancelled(21-10-24 05:32)
|
||||
☐ Uses `strftime` tokens: <https://strftime.org>
|
||||
☐ Document latest typing.
|
||||
☐ Using from `__future__` with `|`
|
||||
☐ `using Tuple[str, ...]`
|
||||
☐ `Sequence` vs `Collection`
|
||||
☐ 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
|
||||
☐ Document using jinja2 briefly and link to Tembo (link to <https://zetcode.com/python/jinja/>)
|
||||
Tembo:
|
||||
☐ Document creating new Tembo config
|
||||
☐ 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
|
||||
☐ 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:
|
||||
☐ Document creating new Tembo config
|
||||
☐ ~/tembo needs creating
|
||||
☐ ~/tembo/.config
|
||||
☐ ~/tembo/.templates
|
||||
☐ ~/tembo/logs
|
||||
☐ Document how to overwrite these with ENV vars
|
||||
☐ Document how to overwrite these with ENV vars
|
||||
|
||||
@@ -9,7 +9,6 @@ import jinja2
|
||||
import pendulum
|
||||
|
||||
from tembo import logger, CONFIG
|
||||
from tembo.exceptions import MismatchedTokenError
|
||||
|
||||
|
||||
class PageCreator:
|
||||
@@ -70,8 +69,8 @@ class ScopedPageCreator(PageCreator):
|
||||
self.filename = ""
|
||||
self.extension = ""
|
||||
# TODO: rename these to input tokens + more sensible
|
||||
self.path_input_tokens: Tuple[int, int] = (0, 0)
|
||||
self.template_input_tokens: Tuple[int, int] = (0, 0)
|
||||
self.path_input_token_counts = {"config": 0, "user": 0}
|
||||
self.template_input_token_counts = {"config": 0, "user": 0}
|
||||
|
||||
def create_page(
|
||||
self,
|
||||
@@ -97,10 +96,6 @@ class ScopedPageCreator(PageCreator):
|
||||
path = pathlib.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
|
||||
if template_filename is not None:
|
||||
@@ -109,51 +104,34 @@ class ScopedPageCreator(PageCreator):
|
||||
template_contents = self._substitute_tokens(
|
||||
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:
|
||||
template_contents = ""
|
||||
|
||||
self.__check_input_token_mismatch(
|
||||
_highest_input_token_in_path, _highest_input_token_in_template
|
||||
)
|
||||
self.__check_input_token_mismatch()
|
||||
return ScopedPage(path, template_contents)
|
||||
|
||||
def __check_input_token_mismatch(
|
||||
self, _highest_input_token_in_path: int, _highest_input_token_in_template: int
|
||||
) -> None:
|
||||
_highest_input_token_count = max(
|
||||
_highest_input_token_in_path, _highest_input_token_in_template
|
||||
def __check_input_token_mismatch(self) -> None:
|
||||
_max_config_input_token_count = max(
|
||||
self.path_input_token_counts["config"],
|
||||
self.template_input_token_counts["config"],
|
||||
)
|
||||
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(
|
||||
"Your config/template specifies %s input tokens, you gave %s "
|
||||
"- exiting",
|
||||
_highest_input_token_count,
|
||||
self.path_input_tokens[0],
|
||||
_max_config_input_token_count,
|
||||
_max_user_input_token_count,
|
||||
)
|
||||
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(
|
||||
"Your config/template specifies %s input tokens, you gave %s",
|
||||
_highest_input_token_count,
|
||||
self.path_input_tokens[0],
|
||||
)
|
||||
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],
|
||||
_max_config_input_token_count,
|
||||
_max_user_input_token_count,
|
||||
)
|
||||
|
||||
def _substitute_tokens(
|
||||
@@ -196,9 +174,11 @@ class ScopedPageCreator(PageCreator):
|
||||
# if the regex matches, save the number of input tokens found
|
||||
if input_token_type == "path": # noqa: bandit 105
|
||||
# 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
|
||||
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
|
||||
return tokenified_string
|
||||
|
||||
@@ -206,9 +186,11 @@ class ScopedPageCreator(PageCreator):
|
||||
if len(user_input) > 0:
|
||||
# save the number of input tokens, and the number of user inputs
|
||||
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
|
||||
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
|
||||
for extracted_input, input_value in zip(input_extraction, user_input):
|
||||
|
||||
Reference in New Issue
Block a user