|
1 | 1 | import fnmatch |
2 | | -import functools |
3 | 2 | import itertools |
4 | 3 | import os |
5 | | -import platform as platform_module |
6 | | -import re |
7 | 4 | import ssl |
8 | 5 | import sys |
9 | 6 | import textwrap |
|
17 | 14 | import certifi |
18 | 15 | import toml |
19 | 16 |
|
| 17 | +from .architecture import Architecture |
20 | 18 | from .environment import ParsedEnvironment |
21 | | -from .typing import PathOrStr, PlatformName, assert_never |
| 19 | +from .typing import PathOrStr, PlatformName |
22 | 20 |
|
23 | 21 | if sys.version_info < (3, 9): |
24 | 22 | from importlib_resources import files |
@@ -163,62 +161,6 @@ def __repr__(self) -> str: |
163 | 161 | return f'{self.__class__.__name__}{self.base_file_path!r})' |
164 | 162 |
|
165 | 163 |
|
166 | | -@functools.total_ordering |
167 | | -class Architecture(Enum): |
168 | | - value: str |
169 | | - |
170 | | - # mac/linux archs |
171 | | - x86_64 = 'x86_64' |
172 | | - i686 = 'i686' |
173 | | - aarch64 = 'aarch64' |
174 | | - ppc64le = 'ppc64le' |
175 | | - s390x = 's390x' |
176 | | - |
177 | | - # windows archs |
178 | | - x86 = 'x86' |
179 | | - AMD64 = 'AMD64' |
180 | | - |
181 | | - # Allow this to be sorted |
182 | | - def __lt__(self, other: "Architecture") -> bool: |
183 | | - return self.value < other.value |
184 | | - |
185 | | - @staticmethod |
186 | | - def parse_config(config: str, platform: PlatformName) -> 'Set[Architecture]': |
187 | | - result = set() |
188 | | - for arch_str in re.split(r'[\s,]+', config): |
189 | | - if arch_str == 'auto': |
190 | | - result |= Architecture.auto_archs(platform=platform) |
191 | | - elif arch_str == 'native': |
192 | | - result.add(Architecture(platform_module.machine())) |
193 | | - elif arch_str == 'all': |
194 | | - result |= Architecture.all_archs(platform=platform) |
195 | | - else: |
196 | | - result.add(Architecture(arch_str)) |
197 | | - return result |
198 | | - |
199 | | - @staticmethod |
200 | | - def auto_archs(platform: PlatformName) -> 'Set[Architecture]': |
201 | | - native_architecture = Architecture(platform_module.machine()) |
202 | | - result = {native_architecture} |
203 | | - if platform == 'linux' and native_architecture == Architecture.x86_64: |
204 | | - # x86_64 machines can run i686 docker containers |
205 | | - result.add(Architecture.i686) |
206 | | - if platform == 'windows' and native_architecture == Architecture.AMD64: |
207 | | - result.add(Architecture.x86) |
208 | | - return result |
209 | | - |
210 | | - @staticmethod |
211 | | - def all_archs(platform: PlatformName) -> 'Set[Architecture]': |
212 | | - if platform == 'linux': |
213 | | - return {Architecture.x86_64, Architecture.i686, Architecture.aarch64, Architecture.ppc64le, Architecture.s390x} |
214 | | - elif platform == 'macos': |
215 | | - return {Architecture.x86_64} |
216 | | - elif platform == 'windows': |
217 | | - return {Architecture.x86, Architecture.AMD64} |
218 | | - else: |
219 | | - assert_never(platform) |
220 | | - |
221 | | - |
222 | 164 | class BuildOptions(NamedTuple): |
223 | 165 | package_dir: Path |
224 | 166 | output_dir: Path |
@@ -286,27 +228,3 @@ def detect_ci_provider() -> Optional[CIProvider]: |
286 | 228 | return CIProvider.other |
287 | 229 | else: |
288 | 230 | return None |
289 | | - |
290 | | - |
291 | | -PRETTY_NAMES = {'linux': 'Linux', 'macos': 'macOS', 'windows': 'Windows'} |
292 | | - |
293 | | - |
294 | | -def allowed_architectures_check( |
295 | | - platform: PlatformName, |
296 | | - options: BuildOptions, |
297 | | -) -> None: |
298 | | - |
299 | | - allowed_architectures = Architecture.all_archs(platform) |
300 | | - |
301 | | - msg = f'{PRETTY_NAMES[platform]} only supports {sorted(allowed_architectures)} at the moment.' |
302 | | - |
303 | | - if platform != 'linux': |
304 | | - msg += ' If you want to set emulation architectures on Linux, use CIBW_ARCHS_LINUX instead.' |
305 | | - |
306 | | - if not options.architectures <= allowed_architectures: |
307 | | - msg = f'Invalid archs option {options.architectures}. ' + msg |
308 | | - raise ValueError(msg) |
309 | | - |
310 | | - if not options.architectures: |
311 | | - msg = 'Empty archs option set. ' + msg |
312 | | - raise ValueError(msg) |
0 commit comments