-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
Fix non-unique heading anchors on changelog doc page #1942
Fix non-unique heading anchors on changelog doc page #1942
Conversation
8546b12
to
00c879a
Compare
00c879a
to
040c7c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is good, but the implementation needs polishing:
- The proper thing to do here is to use the extension interface and not throw arbitrarily loaded modules in the docs dir. Use
_ext/
and make sphinx load it as an extension with it's ownsetup()
. - There's several maintenance/functional improvements in the comments below.
- Finally, let's try to drop the dates from anchors, as it'd be cleaner and more predictable to link releases. Links like https://cheroot.cherrypy.dev/en/latest/history/#v11-0-0 and https://setuptools.pypa.io/en/latest/history.html#v68-0-0 are nicer and can be constructed by guessing from the release versions/repo tags.
@@ -0,0 +1,34 @@ | |||
from __future__ import annotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to the _ext/
subir per convention.
@@ -57,3 +64,9 @@ | |||
] | |||
|
|||
suppress_warnings = ["myst.xref_missing"] | |||
|
|||
|
|||
def setup(app: Sphinx) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't add setup()
here but put it into an extension under _ext/
.
Also, it should return a dict.
|
||
|
||
def setup(app: Sphinx) -> None: | ||
from docs.utils import TransformSectionIdToName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed, especially upon moving to the extension. Just add the extension to the list above and Sphinx will load it through the standard means.
from sphinx.util import logging | ||
from sphinx.util.console import bold | ||
|
||
# Add the docs/ directory to sys.path to be able to import utils | ||
docs_dir = os.path.dirname(os.path.dirname(__file__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plz use pathlib and only convert to str on insert.
from importlib.metadata import version as get_version | ||
from pathlib import Path | ||
|
||
from sphinx.application import Sphinx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously, this won't be necessary upon moving to a proper extension.
numerical_id = re.compile(r"^id[0-9]+$") | ||
|
||
|
||
class TransformSectionIdToName(SphinxTransform): # type: ignore[misc] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this ignore?
|
||
default_priority = SortIds.default_priority + 1 | ||
|
||
def apply(self, **kwargs: Any) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns none, not any.
if not node_ids: | ||
return False | ||
|
||
if len(node_ids) != 1: | ||
return False | ||
|
||
return bool(numerical_id.match(node_ids[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified:
if not node_ids: | |
return False | |
if len(node_ids) != 1: | |
return False | |
return bool(numerical_id.match(node_ids[0])) | |
node_has_single_id = len(node_ids) == 1 | |
return node_has_single_id and | |
numerical_id.match(node_ids[0]) is not None |
return bool(numerical_id.match(node_ids[0])) | ||
|
||
def _transform_id_to_name(self, node: nodes.section) -> None: | ||
node["ids"] = [nodes.make_id("id " + name) for name in node["names"]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String concatenation is slow.
node["ids"] = [nodes.make_id("id " + name) for name in node["names"]] | |
node["ids"] = [nodes.make_id(f"id {node_name}") for node_name in node["names"]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't add Python modules among the normal documents.
Fixes #1935.
Contributor checklist
Maintainer checklist
backwards incompatible
,feature
,enhancement
,deprecation
,bug
,dependency
,docs
orskip-changelog
as they determine changelog listing.