From 6b2b0a3b5eeadf3337f9fc8dc3485820bbaf49a4 Mon Sep 17 00:00:00 2001 From: Daniel Tomlinson Date: Sun, 24 Oct 2021 18:28:18 +0100 Subject: [PATCH] Auto stash before merge of "bugfix/token_mismatch" and "origin/bugfix/token_mismatch" --- .pythonversion => .python-version | 0 tembo/journal/pages.py | 69 +++++++++--------- tests/__pycache__/__init__.cpython-38.pyc | Bin 151 -> 148 bytes .../test_tembo.cpython-38-pytest-6.2.5.pyc | Bin 153 -> 150 bytes 4 files changed, 36 insertions(+), 33 deletions(-) rename .pythonversion => .python-version (100%) diff --git a/.pythonversion b/.python-version similarity index 100% rename from .pythonversion rename to .python-version diff --git a/tembo/journal/pages.py b/tembo/journal/pages.py index 72238a6..ae5b796 100644 --- a/tembo/journal/pages.py +++ b/tembo/journal/pages.py @@ -3,7 +3,7 @@ from __future__ import annotations from abc import ABCMeta, abstractmethod import pathlib import re -from typing import Tuple +from typing import Tuple, Literal import jinja2 import pendulum @@ -69,8 +69,8 @@ class ScopedPageCreator(PageCreator): self.page_path = "" self.filename = "" self.extension = "" - self.path_error: MismatchedTokenError | None = None - self.template_error: MismatchedTokenError | None = None + self.path_date_tokens: Tuple[int, int] = (0, 0) + self.template_date_tokens: Tuple[int, int] = (0, 0) def create_page( @@ -94,7 +94,9 @@ class ScopedPageCreator(PageCreator): ) # substitute tokens in the filepath try: - path = pathlib.Path(self._substitute_tokens(str(path), user_input, name)) + path = pathlib.Path( + self._substitute_tokens(str(path), user_input, name, "path") + ) except MismatchedTokenError as mismatched_path_error: self.path_error = mismatched_path_error # get the template file @@ -103,7 +105,7 @@ class ScopedPageCreator(PageCreator): template_contents = self._load_template(self.base_path, template_filename) try: template_contents = self._substitute_tokens( - template_contents, user_input, name + template_contents, user_input, name, "template" ) except MismatchedTokenError as mismatched_template_error: self.template_error = mismatched_template_error @@ -117,32 +119,32 @@ class ScopedPageCreator(PageCreator): print("template_token_count > path_token_count") return ScopedPage(path, template_contents) - @staticmethod - def __mismatched_token_error( - path_error: MismatchedTokenError | None = None, - template_error: MismatchedTokenError | None = None, - ) -> None: - if isinstance(path_error, MismatchedTokenError): - path_token_count = path_error.args[0] - # logger.critical( - # "Your config specifies %s input tokens, you gave %s " "- exiting", - # path_error.args[0], - # path_error.args[1], - # ) - # raise SystemExit(1) - if isinstance(template_error, MismatchedTokenError): - template_token_count = template_error.args[0] - # logger.critical( - # "Your template specifies %s input tokens, you gave %s " "- exiting", - # template_error.args[0], - # template_error.args[1], - # ) - # raise SystemExit(1) - if path_token_count > template_token_count: - print("path_token_count > template_token_count") - elif template_token_count > path_token_count: - print("template_token_count > path_token_count") - raise SystemExit(1) + # @staticmethod + # def __mismatched_token_error( + # path_error: MismatchedTokenError | None = None, + # template_error: MismatchedTokenError | None = None, + # ) -> None: + # if isinstance(path_error, MismatchedTokenError): + # path_token_count = path_error.args[0] + # # logger.critical( + # # "Your config specifies %s input tokens, you gave %s " "- exiting", + # # path_error.args[0], + # # path_error.args[1], + # # ) + # # raise SystemExit(1) + # if isinstance(template_error, MismatchedTokenError): + # template_token_count = template_error.args[0] + # # logger.critical( + # # "Your template specifies %s input tokens, you gave %s " "- exiting", + # # template_error.args[0], + # # template_error.args[1], + # # ) + # # raise SystemExit(1) + # if path_token_count > template_token_count: + # print("path_token_count > template_token_count") + # elif template_token_count > path_token_count: + # print("template_token_count > path_token_count") + # raise SystemExit(1) # TODO: change the annotation to include the error def _substitute_tokens( @@ -150,6 +152,7 @@ class ScopedPageCreator(PageCreator): tokenified_string: str, user_input: Tuple[str, ...] | Tuple[()], name: str, + token_type: Literal["path", "template"], ) -> str: # for a tokened string, substitute input, name and date tokens try: @@ -170,9 +173,9 @@ class ScopedPageCreator(PageCreator): tokenified_string = tokenified_string.replace(extracted_input, name) return tokenified_string - @staticmethod + # @staticmethod def __substitute_input_tokens( - tokenified_string: str, user_input: Tuple[str, ...] | Tuple[()] + self, tokenified_string: str, user_input: Tuple[str, ...] | Tuple[()] ) -> str: # find {inputN} tokens in string input_extraction = re.findall(r"(\{input\d*\})", tokenified_string) diff --git a/tests/__pycache__/__init__.cpython-38.pyc b/tests/__pycache__/__init__.cpython-38.pyc index 317d9d6aaf71c8b397ae2f32e1fe62869844b8e8..b550fe0f02174128a0407f6693b2cad3bd046cc2 100644 GIT binary patch delta 38 scmbQvIE9frl$V!_0SF%Tl}_ZgVYAfF$j?ok=qJuvS(1^TH!(*W0JlX7+W-In delta 41 vcmbQjIGvF@l$V!_0SNx<=TGFeVYkr_Elw>ep6DyiUX-7enp{#mF;g1=(-#ZI diff --git a/tests/__pycache__/test_tembo.cpython-38-pytest-6.2.5.pyc b/tests/__pycache__/test_tembo.cpython-38-pytest-6.2.5.pyc index 6bfba605c4f36b2dac1d7e1d38aa0f7acf251d64..91d170683e0a5178f624bc17758ff960e5cf6636 100644 GIT binary patch delta 38 scmbQqIE|4zl$V!_0SJWpODA&MuvzP8TEXl~vo0y{u0HenW6aWAK delta 41 vcmbQnIFpe(l$V!_0SLOY^CxoKu-oZ}7N-^!PxKXMFUrqKO)e>(n5hc@&4&w?