22import json
33import platform as _platform_module
44from collections import defaultdict
5- from enum import IntEnum
65from pathlib import Path
76from typing import Dict , List , Optional , Set
87from os .path import join , dirname , abspath
98import logging
109
11- from ..error import InvalidPlatform
10+ from ..libc import get_libc , Libc
1211from ..musllinux import find_musl_libc , get_musl_version
1312
13+
1414_HERE = Path (__file__ ).parent
1515
1616logger = logging .getLogger (__name__ )
1717
18-
19- class Platform (IntEnum ):
20- MANYLINUX = 1 ,
21- MUSLLINUX = 2
22-
23-
2418# https://docs.python.org/3/library/platform.html#platform.architecture
2519bits = 8 * (8 if sys .maxsize > 2 ** 32 else 4 )
2620
@@ -34,19 +28,7 @@ def get_arch_name() -> str:
3428
3529
3630_ARCH_NAME = get_arch_name ()
37-
38-
39- def get_policy_platform () -> Platform :
40- try :
41- find_musl_libc ()
42- logger .debug ("Detected musl libc" )
43- return Platform .MUSLLINUX
44- except InvalidPlatform :
45- logger .debug ("Falling back to GNU libc" )
46- return Platform .MANYLINUX
47-
48-
49- _PLATFORM = get_policy_platform ()
31+ _LIBC = get_libc ()
5032
5133
5234def _validate_pep600_compliance (policies ) -> None :
@@ -82,13 +64,13 @@ def _validate_pep600_compliance(policies) -> None:
8264
8365
8466_POLICY_JSON_MAP = {
85- Platform . MANYLINUX : _HERE / 'manylinux-policy.json' ,
86- Platform . MUSLLINUX : _HERE / 'musllinux-policy.json' ,
67+ Libc . GLIBC : _HERE / 'manylinux-policy.json' ,
68+ Libc . MUSL : _HERE / 'musllinux-policy.json' ,
8769}
8870
8971
9072def _get_musl_policy ():
91- if _PLATFORM != Platform . MUSLLINUX :
73+ if _LIBC != Libc . MUSL :
9274 return None
9375 musl_version = get_musl_version (find_musl_libc ())
9476 return f'musllinux_{ musl_version .major } _{ musl_version .minor } '
@@ -98,7 +80,7 @@ def _get_musl_policy():
9880
9981
10082def _fixup_musl_libc_soname (whitelist ):
101- if _PLATFORM != Platform . MUSLLINUX :
83+ if _LIBC != Libc . MUSL :
10284 return whitelist
10385 soname_map = {
10486 "libc.so" : {
@@ -121,7 +103,7 @@ def _fixup_musl_libc_soname(whitelist):
121103 return new_whitelist
122104
123105
124- with _POLICY_JSON_MAP [_PLATFORM ].open () as f :
106+ with _POLICY_JSON_MAP [_LIBC ].open () as f :
125107 _POLICIES = []
126108 _policies_temp = json .load (f )
127109 _validate_pep600_compliance (_policies_temp )
@@ -137,7 +119,7 @@ def _fixup_musl_libc_soname(whitelist):
137119 for alias in _p ['aliases' ]]
138120 _p ['lib_whitelist' ] = _fixup_musl_libc_soname (_p ['lib_whitelist' ])
139121 _POLICIES .append (_p )
140- if _PLATFORM == Platform . MUSLLINUX :
122+ if _LIBC == Libc . MUSL :
141123 assert len (_POLICIES ) == 2 , _POLICIES
142124
143125POLICY_PRIORITY_HIGHEST = max (p ['priority' ] for p in _POLICIES )
0 commit comments