diff options
author | Christian Heimes <christian@python.org> | 2022-07-29 14:42:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-29 14:42:09 (GMT) |
commit | f81a6c5fc7b13bd2076bdb1481c6085e0ed67184 (patch) | |
tree | d8216a6e0ec90c2328ba7b48c8deef7d169abe6a /Doc/tools | |
parent | 2fbee85931296bbeddae6358583e400ce5321f89 (diff) | |
download | cpython-f81a6c5fc7b13bd2076bdb1481c6085e0ed67184.zip cpython-f81a6c5fc7b13bd2076bdb1481c6085e0ed67184.tar.gz cpython-f81a6c5fc7b13bd2076bdb1481c6085e0ed67184.tar.bz2 |
gh-95415: Make availability directive consistent (GH-95416)
Diffstat (limited to 'Doc/tools')
-rw-r--r-- | Doc/tools/extensions/pyspecific.py | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index 8ac0028..20c372e 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -134,11 +134,22 @@ class ImplementationDetail(Directive): class Availability(Directive): - has_content = False + has_content = True required_arguments = 1 optional_arguments = 0 final_argument_whitespace = True + # known platform, libc, and threading implementations + known_platforms = frozenset({ + "AIX", "Android", "BSD", "DragonFlyBSD", "Emscripten", "FreeBSD", + "Linux", "NetBSD", "OpenBSD", "POSIX", "Solaris", "Unix", "VxWorks", + "WASI", "Windows", "macOS", + # libc + "BSD libc", "glibc", "musl", + # POSIX platforms with pthreads + "pthreads", + }) + def run(self): availability_ref = ':ref:`Availability <availability>`: ' pnode = nodes.paragraph(availability_ref + self.arguments[0], @@ -147,8 +158,53 @@ class Availability(Directive): pnode.extend(n + m) n, m = self.state.inline_text(self.arguments[0], self.lineno) pnode.extend(n + m) + if self.content: + content = " " + " ".join(self.content) + n, m = self.state.inline_text(content, self.content_offset) + pnode.extend(n + m) + + self.parse_platforms() + return [pnode] + 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 Emscripten, not WASI + + Arguments like "Linux >= 3.17 with glibc >= 2.27" are currently not + parsed into separate tokens. + """ + platforms = {} + for arg in self.arguments[0].rstrip(".").split(","): + arg = arg.strip() + platform, _, version = arg.partition(" >= ") + if platform.startswith("not "): + version = False + platform = platform[4:] + elif not version: + version = True + platforms[platform] = version + + unknown = set(platforms).difference(self.known_platforms) + if unknown: + cls = type(self) + logger = logging.getLogger(cls.__qualname__) + logger.warn( + 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." + ) + + return platforms + + # Support for documenting audit event |