MCPcopy
hub / github.com/pex-tool/pex / parse

Method parse

pex/platforms.py:86–126  ·  view source on GitHub ↗
(cls, platform_spec)

Source from the content-addressed store, hash-verified

84
85 @classmethod
86 def parse(cls, platform_spec):
87 # type: (str) -> PlatformSpec
88 platform_components = platform_spec.rsplit(cls.SEP, 3)
89 try:
90 plat, impl, version, abi = platform_components
91 except ValueError:
92 raise cls.InvalidSpecError.create(
93 platform_spec,
94 cause="There are missing platform fields. Expected 4 but given {count}.".format(
95 count=len(platform_components)
96 ),
97 )
98
99 version_components = version.split(".")
100 if len(version_components) == 1:
101 component = version_components[0]
102 if len(component) < 2:
103 raise cls.InvalidSpecError.create(
104 platform_spec,
105 cause=(
106 "The version field must either be a 2 or more digit digit major/minor "
107 "version or else a component dotted version. "
108 "Given: {version!r}".format(version=version)
109 ),
110 )
111
112 # Here version is py_version_nodot (e.g.: "37" or "310") as outlined in
113 # https://peps.python.org/pep-0425/#python-tag
114 version_components = [component[0], component[1:]]
115
116 try:
117 version_info = cast("VersionInfo", tuple(map(int, version_components)))
118 except ValueError:
119 raise cls.InvalidSpecError.create(
120 platform_spec,
121 cause="The version specified had non-integer components. Given: {version!r}".format(
122 version=version
123 ),
124 )
125
126 return cls(platform=plat, impl=impl, version=version, version_info=version_info, abi=abi)
127
128 @classmethod
129 def from_tag(cls, tag):

Callers

nothing calls this directly

Calls 2

castFunction · 0.90
createMethod · 0.45

Tested by

no test coverage detected