Migrating from Pelican 3 to Pelican 4

2019-01-23 - Louis-Philippe Véronneau

A couple of days ago, pelican got updated from version 3.7.1 in testing to 4.0.1. Good news is that it's now written in Python 3, bad news is that breaking changes in the main configuration file need to be made.

Here's two things you'll need to change in pelicanconf.py to migrate:

1. %s in the Atom feed path needs to be replaced by either {slug} or {lang}, depending on the variable.

For example:

-TAG_FEED_ATOM = 'feeds/tags/%s.atom.xml'
+TAG_FEED_ATOM = 'feeds/tags/{slug}.atom.xml'

2. FEED_MAX_ITEMS now needs to be an integer and not a string.

My previous configuration had FEED_MAX_ITEMS = '20' and this crashed pelican with this error:

CRITICAL: TypeError: '<' not supported between instances of 'int' and 'str'
Traceback (most recent call last):
  File "/usr/bin/pelican", line 11, in <module>
    load_entry_point('pelican==4.0.1', 'console_scripts', 'pelican')()
  File "/usr/lib/python3/dist-packages/pelican/__init__.py", line 623, in main
    pelican.run()
  File "/usr/lib/python3/dist-packages/pelican/__init__.py", line 190, in run
    p.generate_output(writer)
  File "/usr/lib/python3/dist-packages/pelican/generators.py", line 688, in generate_output
    self.generate_feeds(writer)
  File "/usr/lib/python3/dist-packages/pelican/generators.py", line 335, in generate_feeds
    self.settings['FEED_ALL_ATOM'])
  File "/usr/lib/python3/dist-packages/pelican/writers.py", line 131, in write_feed
    max_items = min(self.settings['FEED_MAX_ITEMS'], max_items)
TypeError: '<' not supported between instances of 'int' and 'str'

This can be fixed this way:

-FEED_MAX_ITEMS = '20'
+FEED_MAX_ITEMS = 20

debianpelican