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

Method from_platform

pex/pep_508.py:51–143  ·  view source on GitHub ↗

Populate a partial marker environment given what we know from platform information. Since Pex support is (currently) restricted to: + interpreters: CPython and PyPy + os: Linux and Mac and Windows We can fill in most of the environment markers used in these environm

(cls, platform)

Source from the content-addressed store, hash-verified

49
50 @classmethod
51 def from_platform(cls, platform):
52 # type: (Platform) -> MarkerEnvironment
53 """Populate a partial marker environment given what we know from platform information.
54
55 Since Pex support is (currently) restricted to:
56 + interpreters: CPython and PyPy
57 + os: Linux and Mac and Windows
58
59 We can fill in most of the environment markers used in these environments in practice in the
60 wild. For those we can't, we leave the markers unset (`None`).
61 """
62
63 major_version = platform.version_info[0]
64
65 implementation_name = None
66 implementation_version = None
67
68 if major_version == 2:
69 # Python 2 does not expose the `sys.implementation` object which these values are
70 # derived from; so we default them as per the PEP-508 defaulting spec ("0" for versions
71 # and the empty string for everything else).
72 implementation_name = ""
73 implementation_version = "0"
74 elif platform.impl == "cp":
75 implementation_name = "cpython"
76 elif platform.impl == "pp":
77 implementation_name = "pypy"
78
79 os_name = None
80 platform_machine = None
81 platform_system = None
82 sys_platform = None
83
84 if "linux" in platform.platform:
85 os_name = "posix"
86 if platform.platform.startswith(
87 ("linux_", "manylinux1_", "manylinux2010_", "manylinux2014_")
88 ):
89 # E.G.:
90 # + linux_x86_64
91 # + manylinux{1,2010,2014}_x86_64
92 # For the manylinux* See:
93 # + manylinux1: https://peps.python.org/pep-0513/
94 # + manylinux2010: https://peps.python.org/pep-0571/
95 # + manylinux2014: https://peps.python.org/pep-0599/
96 platform_machine = platform.platform.split("_", 1)[-1]
97 else:
98 # E.G.: manylinux_<glibc major>_<glibc_minor>_x86_64
99 # See: https://peps.python.org/pep-0600/
100 platform_machine = platform.platform.split("_", 3)[-1]
101 platform_system = "Linux"
102 sys_platform = "linux2" if major_version == 2 else "linux"
103 elif "mac" in platform.platform:
104 os_name = "posix"
105 # E.G:
106 # + macosx_10_15_x86_64
107 # + macosx_11_0_arm64
108 platform_machine = platform.platform.split("_", 3)[-1]

Calls 2

valuesMethod · 0.45
joinMethod · 0.45