refactor: identifiers in a file (#511)

* refactor: identifiers in a file

* chore: more typing

* refactor: PlatStr -> PlatformName

* refactor: load in file, use importlib.resources

* refactor: change toml structure

* refactor: use common Traversable

* fix: ensure reasonable version of importlib_resources

* style: fix extra line
This commit is contained in:
Henry Schreiner
2021-01-09 15:40:40 -05:00
committed by GitHub
parent 635b226a6c
commit 5eb5ea10f5
9 changed files with 180 additions and 92 deletions
+20 -12
View File
@@ -13,14 +13,20 @@ from time import sleep
from typing import Dict, List, NamedTuple, Optional, Set
import certifi
import toml
from .environment import ParsedEnvironment
from .typing import PathOrStr
from .typing import PathOrStr, PlatformName
if sys.version_info < (3, 8):
from typing_extensions import Literal
if sys.version_info < (3, 9):
from importlib_resources import files
else:
from typing import Literal
from importlib.resources import files
resources_dir = files('cibuildwheel') / 'resources'
get_pip_script = resources_dir / 'get-pip.py'
install_certifi_script = resources_dir / "install_certifi.py"
def prepare_command(command: str, **kwargs: PathOrStr) -> str:
@@ -42,6 +48,13 @@ def get_build_verbosity_extra_flags(level: int) -> List[str]:
return []
def read_python_configs(config: PlatformName) -> List[Dict[str, str]]:
input_file = resources_dir / 'build-platforms.toml'
loaded_file = toml.load(input_file)
results: List[Dict[str, str]] = list(loaded_file[config]['python_configurations'])
return results
class BuildSelector:
def __init__(self, build_config: str, skip_config: str):
self.build_patterns = build_config.split()
@@ -151,7 +164,7 @@ class Architecture(Enum):
return self.value < other.value
@staticmethod
def parse_config(config: str, platform: str) -> 'Set[Architecture]':
def parse_config(config: str, platform: PlatformName) -> 'Set[Architecture]':
result = set()
for arch_str in re.split(r'[\s,]+', config):
if arch_str == 'auto':
@@ -161,7 +174,7 @@ class Architecture(Enum):
return result
@staticmethod
def auto_archs(platform: str) -> 'Set[Architecture]':
def auto_archs(platform: PlatformName) -> 'Set[Architecture]':
native_architecture = Architecture(platform_module.machine())
result = {native_architecture}
if platform == 'linux' and native_architecture == Architecture.x86_64:
@@ -190,11 +203,6 @@ class BuildOptions(NamedTuple):
build_verbosity: int
resources_dir = Path(__file__).resolve().parent / 'resources'
get_pip_script = resources_dir / 'get-pip.py'
install_certifi_script = resources_dir / "install_certifi.py"
class NonPlatformWheelError(Exception):
def __init__(self) -> None:
message = textwrap.dedent('''
@@ -255,7 +263,7 @@ ALLOWED_ARCHITECTURES = {
def allowed_architectures_check(
name: Literal['linux', 'macos', 'windows'],
name: PlatformName,
options: BuildOptions,
) -> None: