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

Fix non-unique heading anchors on changelog doc page #1942

Closed

Conversation

atugushev
Copy link
Member

Fixes #1935.

Contributor checklist
  • Provided the tests for the changes.
  • Assure PR title is short, clear, and good to be included in the user-oriented changelog
Maintainer checklist
  • Assure one of these labels is present: backwards incompatible, feature, enhancement, deprecation, bug, dependency, docs or skip-changelog as they determine changelog listing.
  • Assign the PR to an existing or new milestone for the target version (following Semantic Versioning).

@atugushev atugushev added docs Documentation related skip-changelog Avoid listing in changelog labels Jul 31, 2023
@atugushev atugushev force-pushed the non-unique-changelog-heading-1935 branch from 8546b12 to 00c879a Compare August 1, 2023 10:32
@atugushev atugushev force-pushed the non-unique-changelog-heading-1935 branch from 00c879a to 040c7c5 Compare August 1, 2023 11:03
@webknjaz webknjaz self-requested a review August 1, 2023 11:40
Copy link
Member

@webknjaz webknjaz left a 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:

  1. 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 own setup().
  2. There's several maintenance/functional improvements in the comments below.
  3. 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
Copy link
Member

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:
Copy link
Member

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
Copy link
Member

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__))
Copy link
Member

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
Copy link
Member

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]
Copy link
Member

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:
Copy link
Member

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.

Comment on lines +25 to +31
if not node_ids:
return False

if len(node_ids) != 1:
return False

return bool(numerical_id.match(node_ids[0]))
Copy link
Member

Choose a reason for hiding this comment

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

This can be simplified:

Suggested change
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"]]
Copy link
Member

Choose a reason for hiding this comment

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

String concatenation is slow.

Suggested change
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"]]

Copy link
Member

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.

@atugushev atugushev mentioned this pull request Aug 1, 2023
4 tasks
@atugushev
Copy link
Member Author

@webknjaz thanks for the review. I think #1945 should address all your suggestions.

@atugushev atugushev closed this Aug 1, 2023
@atugushev atugushev deleted the non-unique-changelog-heading-1935 branch August 1, 2023 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation related skip-changelog Avoid listing in changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-unique heading anchors on pip-tools' changelog documentation
2 participants