MCPcopy Index your code
hub / github.com/python/cpython / parse_platforms

Method parse_platforms

Doc/tools/extensions/availability.py:82–116  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

80 return [cnode]
81
82 def parse_platforms(self) -> dict[str, str | bool]:
83 """Parse platform information from arguments
84
85 Arguments is a comma-separated string of platforms. A platform may
86 be prefixed with "not " to indicate that a feature is not available.
87
88 Example::
89
90 .. availability:: Windows, Linux >= 4.2, not WASI
91
92 Arguments like "Linux >= 3.17 with glibc >= 2.27" are currently not
93 parsed into separate tokens.
94 """
95 platforms = {}
96 for arg in self.arguments[0].rstrip(".").split(","):
97 arg = arg.strip()
98 platform, _, version = arg.partition(" >= ")
99 if platform.startswith("not "):
100 version = False
101 platform = platform.removeprefix("not ")
102 elif not version:
103 version = True
104 platforms[platform] = version
105
106 if unknown := set(platforms).difference(KNOWN_PLATFORMS):
107 logger.warning(
108 "Unknown platform%s or syntax '%s' in '.. availability:: %s', "
109 "see %s:KNOWN_PLATFORMS for a set of known platforms.",
110 "s" if len(platforms) != 1 else "",
111 " ".join(sorted(unknown)),
112 self.arguments[0],
113 __file__,
114 )
115
116 return platforms
117
118
119def setup(app: Sphinx) -> ExtensionMetadata:

Callers 1

runMethod · 0.95

Calls 10

setFunction · 0.85
differenceMethod · 0.80
splitMethod · 0.45
rstripMethod · 0.45
stripMethod · 0.45
partitionMethod · 0.45
startswithMethod · 0.45
removeprefixMethod · 0.45
warningMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected