f49733adcac8 — Nolan Prescott 2 years ago
Remove f-string formatting, the bleeding-edge sucks

F-string formatting isn't worth the headaches associated with getting
a CI system configured correctly with a non-package build of python
3.6. I'd rather _not_ be tied to testing on a linux distro I don't
deploy to.
4 files changed, 39 insertions(+), 22 deletions(-)

M quiescent/bootstrap.py
M quiescent/post.py
M quiescent/static.py
M quiescent/templite.py
M quiescent/bootstrap.py +4 -2
@@ 87,11 87,13 @@ feed link = feed.atom
         try:
             os.makedirs(directory)
         except Exception:
-            logger.warning(f'{directory} directory already exists')
+            logger.warning('{directory} directory already exists'
+                           .format(directory=directory)
 
     for each_file, template in (config, index, archive, post):
         try:
             with open(each_file, 'x') as f:
                 f.write(template)
         except FileExistsError:
-            logger.warning(f'{each_file} already exists')
+            logger.warning('{each_file} already exists'
+                           .format(each_file=each_file)

          
M quiescent/post.py +6 -3
@@ 48,7 48,8 @@ class Post:
         return self.body == other.body
 
     def __repr__(self):
-        return f'<Post: {self.title}, {self.date}>'
+        return ('<Post: {title}, {date}>'
+                .format(title=self.title, date=self.date))
 
     def parse(self, raw_text):
         '''

          
@@ 60,14 61,16 @@ class Post:
             meta, body = self._split(raw_text)
             post.title = meta['title']
             post.slug = slugify(post.title)
-            post.path = os.path.join(self.relative_dir, f'{post.slug}.html')
+            post.path = os.path.join(self.relative_dir,
+                                     '{slug}.html'.format(slug=post.slug))
             post._date = self._parse_date(meta['date'])
             post.date = post._date.strftime('%Y-%m-%d')
             post.body = self.markdown(body)
             post.leader = self.markdown(self._parse_leader(body))
             return post
         except (ValueError, KeyError, TypeError) as e:
-            raise ValueError(f'Unable to parse post from:\n{raw_text[:50]}')
+            raise ValueError('Unable to parse post from:\n{text}'
+                             .format(text=raw_text[:50]))
 
     @staticmethod
     def _split(text):

          
M quiescent/static.py +2 -1
@@ 102,7 102,8 @@ class StaticGenerator:
                 post = Post(relative_dir=relative_dir).parse(text)
                 self.all_posts.append(post)
             except ValueError as e:
-                logger.warning(f'Failed to create post: {post}\n\t{e}')
+                logger.warning('Failed to create post: {post}\n\t{e}'
+                               .format(post=post, e=e))
         self.all_posts = sorted(self.all_posts)
 
     def render_page(self, template_name, **kwargs):

          
M quiescent/templite.py +27 -16
@@ 83,44 83,55 @@ class Templite:
         for token in tokens:
             if token.startswith('{{'):
                 expression = self._expr_code(token[2:-2].strip())
-                code.add_line(f'result.append(str({expression}))')
+                code.add_line('result.append(str({expression}))'
+                              .format(expression=expression))
             elif token.startswith('{%'):
                 words = token[2:-2].strip().split()
                 if words[0] == 'if':
                     if len(words) != 2:
-                        raise TempliteSyntaxError(f'Bad syntax:\n\t{token}')
+                        raise TempliteSyntaxError('Bad syntax:\n\t{token}'
+                                                  .format(token=token))
                     operations_stack.append('if')
-                    code.add_line(f'if {self._expr_code(words[1])}:')
+                    code.add_line('if {statement}:'
+                                  .format(statement=self._expr_code(words[1])))
                     code.indent()
                 elif words[0] == 'for':
                     if len(words) != 4 or words[2] != 'in':
-                        raise TempliteSyntaxError(f'Bad syntax:\n\t{token}')
+                        raise TempliteSyntaxError('Bad syntax:\n\t{token}'
+                                                  .format(token=token))
                     operations_stack.append('for')
                     self._variable(words[1], self.loop_variables)
-                    code.add_line(
-                        f'for c_{words[1]} in {self._expr_code(words[3])}:')
+                    code.add_line('for c_{word} in {thing}:'
+                                  .format(word=words[1], thing=self._expr_code(words[3])))
                     code.indent()
                 elif words[0].startswith('end'):
                     if len(words) != 1:
-                        raise TempliteSyntaxError(f'Bad syntax:\n\t{token}')
+                        raise TempliteSyntaxError('Bad syntax:\n\t{token}'
+                                                  .format(token=token))
                     end_type = words[0].lstrip('end')
                     if not operations_stack:
-                        raise TempliteSyntaxError(f'Bad syntax:\n\t{token}')
+                        raise TempliteSyntaxError('Bad syntax:\n\t{token}'
+                                                  .format(token=token))
                     if end_type != operations_stack.pop():
-                        raise TempliteSyntaxError(f'Bad syntax:\n\t{token}')
+                        raise TempliteSyntaxError('Bad syntax:\n\t{token}'
+                                                  .format(token=token))
                     code.dedent()
                 else:
-                    raise TempliteSyntaxError(f'Bad syntax:\n\t{token}')
+                    raise TempliteSyntaxError('Bad syntax:\n\t{token}'
+                                              .format(token=token))
             else:
                 if token:
-                    code.add_line(f'result.append({repr(token)})')
+                    code.add_line('result.append({thing})'
+                                  .format(thing=repr(token)))
 
         if operations_stack:
             raise TempliteSyntaxError(
-                f'Bad syntax, unmatched action:\n\t{operations_stack[-1]}')
+                'Bad syntax, unmatched action:\n\t{end_of_stack}'
+                .format(end_of_stack=operations_stack[-1]))
 
         for variable in self.all_variables - self.loop_variables:
-            variable_code.add_line(f'c_{variable} = context[{repr(variable)}]')
+            variable_code.add_line('c_{variable} = context[{_repr}]'
+                                   .format(variable=variable, _repr=repr(variable)))
         code.add_line("return ''.join(result)")
         code.dedent()
         self._render_function = code.get_globals()['render_function']

          
@@ 130,15 141,15 @@ class Templite:
             dots = expression.split('.')
             code = self._expr_code(dots[0])
             args = ', '.join(repr(d) for d in dots[1:])
-            code = f'do_dots({code}, {args})'
+            code = 'do_dots({code}, {args})'.format(code=code, args=args)
         else:
             self._variable(expression, self.all_variables)
-            code = f'c_{expression}'
+            code = 'c_{expression}'.format(expression=expression)
         return code
 
     def _variable(self, name, variable_set):
         if not re.match(r'[_a-zA-Z][_a-zA-Z0-9]*$', name):
-            raise TempliteSyntaxError(f'Invalid name: {name}')
+            raise TempliteSyntaxError('Invalid name: {name}'.format(name=name))
         variable_set.add(name)
 
     def render(self, context=None):