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

Method decode

pex/interpreter.py:333–405  ·  view source on GitHub ↗
(cls, encoded)

Source from the content-addressed store, hash-verified

331
332 @classmethod
333 def decode(cls, encoded):
334 # type: (Text) -> PythonIdentity
335 TRACER.log("creating PythonIdentity from encoded: {encoded}".format(encoded=encoded), V=9)
336 values = json.loads(encoded)
337 if len(values) != 20:
338 raise cls.InvalidError(
339 "Invalid interpreter identity: {encoded}".format(encoded=encoded)
340 )
341 try:
342 format_version = int(values.pop("__format_version__", "0"))
343 except ValueError as e:
344 raise cls.InvalidError(
345 "The PythonIdentity __format_version__ is invalid: {err}".format(err=e)
346 )
347 else:
348 if format_version < cls._FORMAT_VERSION:
349 raise cls.InvalidError(
350 "The PythonIdentity __format_version__ was {format_version}, but the current "
351 "version is {current_version}. Upgrading existing encoding: {encoded}".format(
352 format_version=format_version,
353 current_version=cls._FORMAT_VERSION,
354 encoded=encoded,
355 )
356 )
357
358 version = tuple(values.pop("version"))
359 pypy_version = tuple(values.pop("pypy_version") or ()) or None
360
361 supported_tags = values.pop("supported_tags")
362
363 def iter_tags():
364 for (interpreter, abi, platform) in supported_tags:
365 yield tags.Tag(interpreter=interpreter, abi=abi, platform=platform)
366
367 # N.B.: Old encoded identities may have numeric values; so we support these and convert
368 # back to strings here as needed. See: https://github.com/pex-tool/pex/issues/1337
369 configured_macosx_deployment_target = cls._normalize_macosx_deployment_target(
370 values.pop("configured_macosx_deployment_target")
371 )
372
373 env_markers = MarkerEnvironment(**values.pop("env_markers"))
374
375 site_packages_paths = values.pop("site_packages")
376 purelib = values.pop("purelib")
377 platlib = values.pop("platlib")
378 site_packages = [] # type: List[SitePackagesDir]
379 for path in site_packages_paths:
380 if path == purelib:
381 site_packages.append(Purelib(_adjust_to_current_path(path)))
382 elif path == platlib:
383 site_packages.append(Platlib(_adjust_to_current_path(path)))
384 else:
385 site_packages.append(SitePackagesDir(_adjust_to_current_path(path)))
386
387 return cls(
388 binary=_adjust_to_current_path(values.pop("binary")),
389 prefix=_adjust_to_current_path(values.pop("prefix")),
390 base_prefix=_adjust_to_current_path(values.pop("base_prefix")),

Callers 15

loadMethod · 0.80
encodeMethod · 0.80
build_pex_scieFunction · 0.80
add_git_stateFunction · 0.80
is_aliveFunction · 0.80
create_interpreterMethod · 0.80
from_envMethod · 0.80
from_jsonMethod · 0.80
executeMethod · 0.80
create_errorMethod · 0.80
create_whlFunction · 0.80
install_wheelFunction · 0.80

Calls 10

MarkerEnvironmentClass · 0.90
castFunction · 0.90
PurelibClass · 0.85
_adjust_to_current_pathFunction · 0.85
PlatlibClass · 0.85
SitePackagesDirClass · 0.85
logMethod · 0.80
appendMethod · 0.80
popMethod · 0.45

Tested by 15

executeFunction · 0.64
assert_pex_args_shebangFunction · 0.64
test_to_bytesFunction · 0.64
test_pex_scriptFunction · 0.64
test_pex_tools_scriptFunction · 0.64
test_user_agentFunction · 0.64
test_issues_892Function · 0.64
test_spawn_stdoutFunction · 0.64
test_pex_scriptFunction · 0.64