Skip to content

Fix Python deprecation warnings (LOGGER.warn, datetime.utcnow, docutils 2.0)#3894

Open
arunpersaud wants to merge 5 commits into
getnikola:masterfrom
arunpersaud:deprecated
Open

Fix Python deprecation warnings (LOGGER.warn, datetime.utcnow, docutils 2.0)#3894
arunpersaud wants to merge 5 commits into
getnikola:masterfrom
arunpersaud:deprecated

Conversation

@arunpersaud

Copy link
Copy Markdown
Contributor

Pull Request Checklist

  • I’ve read the guidelines for contributing.
  • I updated AUTHORS.txt and CHANGES.txt (if the change is non-trivial) and documentation (if applicable).
  • I tested my changes.

Description

Updates deprecated APIs to their modern equivalents for better Python 3.13+ compatibility. These showed up in 'ty' and pytest.

@felixfontein felixfontein left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While most changes look good, I'm not sure requiring docutils >= 0.22 is a good idea. 0.22 got released less than a year ago, and is likely not available on some of the platforms Nikola should work on. Ubuntu 24.04 for example only 0.20.1, and even Ubuntu 25.10 only has 0.21.2. (Ubuntu 26.04 has 0.22.4.)

Comment thread nikola/plugins/compile/rest/listing.py Outdated
from docutils import nodes
from docutils.parsers.rst import Directive, directives
from docutils.parsers.rst.roles import set_classes
from docutils.parsers.rst.roles import normalize_options

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here I would use a conditional import:

Suggested change
from docutils.parsers.rst.roles import normalize_options
try:
from docutils.parsers.rst.roles import normalize_options
except ImportError:
from docutils.parsers.rst.roles import set_classes as normalize_options

This way it also works with docutils < 0.22.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point, reverted this partially and added the above

settings=settings,
source_class=source_class,
destination_class=docutils.io.StringOutput)
pub.set_components(None, parser_name, writer_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This one is harder. Maybe conditional code based on the docutils version will work here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just reverted this for now

…the deprecated warning using normalize_options when available
@arunpersaud

Copy link
Copy Markdown
Contributor Author

@felixfontein thanks for looking at this. Let me know if this looks better

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

Successfully merging this pull request may close these issues.

2 participants