8000 gh-126609: Revert Availability Directive changes by StanFromIreland · Pull Request #129480 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-126609: Revert Availability Directive changes #129480

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

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert Availability Directive changes
  • Loading branch information
StanFromIreland committed Jan 30, 2025
commit b9f7e04fc4fcc9711fb6f7dc97d4bbae88dbb374
106 changes: 29 additions & 77 deletions Doc/tools/extensions/availability.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,39 @@
"""Support for documenting platform availability"""

from __future__ import annotations

from typing import TYPE_CHECKING

Check failure on line 5 in Doc/tools/extensions/availability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

Doc/tools/extensions/availability.py:5:20: F401 `typing.TYPE_CHECKING` imported but unused

from docutils import nodes
from sphinx import addnodes

Check failure on line 8 in Doc/tools/extensions/availability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

Doc/tools/extensions/availability.py:8:20: F401 `sphinx.addnodes` imported but unused
from sphinx.util import logging
from sphinx.util.docutils import SphinxDirective

if TYPE_CHECKING:
from sphinx.application import Sphinx
from sphinx.util.typing import ExtensionMetadata

logger = logging.getLogger("availability")

# known platform, libc, and threading implementations
_PLATFORMS = frozenset({
"AIX",
"Android",
"BSD",
"DragonFlyBSD",
"Emscripten",
"FreeBSD",
"GNU/kFreeBSD",
"iOS",
"Linux",
"macOS",
"NetBSD",
"OpenBSD",
"POSIX",
"Solaris",
"Unix",
"VxWorks",
"WASI",
"Windows",
})
_LIBC = frozenset({
"BSD libc",
"glibc",
"musl",
})
_THREADING = frozenset({
# POSIX platforms with pthreads
"pthreads",
})
KNOWN_PLATFORMS = _PLATFORMS | _LIBC | _THREADING


class Availability(SphinxDirective):

Check failure on line 12 in Doc/tools/extensions/availability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (I001)

Doc/tools/extensions/availability.py:3:1: I001 Import block is un-sorted or un-formatted

Check failure on line 12 in Doc/tools/extensions/availability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (E302)

Doc/tools/extensions/availability.py:12:1: E302 Expected 2 blank lines, found 1

has_content = True
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True

def run(self) -> list[nodes.container]:
title = "Availability"
refnode = addnodes.pending_xref(
title,
nodes.inline(title, title, classes=["xref", "std", "std-ref"]),
refdoc=self.env.docname,
refdomain="std",
refexplicit=True,
reftarget="availability",
reftype="ref",
refwarn=True,
)
sep = nodes.Text(": ")
parsed, msgs = self.state.inline_text(self.arguments[0], self.lineno)
pnode = nodes.paragraph(title, "", refnode, sep, *parsed, *msgs)
# known platform, libc, and threading implementations
known_platforms = frozenset({
"AIX", "Android", "BSD", "DragonFlyBSD", "Emscripten", "FreeBSD",
"GNU/kFreeBSD", "Linux", "NetBSD", "OpenBSD", "POSIX", "Solaris",
"Unix", "VxWorks", "WASI", "Windows", "macOS", "iOS",
# libc
"BSD libc", "glibc", "musl",
# POSIX platforms with pthreads
"pthreads",
})

def run(self):
availability_ref = ':ref:`Availability <availability>`: '
avail_nodes, avail_msgs = self.state.inline_text(
availability_ref + self.arguments[0],
self.lineno)
pnode = nodes.paragraph(availability_ref + self.arguments[0],
'', *avail_nodes, *avail_msgs)
self.set_source_info(pnode)
cnode = nodes.container("", pnode, classes=["availability"])
self.set_source_info(cnode)
Expand All @@ -78,16 +43,12 @@

return [cnode]

def parse_platforms(self) -> dict[str, str | bool]:
def parse_platforms(self):
"""Parse platform information from arguments

Arguments is a comma-separated string of platforms. A platform may
be prefixed with "not " to indicate that a feature is not available.

Example::

.. availability:: Windows, Linux >= 4.2, not WASI

Arguments like "Linux >= 3.17 with glibc >= 2.27" are currently not
parsed into separate tokens.
"""
Expand All @@ -97,29 +58,20 @@
platform, _, version = arg.partition(" >= ")
if platform.startswith("not "):
version = False
platform = platform.removeprefix("not ")
platform = platform[4:]
elif not version:
version = True
platforms[platform] = version

if unknown := set(platforms).difference(KNOWN_PLATFORMS):
unknown = set(platforms).difference(self.known_platforms)
if unknown:
cls = type(self)
logger = logging.getLogger(cls.__qualname__)
logger.warning(
"Unknown platform%s or syntax '%s' in '.. availability:: %s', "
"see %s:KNOWN_PLATFORMS for a set of known platforms.",
"s" if len(platforms) != 1 else "",
" ".join(sorted(unknown)),
self.arguments[0],
__file__,
f"Unknown platform(s) or syntax '{' '.join(sorted(unknown))}' "
f"in '.. availability:: {self.arguments[0]}', see "
f"{__file__}:{cls.__qualname__}.known_platforms for a set "
"known platforms."

Check failure on line 74 in Doc/tools/extensions/availability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (G004)

Doc/tools/extensions/availability.py:71:17: G004 Logging statement uses f-string
)

return platforms


def setup(app: Sphinx) -> ExtensionMetadata:
app.add_directive("availability", Availability)

return {
"version": "1.0",
"parallel_read_safe": True,
"parallel_write_safe": True,
}
Loading
0