Add some type safety to the container_engine option
This commit is contained in:
@@ -13,7 +13,9 @@ from typing import IO, Dict, List, Optional, Sequence, Type, cast
|
|||||||
|
|
||||||
from cibuildwheel.util import CIProvider, detect_ci_provider
|
from cibuildwheel.util import CIProvider, detect_ci_provider
|
||||||
|
|
||||||
from .typing import PathOrStr, PopenBytes
|
from .typing import Literal, PathOrStr, PopenBytes
|
||||||
|
|
||||||
|
ContainerEngine = Literal["docker", "podman"]
|
||||||
|
|
||||||
|
|
||||||
class DockerContainer:
|
class DockerContainer:
|
||||||
@@ -54,7 +56,7 @@ class DockerContainer:
|
|||||||
docker_image: str,
|
docker_image: str,
|
||||||
simulate_32_bit: bool = False,
|
simulate_32_bit: bool = False,
|
||||||
cwd: Optional[PathOrStr] = None,
|
cwd: Optional[PathOrStr] = None,
|
||||||
container_engine: str = "docker",
|
container_engine: ContainerEngine = "docker",
|
||||||
):
|
):
|
||||||
if not docker_image:
|
if not docker_image:
|
||||||
raise ValueError("Must have a non-empty docker image to run.")
|
raise ValueError("Must have a non-empty docker image to run.")
|
||||||
@@ -193,8 +195,6 @@ class DockerContainer:
|
|||||||
to_path.mkdir(parents=True, exist_ok=True)
|
to_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
if self.container_engine == "podman":
|
if self.container_engine == "podman":
|
||||||
# There is a bug in docker that prevents this simple implementation
|
|
||||||
# from working https://github.com/moby/moby/issues/38995
|
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
self.container_engine,
|
self.container_engine,
|
||||||
@@ -206,6 +206,8 @@ class DockerContainer:
|
|||||||
cwd=to_path,
|
cwd=to_path,
|
||||||
)
|
)
|
||||||
elif self.container_engine == "docker":
|
elif self.container_engine == "docker":
|
||||||
|
# There is a bug in docker that prevents a simple 'cp' invocation
|
||||||
|
# from working https://github.com/moby/moby/issues/38995
|
||||||
command = f"{self.container_engine} exec -i {self.name} tar -cC {shell_quote(from_path)} -f - . | tar -xf -"
|
command = f"{self.container_engine} exec -i {self.name} tar -cC {shell_quote(from_path)} -f - . | tar -xf -"
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
command,
|
command,
|
||||||
|
|||||||
+11
-2
@@ -16,6 +16,7 @@ from typing import (
|
|||||||
Set,
|
Set,
|
||||||
Tuple,
|
Tuple,
|
||||||
Union,
|
Union,
|
||||||
|
cast,
|
||||||
)
|
)
|
||||||
|
|
||||||
if sys.version_info >= (3, 11):
|
if sys.version_info >= (3, 11):
|
||||||
@@ -26,6 +27,7 @@ else:
|
|||||||
from packaging.specifiers import SpecifierSet
|
from packaging.specifiers import SpecifierSet
|
||||||
|
|
||||||
from .architecture import Architecture
|
from .architecture import Architecture
|
||||||
|
from .docker_container import ContainerEngine
|
||||||
from .environment import EnvironmentParseError, ParsedEnvironment, parse_environment
|
from .environment import EnvironmentParseError, ParsedEnvironment, parse_environment
|
||||||
from .projectfiles import get_requires_python_str
|
from .projectfiles import get_requires_python_str
|
||||||
from .typing import PLATFORMS, Literal, PlatformName, TypedDict
|
from .typing import PLATFORMS, Literal, PlatformName, TypedDict
|
||||||
@@ -79,7 +81,7 @@ class BuildOptions(NamedTuple):
|
|||||||
test_extras: str
|
test_extras: str
|
||||||
build_verbosity: int
|
build_verbosity: int
|
||||||
build_frontend: BuildFrontend
|
build_frontend: BuildFrontend
|
||||||
container_engine: str
|
container_engine: ContainerEngine
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def package_dir(self) -> Path:
|
def package_dir(self) -> Path:
|
||||||
@@ -423,7 +425,14 @@ class Options:
|
|||||||
test_requires = self.reader.get("test-requires", sep=" ").split()
|
test_requires = self.reader.get("test-requires", sep=" ").split()
|
||||||
test_extras = self.reader.get("test-extras", sep=",")
|
test_extras = self.reader.get("test-extras", sep=",")
|
||||||
build_verbosity_str = self.reader.get("build-verbosity")
|
build_verbosity_str = self.reader.get("build-verbosity")
|
||||||
container_engine = self.reader.get("container-engine")
|
container_engine_str = self.reader.get("container-engine")
|
||||||
|
|
||||||
|
if container_engine_str not in ["docker", "podman"]:
|
||||||
|
msg = f"cibuildwheel: Unrecognised container_engine '{container_engine_str}', only 'docker' and 'podman' are supported"
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
container_engine = cast(ContainerEngine, container_engine_str)
|
||||||
|
|
||||||
build_frontend: BuildFrontend
|
build_frontend: BuildFrontend
|
||||||
if build_frontend_str == "build":
|
if build_frontend_str == "build":
|
||||||
|
|||||||
Reference in New Issue
Block a user