Skip to content

Commit 9da4ede

Browse files
authored
Merge pull request #1620 from Helveg/cibw-debug-keep-container
feat: `CIBW_DEBUG_KEEP_CONTAINER`: debug container after build
2 parents 77d3a5f + 28ad6e4 commit 9da4ede

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

cibuildwheel/oci_container.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
from typing import IO, Dict, Literal
1818

1919
from .typing import PathOrStr, PopenBytes
20-
from .util import CIProvider, call, detect_ci_provider, parse_key_value_string
20+
from .util import (
21+
CIProvider,
22+
call,
23+
detect_ci_provider,
24+
parse_key_value_string,
25+
strtobool,
26+
)
2127

2228
ContainerEngineName = Literal["docker", "podman"]
2329

@@ -188,12 +194,14 @@ def __exit__(
188194

189195
assert isinstance(self.name, str)
190196

191-
subprocess.run(
192-
[self.engine.name, "rm", "--force", "-v", self.name],
193-
stdout=subprocess.DEVNULL,
194-
check=False,
195-
)
196-
self.name = None
197+
keep_container = strtobool(os.environ.get("CIBW_DEBUG_KEEP_CONTAINER", ""))
198+
if not keep_container:
199+
subprocess.run(
200+
[self.engine.name, "rm", "--force", "-v", self.name],
201+
stdout=subprocess.DEVNULL,
202+
check=False,
203+
)
204+
self.name = None
197205

198206
def copy_into(self, from_path: Path, to_path: PurePath) -> None:
199207
# `docker cp` causes 'no space left on device' error when

docs/options.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,23 @@ This option is not supported in the overrides section in `pyproject.toml`.
14221422
test-skip = "*-macosx_arm64 *-macosx_universal2:arm64"
14231423
```
14241424

1425-
## Other
1425+
## Debugging
1426+
1427+
### `CIBW_DEBUG_KEEP_CONTAINER`
1428+
1429+
Enable this flag to keep the container around for inspection after a build. This
1430+
option is provided for debugging purposes only.
1431+
1432+
Default: Off (0).
1433+
1434+
!!! caution
1435+
This option can only be set as environment variable on the host machine
1436+
1437+
#### Examples
1438+
1439+
```shell
1440+
export CIBW_DEBUG_KEEP_CONTAINER=TRUE
1441+
```
14261442

14271443
### `CIBW_BUILD_VERBOSITY` {: #build-verbosity}
14281444
> Increase/decrease the output of pip wheel

0 commit comments

Comments
 (0)