refactor: address review, use NamedTuple
This commit is contained in:
+21
-11
@@ -2,7 +2,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
from typing import Iterator, List, NamedTuple, Set, Tuple
|
from typing import Iterator, List, NamedTuple, Set
|
||||||
|
|
||||||
from .architecture import Architecture
|
from .architecture import Architecture
|
||||||
from .docker_container import DockerContainer
|
from .docker_container import DockerContainer
|
||||||
@@ -28,6 +28,12 @@ class PythonConfiguration(NamedTuple):
|
|||||||
return PurePath(self.path_str)
|
return PurePath(self.path_str)
|
||||||
|
|
||||||
|
|
||||||
|
class BuildConfig(NamedTuple):
|
||||||
|
platform_configs: List[PythonConfiguration]
|
||||||
|
platform_tag: str
|
||||||
|
docker_image: str
|
||||||
|
|
||||||
|
|
||||||
def get_python_configurations(
|
def get_python_configurations(
|
||||||
build_selector: BuildSelector,
|
build_selector: BuildSelector,
|
||||||
architectures: Set[Architecture],
|
architectures: Set[Architecture],
|
||||||
@@ -47,9 +53,9 @@ def get_python_configurations(
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_linux_platforms(
|
def get_build_configs(
|
||||||
options: BuildOptions, python_configurations: List[PythonConfiguration]
|
options: BuildOptions, python_configurations: List[PythonConfiguration]
|
||||||
) -> Iterator[Tuple[List[PythonConfiguration], str, str]]:
|
) -> Iterator[BuildConfig]:
|
||||||
platforms = [
|
platforms = [
|
||||||
("cp", "manylinux_x86_64", "x86_64"),
|
("cp", "manylinux_x86_64", "x86_64"),
|
||||||
("cp", "manylinux_i686", "i686"),
|
("cp", "manylinux_i686", "i686"),
|
||||||
@@ -84,7 +90,7 @@ def get_linux_platforms(
|
|||||||
if not platform_configs:
|
if not platform_configs:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield platform_configs, platform_tag, docker_image
|
yield BuildConfig(platform_configs, platform_tag, docker_image)
|
||||||
|
|
||||||
|
|
||||||
def build_on_docker(
|
def build_on_docker(
|
||||||
@@ -307,18 +313,22 @@ def build(options: BuildOptions) -> None:
|
|||||||
container_project_path = PurePath("/project")
|
container_project_path = PurePath("/project")
|
||||||
container_package_dir = container_project_path / abs_package_dir.relative_to(cwd)
|
container_package_dir = container_project_path / abs_package_dir.relative_to(cwd)
|
||||||
|
|
||||||
for platform_configs, platform_tag, docker_image in get_linux_platforms(
|
for build_config in get_build_configs(options, python_configurations):
|
||||||
options, python_configurations
|
|
||||||
):
|
|
||||||
try:
|
try:
|
||||||
log.step(f"Starting Docker image {docker_image}...")
|
log.step(f"Starting Docker image {build_config.docker_image}...")
|
||||||
|
|
||||||
with DockerContainer(
|
with DockerContainer(
|
||||||
docker_image,
|
build_config.docker_image,
|
||||||
simulate_32_bit=platform_tag.endswith("i686"),
|
simulate_32_bit=build_config.platform_tag.endswith("i686"),
|
||||||
cwd=container_project_path,
|
cwd=container_project_path,
|
||||||
) as docker:
|
) as docker:
|
||||||
|
|
||||||
build_on_docker(
|
build_on_docker(
|
||||||
options, platform_configs, docker, container_project_path, container_package_dir
|
options,
|
||||||
|
build_config.platform_configs,
|
||||||
|
docker,
|
||||||
|
container_project_path,
|
||||||
|
container_package_dir,
|
||||||
)
|
)
|
||||||
|
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
|
|||||||
Reference in New Issue
Block a user