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

Convert FEED setting from %s to {slug}-style strings #2383

Closed
wants to merge 11 commits into from

Conversation

MinchinWeb
Copy link
Contributor

@MinchinWeb MinchinWeb commented Jul 12, 2018

Closes #2106

@justinmayer
Copy link
Member

@MinchinWeb: It appears Travis is reporting test failures. Could you take a look?

@MinchinWeb
Copy link
Contributor Author

MinchinWeb commented Jul 13, 2018

@justinmayer Success!

Flake8 issues have been fixed.

I have Pandoc v2.1.3 install locally and so some test fail due to that. See issues #2255 and #2322, and WIP PR #2289.

There are several other tests that fail locally (on Windows) for various reasons; some are things I haven't touched, so I'm leaving alone; some are due to 'symbolic link privilege not help'; some are due to Windows filepaths being written different than POSIX paths (these I skip now on Windows). These, as a whole, I'm ignoring.

The other broken test was a simple typo. Fixed now!

Python 3.7 has been released, but was failing to download on Travis; it can be added back at a later time.

@justinmayer
Copy link
Member

Would any @getpelican/reviewers be willing to take a moment and review this pull request?

@mosra
Copy link
Contributor

mosra commented Sep 12, 2018

Yay, I personally welcome the change to {}-style! (Was also wondering myself why feeds use %s while everything else is {}-style.) But I think this should be done in a backwards-compatible way. With your proposed change, all setting that had the old-style

CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'

would now result in feeds/%s.atom.xml put verbatim into the generated output, without any warning that something's wrong. Discovering such breakage in each affected site can then take months and that's bad. So instead just calling format(), I'd propose something like this:

self.settings['CATEGORY_FEED_ATOM']).format(slug=category.slug).replace('%s', category.slug)

And similarly elsewhere (maybe replace() first? not sure). That'll work for both approaches, with the replace() being removed some years later once the backwards compatibility is not needed anymore.

Besides that, the diff contains a lot of unnecessary formatting changes that make it very hard to review. Would it be possible to clean up the diff to not have them? Also, unrelated changes such as posix_path() or Windows test fixes could be better discussed in a separate PR.

@MinchinWeb
Copy link
Contributor Author

@mosra : I like you suggestion of how to support the two styles. I searched for examples of how to do this, and never did find anything useful...

Regarding the "extra" pieces, some of the reformatting is from the different lengths of {slug} vs %s, some was for line-length consistency. The second group could be removed, but there is no automated way to do it, I'd basically have to completely rebuilding the patch. The posix_path() changes again were for consistency. If you really want these two pieces out, I could maybe pull them out to a new PR, and then rebase this one on top of it. Is is worth the extra effort?

The Windows testing issues are similar (they could be pulled to a separate PR, and this one rebased on to it), but they were needed to get this far: when I first ran the test suite locally (on my Windows machine), a huge swatch of the tests failed, and so it was very hard to know what, if any, tests I had broken. Making the tests behave more sanely was the faster alternative to spamming Travis and crossing my fingers.

@MinchinWeb
Copy link
Contributor Author

MinchinWeb commented Sep 18, 2018

@justinmayer @mosra : both old-style and new-style text substitutes are now supported!

self.settings['CATEGORY_FEED_ATOM'].replace('%s', '{slug}')
                                   .format(slug=cat.slug),

@@ -400,7 +402,8 @@ def generate_feeds(self, writer):
writer.write_feed(
arts,
self.context,
self.settings['TAG_FEED_ATOM'].format(tag.slug),
self.settings['TAG_FEED_ATOM'].replace('%s', '{slug}')
.format(tag.slug),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not .format(slug=tag.slug) here (and the two cases below)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. It's been fixed!

@avaris
Copy link
Member

avaris commented Oct 2, 2018

Sorry for late-ish response but, I don't really like the %s replacement.

For one, it'd fail if you have {}s around %s:

>>> '%s'.replace('%s', '{slug}').format(slug='foo')
'foo'
>>> '{%s}'.replace('%s', '{slug}').format(slug='foo')
'{slug}'
>>> '{%s'.replace('%s', '{slug}').format(slug='foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Single '}' encountered in format string

Second, I'd rather have these handled when the settings file is read (in settings.py).

And I'd propose throwing a warning and falling back to the default in case %s is in these settings.

@MinchinWeb
Copy link
Contributor Author

@avaris I like the idea of moving the conversion to the settings.py file.

I'm not sure what to do about the errors you mention, and I haven't found an example online support both string styles at the same time. Do we throw an error on %s strings, and make the users upgrade? Do we throw a warning, try the conversion, and hope for the best?

@avaris
Copy link
Member

avaris commented Oct 4, 2018

A check in settings.py. If '%s' is in the string, then throw a warning about deprecation, replace it from the DEFAULT_CONFIG. Something like:

for KEY in list_of_feed_setting_keys:
    if '%s' in setting[KEY]:
        logger.warning('%%s usage in %s is deprecated, use {name} instead. Falling back to default'. KEY)
        setting[KEY] = DEFAULT_CONFIG[KEY]

Very similar to this.

@MinchinWeb MinchinWeb force-pushed the feed-slugs branch 2 times, most recently from 39e2820 to fba4c84 Compare October 13, 2018 15:40
rather than trying to update them in place. Relies on the user to make the needed changes. Fallback is the default setting.
@MinchinWeb
Copy link
Contributor Author

@avaris @mosra : I've moved to avaris' suggestion of complaining of old style settings when the settings are first loaded and falling back to the default in this case. I'm of slightly mixed feeling as it requires the user to actively update their settings to work with the new Pelican version, and doesn't support backwards-compatibility, but on the other hand it avoids a bunch of odd corner cases that are hard to detect and resolve automatically. But "explicit is better than implicit", so let's go with it.

Does something in the documentation need to be added to explain this change?

The failing test is due to a change in how Markdown v3 outputs HTML for footnotes. The fix has been submitted separately as PR #2417.

@justinmayer
Copy link
Member

@avaris / @mosra: Any further comments on @MinchinWeb's pull request?

@avaris
Copy link
Member

avaris commented Oct 30, 2018

Stuff related to this PR is OK, but there are a lot of unrelated stuff (some unwarranted formatting changes, tox?? etc) attached to it. Is it possible to clean this up a bit?

@avaris avaris closed this Oct 30, 2018
@avaris avaris reopened this Oct 30, 2018
@justinmayer
Copy link
Member

@MinchinWeb: I agree it's best to keep pull requests as discrete and digestible as possible. Could you take a look and perhaps move anything not directly related to issue 2106 into separate pull requests?

@MinchinWeb
Copy link
Contributor Author

It can be done, but it does seem like "busy work" rather than "fun work". And I don't understand what it adds.

@avaris
Copy link
Member

avaris commented Nov 2, 2018

It's more about what it removes, which is the unrelated stuff reviewers have to go over otherwise.

@MinchinWeb
Copy link
Contributor Author

7 Pull Requests and 5 hours later, the pieces of this have all been split apart. #2432 is the core functionality I set out to add. I hope the various pull requests can be merged quickly and cleanly.

justinmayer pushed a commit that referenced this pull request Nov 3, 2018
* Convert FEED settings from `%s` to `{slug}` redux

Closes #2106, Closes #2383
@MinchinWeb MinchinWeb deleted the feed-slugs branch November 22, 2018 05:12
pedrohdz pushed a commit to pedrohdz/pelican-themes that referenced this pull request Jan 20, 2019
Since Pelican 4.0, `CATEGORY_FEED_ATOM` and `TAG_FEED_ATOM` are expected
to use `{slug}`, not `%s`. Seems to have been introduced in
getpelican/pelican#2383.

This would cause the following error:

```
CRITICAL: TypeError: not all arguments converted during string formatting
```

This change allows for backwards and forward compatibility.
pedrohdz added a commit to pedrohdz/pelican-themes that referenced this pull request Jan 20, 2019
Since Pelican 4.0, `CATEGORY_FEED_ATOM` and `TAG_FEED_ATOM` are expected
to use `{slug}`, not `%s`. Seems to have been introduced in
getpelican/pelican#2383.

This would cause the following error:

```
CRITICAL: TypeError: not all arguments converted during string formatting
```

This change allows for backwards and forward compatibility.
StevenMaude pushed a commit to StevenMaude/pelican-bootstrap3-sm that referenced this pull request Nov 26, 2019
Since Pelican 4.0, `CATEGORY_FEED_ATOM` and `TAG_FEED_ATOM` are expected
to use `{slug}`, not `%s`. Seems to have been introduced in
getpelican/pelican#2383.

This would cause the following error:

```
CRITICAL: TypeError: not all arguments converted during string formatting
```

This change allows for backwards and forward compatibility.

Cherry picked from commit
getpelican/pelican-themes@be0a410.
MinchinWeb added a commit to MinchinWeb/pelican that referenced this pull request Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants