Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jinja2.exceptions.TemplateSyntaxError #399

Closed
speeskeek opened this issue Jul 28, 2020 · 6 comments
Closed

jinja2.exceptions.TemplateSyntaxError #399

speeskeek opened this issue Jul 28, 2020 · 6 comments
Milestone

Comments

@speeskeek
Copy link

speeskeek commented Jul 28, 2020

Hello,

I got sigal on my old NAS, now I got a new one but cant get Sigal to work.
I get errors It's a arm-config instead of a x86. But that shouldn't make a difference with pyhton?

see below for the error.

I'm on debian 10.4
with Python 3.7.3
and sigal 2.1

root@HomeCloud:/media/internal-disk/Foto# sigal build 2020/2020\ Verjaardag\ Noah/ web-gallery/
Collecting albums, done.
Traceback (most recent call last):
  File "/usr/local/bin/sigal", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/sigal/__init__.py", line 157, in build
    gal.build(force=force)
  File "/usr/local/lib/python3.7/dist-packages/sigal/gallery.py", line 735, in build
    album_writer.write(album)
  File "/usr/local/lib/python3.7/dist-packages/sigal/writer.py", line 118, in write
    page = self.template.render(**context)
  File "/usr/lib/python3/dist-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.7/dist-packages/sigal/themes/default/templates/decrypt.html", line 1, in template
    {% if 'sigal.plugins.encrypt' is in settings.plugins %}
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 1005, in render
    return concat(self.root_render_func(self.new_context(vars)))
  File "/usr/local/lib/python3.7/dist-packages/sigal/themes/galleria/templates/album.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "/usr/local/lib/python3.7/dist-packages/sigal/themes/galleria/templates/base.html", line 17, in top-level template code
    {% include 'decrypt.html' %}
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.7/dist-packages/sigal/themes/default/templates/decrypt.html", line 1, in template
    {% if 'sigal.plugins.encrypt' is in settings.plugins %}
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 497, in _parse
    return Parser(self, source, name, encode_filename(filename)).parse()
  File "/usr/lib/python3/dist-packages/jinja2/parser.py", line 901, in parse
    result = nodes.Template(self.subparse(), lineno=1)
  File "/usr/lib/python3/dist-packages/jinja2/parser.py", line 883, in subparse
    rv = self.parse_statement()
  File "/usr/lib/python3/dist-packages/jinja2/parser.py", line 130, in parse_statement
    return getattr(self, 'parse_' + self.stream.current.value)()
  File "/usr/lib/python3/dist-packages/jinja2/parser.py", line 212, in parse_if
    node.body = self.parse_statements(('name:elif', 'name:else',
  File "/usr/lib/python3/dist-packages/jinja2/parser.py", line 164, in parse_statements
    self.stream.expect('block_end')
  File "/usr/lib/python3/dist-packages/jinja2/lexer.py", line 384, in expect
    self.name, self.filename)
jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got '.'
@saimn
Copy link
Owner

saimn commented Aug 1, 2020

arm should not make a difference indeed, but I don't really understand where the error comes from. Did you modify the template ?

@roesel
Copy link

roesel commented Aug 2, 2020

I just tried to run sigal today, freshly installed with pip on Windows 10, ran sigal init, kept the default config, put images into a freshly made pictures folder, tried to run sigal build and got the same error as @speeskeek . Same for both colorbox and galleria.

Python 3.7.4
Windows 10, build 18363
sigal 2.1

Full traceback follows:

C:\Users\****\Desktop\gal>sigal build
Collecting albums, done.
Traceback (most recent call last):
File "c:\programs\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
	"__main__", mod_spec)
File "c:\programs\anaconda3\lib\runpy.py", line 85, in _run_code
	exec(code, run_globals)
File "C:\Programs\Anaconda3\Scripts\sigal.exe\__main__.py", line 9, in <module>
File "c:\programs\anaconda3\lib\site-packages\click\core.py", line 764, in __call__
	return self.main(*args, **kwargs)
File "c:\programs\anaconda3\lib\site-packages\click\core.py", line 717, in main
	rv = self.invoke(ctx)
File "c:\programs\anaconda3\lib\site-packages\click\core.py", line 1137, in invoke
	return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\programs\anaconda3\lib\site-packages\click\core.py", line 956, in invoke
	return ctx.invoke(self.callback, **ctx.params)
File "c:\programs\anaconda3\lib\site-packages\click\core.py", line 555, in invoke
	return callback(*args, **kwargs)
File "c:\programs\anaconda3\lib\site-packages\sigal\__init__.py", line 157, in build
	gal.build(force=force)
File "c:\programs\anaconda3\lib\site-packages\sigal\gallery.py", line 735, in build
	album_writer.write(album)
File "c:\programs\anaconda3\lib\site-packages\sigal\writer.py", line 118, in write
	page = self.template.render(**context)
File "c:\programs\anaconda3\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
	return original_render(self, *args, **kwargs)
File "c:\programs\anaconda3\lib\site-packages\jinja2\environment.py", line 1008, in render
	return self.environment.handle_exception(exc_info, True)
File "c:\programs\anaconda3\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
	reraise(exc_type, exc_value, tb)
File "c:\programs\anaconda3\lib\site-packages\jinja2\_compat.py", line 37, in reraise
	raise value.with_traceback(tb)
File "c:\programs\anaconda3\lib\site-packages\sigal\themes\default\templates\decrypt.html", line 1, in template
	{% if 'sigal.plugins.encrypt' is in settings.plugins %}
File "c:\programs\anaconda3\lib\site-packages\jinja2\environment.py", line 1005, in render
	return concat(self.root_render_func(self.new_context(vars)))
File "c:\programs\anaconda3\lib\site-packages\sigal\themes\colorbox\templates\album.html", line 14, in root
	{% endif %}
File "c:\programs\anaconda3\lib\site-packages\sigal\themes\colorbox\templates\base.html", line 26, in root
	{% else %}
File "c:\programs\anaconda3\lib\site-packages\jinja2\environment.py", line 830, in get_template
	return self._load_template(name, self.make_globals(globals))
File "c:\programs\anaconda3\lib\site-packages\jinja2\environment.py", line 804, in _load_template
	template = self.loader.load(self, name, globals)
File "c:\programs\anaconda3\lib\site-packages\jinja2\loaders.py", line 405, in load
	return loader.load(environment, name, globals)
File "c:\programs\anaconda3\lib\site-packages\jinja2\loaders.py", line 125, in load
	code = environment.compile(source, name, filename)
File "c:\programs\anaconda3\lib\site-packages\jinja2\environment.py", line 591, in compile
	self.handle_exception(exc_info, source_hint=source_hint)
File "c:\programs\anaconda3\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
	reraise(exc_type, exc_value, tb)
File "c:\programs\anaconda3\lib\site-packages\jinja2\_compat.py", line 37, in reraise
	raise value.with_traceback(tb)
File "c:\programs\anaconda3\lib\site-packages\sigal\themes\default\templates\decrypt.html", line 1, in template
	{% if 'sigal.plugins.encrypt' is in settings.plugins %}
File "c:\programs\anaconda3\lib\site-packages\jinja2\environment.py", line 497, in _parse
	return Parser(self, source, name, encode_filename(filename)).parse()
File "c:\programs\anaconda3\lib\site-packages\jinja2\parser.py", line 901, in parse
	result = nodes.Template(self.subparse(), lineno=1)
File "c:\programs\anaconda3\lib\site-packages\jinja2\parser.py", line 883, in subparse
	rv = self.parse_statement()
File "c:\programs\anaconda3\lib\site-packages\jinja2\parser.py", line 130, in parse_statement
	return getattr(self, 'parse_' + self.stream.current.value)()
File "c:\programs\anaconda3\lib\site-packages\jinja2\parser.py", line 212, in parse_if
	node.body = self.parse_statements(('name:elif', 'name:else',
File "c:\programs\anaconda3\lib\site-packages\jinja2\parser.py", line 164, in parse_statements
	self.stream.expect('block_end')
File "c:\programs\anaconda3\lib\site-packages\jinja2\lexer.py", line 384, in expect
	self.name, self.filename)
jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got '.'

Let me know if there is any more information I could provide to help fix this issue.

@saimn
Copy link
Owner

saimn commented Aug 2, 2020

Weird! I'm not sure everything works correctly on Windows, but since you get the same error as @speeskeek I guess that's another issue.

  • What is your jinja2 version ?
  • Could you replace {% if 'sigal.plugins.encrypt' is in settings.plugins %} with {% if 'sigal.plugins.encrypt' in settings.plugins %} ? In themes\default\templates\decrypt.html.
  • Could you paste your settings ?

@roesel
Copy link

roesel commented Aug 3, 2020

Let me try to answer your questions:

  • What is your jinja2 version? 2.10.3
  • Could you replace {% if 'sigal.plugins.encrypt' is in settings.plugins %} with {% if 'sigal.plugins.encrypt' in settings.plugins %}? In themes\default\templates\decrypt.html. I can and that does seem to do the trick, the build now completes.
  • Could you paste your settings? The settings are the default - generated by the sigal build command. But the paste follows:
# All configuration values have a default; values that are commented out serve
# to show the default. Default values are specified when modified in this
# example config file

# Gallery title. Can be set here or as the '--title' option of the `sigal
# build` command, or in the 'index.md' file of the source directory.
# The priority order is: cli option > settings file > index.md file
# title = "Sigal test gallery"

# ---------------------
# General configuration
# ---------------------

# Source directory. Can be set here or as the first argument of the `sigal
# build` command
source = 'pictures'

# Destination directory. Can be set here or as the second argument of the
# `sigal build` command (default: '_build')
# destination = '_build'

# Theme :
# - colorbox (default), galleria, photoswipe, or the path to a custom theme
# directory
theme = 'galleria'

# Author. Used in the footer of the pages and in the author meta tag.
# author = ''

# Use originals in gallery (default: False). If True, this will bypass all
# processing steps (resize, auto-orient, recompress, and any plugin-specific
# step).
# Originals will be symlinked if orig_link = True, else they will be copied.
# use_orig = False

# ----------------
# Image processing (ignored if use_orig = True)
# ----------------

# Size of resized image (default: (640, 480))
img_size = (800, 600)

# Output format of images (default: None, i.e. use input format)
# img_format = "JPEG"

# Show a map of the images where possible?
# This option only has an effect on the galleria theme for the while.
# The leaflet_provider setting allow to customize the tile provider (see
# https://github.com/leaflet-extras/leaflet-providers#providers)
# show_map = False
# leaflet_provider = 'OpenStreetMap.Mapnik'

# File extensions that should be treated as images
# img_extensions = ['.jpg', '.jpeg', '.png', '.gif']

# Pilkit processor used to resize the image
# (see http://pilkit.readthedocs.org/en/latest/#processors)
# - ResizeToFit: fit the image within the specified dimensions (default)
# - ResizeToFill: crop THE IMAGE it to the exact specified width and height
# - SmartResize: identical to ResizeToFill, but uses entropy to crop the image
# - None: don't resize
# img_processor = 'ResizeToFit'

# Autorotate images
# Warning: this setting is not compatible with `copy_exif_data` (see below),
# because Sigal can't save the modified Orientation tag (currently Pillow can't
# write EXIF).
# autorotate_images = True

# If True, EXIF data from the original image is copied to the resized image
# copy_exif_data = False

# Python's datetime format string used for the EXIF date formatting
# https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
# datetime_format = '%c'

# Jpeg options
# jpg_options = {'quality': 85,
#                'optimize': True,
#                'progressive': True}

# --------------------
# Thumbnail generation
# --------------------

# Generate thumbnails
# make_thumbs = True

# Subdirectory of the thumbnails
# thumb_dir = 'thumbnails'

# Prefix and/or suffix for thumbnail filenames (default: '')
# thumb_prefix = ''
# thumb_suffix = '.tn'

# Thumbnail size (default: (200, 150))
# For the galleria theme, use 280 px for the width
# For the colorbox and photoswipe theme, use 200 px for the width
thumb_size = (280, 210)

# Crop the image to fill the box
# thumb_fit = True

# When using thumb_fit, specifies what we should crop
# for usage see
# http://pillow.readthedocs.io/en/stable/reference/ImageOps.html#PIL.ImageOps.fit
# thumb_fit_centering = (0.5, 0.5)

# Delay in seconds to avoid black thumbnails in videos with fade-in
# thumb_video_delay = '0'

# Keep original image (default: False)
# keep_orig = True

# Subdirectory for original images
# orig_dir = 'original'

# Use symbolic links instead of copying the original images
# orig_link = False

# Use symbolic links that are relative to the source directory instead of absolute paths
# rel_link = False

# Attribute of Album objects which is used to sort medias (eg 'title'). To sort
# on a metadata key, use 'meta.key'.
# albums_sort_attr = 'name'

# Reverse sort for albums
# albums_sort_reverse = False

# Attribute of Media objects which is used to sort medias. 'date' can be used
# to sort with EXIF dates, and 'meta.key' to sort on a metadata key (which then
# must exist for all images).
# medias_sort_attr = 'filename'

# Reverse sort for medias
# medias_sort_reverse = False

# Filter directories and files.
# The settings take a list of patterns matched with the fnmatch module on the
# path relative to the source directory:
# http://docs.python.org/2/library/fnmatch.html
ignore_directories = []
ignore_files = []

# -------------
# Video options
# -------------

# Video converter binary (can be 'avconv' on certain GNU/Linux distributions)
# video_converter = 'ffmpeg'

# File extensions that should be treated as video files
# video_extensions = ['.mov', '.avi', '.mp4', '.webm', '.ogv', '.3gp']

# Video format
# specify an alternative format, valid are 'webm' (default) and 'mp4'
# video_format = 'webm'

# Webm options
# Options used in ffmpeg to encode the webm video. You may want to read
# http://ffmpeg.org/trac/ffmpeg/wiki/vpxEncodingGuide
# Be aware of the fact these options need to be passed as strings. If you are
# using avconv (for example with Ubuntu), you will need to adapt the settings.
# webm_options = ['-crf', '10', '-b:v', '1.6M',
#                 '-qmin', '4', '-qmax', '63']

# MP4 options
# Options used to encode the mp4 video. You may want to read
# https://trac.ffmpeg.org/wiki/Encode/H.264
# mp4_options = ['-crf', '23' ]

# Size of resized video (default: (480, 360))
# video_size = (480, 360)

# -------------
# Miscellaneous
# -------------

# Write HTML files. If False, sigal will only process the images.
# write_html = True

# Name of the generated HTML files
# output_filename = 'index.html'

# Add output filename (see above) to the URLs
# index_in_url = False

# A list of links (tuples (title, URL))
# links = [('Example link', 'http://example.org'),
#          ('Another link', 'http://example.org')]

# Google Analytics tracking code (UA-xxxx-x)
# google_analytics = ''

# Google Tag Manager tracking code (GTM-xxxxxx)
# google_tag_manager = ''

# Piwik tracking
# tracker_url must not contain trailing slash.
# Example : {'tracker_url': 'http://stats.domain.com', 'site_id' : 2}
# piwik = {'tracker_url': '', 'site_id' : 0}

# Set zip_gallery to either False or a file name. The file name can be formatted
# python style with an 'album' variable, for example '{album.name}.zip'. The final archive will
# contain all resized or original files (depending on `zip_media_format`).
# zip_gallery = False   # False or 'archive.zip'
# zip_media_format = 'resized'  # 'resized' or 'orig'
# zip_skip_if_exists = False # Skip archive generation if archive is already present. Warning: new photos in an album won't be added to archive

# Specify a different locale. If set to '', the default locale is used.
# locale = ''

# Define language used on main <html> tag in templates
# html_language = 'en'

# List of files to copy from the source directory to the destination.
# A symbolic link is used if ``orig_link`` is set to True (see above).
# files_to_copy = (('extra/robots.txt', 'robots.txt'),
#                  ('extra/favicon.ico', 'favicon.ico'),)

# Colorbox theme config
# The column size is given in number of column of the css grid of the Skeleton
# framework which is used for this theme: http://www.getskeleton.com/#grid
# Then the image size must be adapted to fit the column size.
# The default is 3 columns (176px).
# colorbox_column_size = 3

# Site Logo - Use a logo file in the sidebar
# Only for colorbox currently, it could be adapted for other themes
# You must place the logo file into the theme's static images folder, which
# can be done using 'files_to_copy':
# files_to_copy = (('extra/logo.png', 'static/logo.png'))
# site_logo = 'logo.png'

# --------
# Plugins
# --------

# List of plugins to use. The values must be a path than can be imported.
# Another option is to import the plugin and put the module in the list, but
# this will break with the multiprocessing feature (the settings dict obtained
# from this file must be serializable).
# plugins = ['sigal.plugins.adjust', 'sigal.plugins.copyright',
#            'sigal.plugins.upload_s3', 'sigal.plugins.media_page',
#            'sigal.plugins.nomedia', 'sigal.plugins.extended_caching',
#            'sigal.plugins.encrypt']

# Add a copyright text on the image (default: '')
# copyright = "© An example copyright message"

# Adjust the image after resizing it. A default value of 1.0 leaves the images
# untouched.
# adjust_options = {'color': 1.0,
#                   'brightness': 1.0,
#                   'contrast': 1.0,
#                   'sharpness': 1.0}

# Settings for upload to s3 plugin
# upload_s3_options = {
# 	'bucket': 'my-bucket',
# 	'policy': 'public-read',
# 	'overwrite': False
# }

# Settings for compressing static assets
# compress_assets_options = {
#    'method': 'gzip' # Or 'zopfli' or 'brotli'
# }

# Settings for encryption plugin
# encrypt_options = {
#    'password': 'password',
#    'ask_password': False
# }

@saimn
Copy link
Owner

saimn commented Aug 4, 2020

Many thanks @roesel , I can reproduce with Jinja2 2.10.3, but it is not crashing with 2.11.2
And indeed replacing the is in with in fixes the issue. It seemed weird but I was not sure about this as I couldn't reproduce.
I will push a fix soon, thanks for the help in debugging the issue.

@saimn saimn closed this as completed in f33b663 Aug 4, 2020
@saimn saimn added this to the 2.1.1 milestone Aug 4, 2020
@roesel
Copy link

roesel commented Aug 4, 2020

Thank you for the fix and thank you for working on sigal, it's a great little library!

kontza pushed a commit to kontza/sigal that referenced this issue Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants