sigal icon indicating copy to clipboard operation
sigal copied to clipboard

KeyError after adding a directory to exclude patterns

Open JulienPalard opened this issue 1 year ago • 1 comments

I noticed I had a .venv in my output so I added .venv to ignore_directories, but then I got:

Traceback (most recent call last):
  File "./.venv/bin/sigal", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "./.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.11/site-packages/sigal/__main__.py", line 190, in build
    gal.build(force=force_album if len(force_album) else force)
  File "./.venv/lib/python3.11/site-packages/sigal/gallery.py", line 916, in build
    album_writer.write(album)
  File "./.venv/lib/python3.11/site-packages/sigal/writer.py", line 150, in write
    page = self.template.render(**context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "./.venv/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "./.venv/lib/python3.11/site-packages/sigal/themes/colorbox/templates/album.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "./.venv/lib/python3.11/site-packages/sigal/themes/colorbox/templates/base.html", line 40, in top-level template code
    {% include 'breadcrumb.html' %}
^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.11/site-packages/sigal/themes/default/templates/breadcrumb.html", line 1, in top-level template code
    {% if album.breadcrumb %}
  File "./.venv/lib/python3.11/site-packages/jinja2/environment.py", line 485, in getattr
    return getattr(obj, attribute)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.11/site-packages/sigal/gallery.py", line 684, in breadcrumb
    breadcrumb.append((url, self.gallery.albums[path].title))
                            ~~~~~~~~~~~~~~~~~~~^^^^^^
KeyError: '.venv'

with sigal, version 2.4

JulienPalard avatar Mar 31 '24 16:03 JulienPalard

I found a problem in the ignore_directories logic, hopefully 114f4e2d42c3fb3526b47418a1cd1de44f948b44 should fix that.

saimn avatar Apr 02 '24 19:04 saimn

It does not looks enough, I'm tried the patch and I'm now getting:

KeyError: '.venv/lib64'

JulienPalard avatar Aug 04 '24 14:08 JulienPalard

@JulienPalard - I couldn't reproduce (see commit above), it works for me with ignore_directories = [".venv*"]. Maybe you forgot the star ?

saimn avatar Sep 30 '24 07:09 saimn

For the record, I reproduced the bug by setting ignore_directories = ["venv/*"] with a virtualenv directory named venv.

Removing the slash from the pattern solved the issue in my case.

Lucas-C avatar Aug 16 '25 01:08 Lucas-C