|
3 | 3 | import inspect |
4 | 4 | import json |
5 | 5 | import shlex |
| 6 | +import sys |
6 | 7 | import textwrap |
7 | 8 | import warnings |
8 | 9 | from datetime import datetime, timedelta |
|
17 | 18 | Optional, |
18 | 19 | Sequence, |
19 | 20 | Tuple, |
| 21 | + TypedDict, |
20 | 22 | Union, |
21 | 23 | overload, |
22 | 24 | ) |
23 | 25 |
|
24 | 26 | import pydantic |
25 | 27 | from typing_extensions import TypeAlias |
26 | 28 |
|
| 29 | +if sys.version_info >= (3, 11): |
| 30 | + from typing import Unpack |
| 31 | +else: |
| 32 | + from typing_extensions import Unpack |
| 33 | + |
27 | 34 | import python_on_whales.components.image.cli_wrapper |
28 | 35 | import python_on_whales.components.network.cli_wrapper |
29 | 36 | import python_on_whales.components.pod.cli_wrapper |
@@ -443,6 +450,106 @@ def stop(self, time: Union[int, timedelta] = None) -> None: |
443 | 450 | ValidContainer = Union[Container, str] |
444 | 451 |
|
445 | 452 |
|
| 453 | +class RunArgs(TypedDict, total=False): |
| 454 | + add_hosts: Iterable[Tuple[str, str]] |
| 455 | + blkio_weight: Optional[int] |
| 456 | + blkio_weight_device: Iterable[str] |
| 457 | + cap_add: Iterable[str] |
| 458 | + cap_drop: Iterable[str] |
| 459 | + cgroup_parent: Optional[str] |
| 460 | + cgroupns: Optional[str] |
| 461 | + cidfile: Optional[ValidPath] |
| 462 | + cpu_period: Optional[int] |
| 463 | + cpu_quota: Optional[int] |
| 464 | + cpu_rt_period: Optional[int] |
| 465 | + cpu_rt_runtime: Optional[int] |
| 466 | + cpu_shares: Optional[int] |
| 467 | + cpus: Optional[float] |
| 468 | + cpuset_cpus: Optional[List[int]] |
| 469 | + cpuset_mems: Optional[List[int]] |
| 470 | + devices: Iterable[str] |
| 471 | + device_cgroup_rules: Iterable[str] |
| 472 | + device_read_bps: Iterable[str] |
| 473 | + device_read_iops: Iterable[str] |
| 474 | + device_write_bps: Iterable[str] |
| 475 | + device_write_iops: Iterable[str] |
| 476 | + content_trust: bool |
| 477 | + dns: Iterable[str] |
| 478 | + dns_options: Iterable[str] |
| 479 | + dns_search: Iterable[str] |
| 480 | + domainname: Optional[str] |
| 481 | + entrypoint: Optional[str] |
| 482 | + envs: Mapping[str, str] |
| 483 | + env_files: Union[ValidPath, Iterable[ValidPath]] |
| 484 | + env_host: bool |
| 485 | + expose: Union[int, Iterable[int]] |
| 486 | + gpus: Union[int, str, None] |
| 487 | + groups_add: Iterable[str] |
| 488 | + healthcheck: bool |
| 489 | + health_cmd: Optional[str] |
| 490 | + health_interval: Union[None, int, timedelta] |
| 491 | + health_retries: Optional[int] |
| 492 | + health_start_period: Union[None, int, timedelta] |
| 493 | + health_timeout: Union[None, int, timedelta] |
| 494 | + hostname: Optional[str] |
| 495 | + init: bool |
| 496 | + interactive: bool |
| 497 | + ip: Optional[str] |
| 498 | + ip6: Optional[str] |
| 499 | + ipc: Optional[str] |
| 500 | + isolation: Optional[str] |
| 501 | + kernel_memory: Union[int, str, None] |
| 502 | + labels: Mapping[str, str] |
| 503 | + label_files: Iterable[ValidPath] |
| 504 | + link: Iterable[ValidContainer] |
| 505 | + link_local_ip: Iterable[str] |
| 506 | + log_driver: Optional[str] |
| 507 | + log_options: Iterable[str] |
| 508 | + mac_address: Optional[str] |
| 509 | + memory: Union[int, str, None] |
| 510 | + memory_reservation: Union[int, str, None] |
| 511 | + memory_swap: Union[int, str, None] |
| 512 | + memory_swappiness: Optional[int] |
| 513 | + mounts: Iterable[List[str]] |
| 514 | + name: Optional[str] |
| 515 | + networks: Iterable[python_on_whales.components.network.cli_wrapper.ValidNetwork] |
| 516 | + network_aliases: Iterable[str] |
| 517 | + oom_kill: bool |
| 518 | + oom_score_adj: Optional[int] |
| 519 | + pid: Optional[str] |
| 520 | + pids_limit: Optional[int] |
| 521 | + platform: Optional[str] |
| 522 | + pod: Optional[python_on_whales.components.pod.cli_wrapper.ValidPod] |
| 523 | + preserve_fds: Optional[int] |
| 524 | + privileged: bool |
| 525 | + publish: Iterable[ValidPortMapping] |
| 526 | + publish_all: bool |
| 527 | + pull: str |
| 528 | + read_only: bool |
| 529 | + restart: Optional[str] |
| 530 | + remove: bool |
| 531 | + runtime: Optional[str] |
| 532 | + security_options: Iterable[str] |
| 533 | + shm_size: Union[int, str, None] |
| 534 | + sig_proxy: bool |
| 535 | + stop_signal: Optional[Union[int, str]] |
| 536 | + stop_timeout: Optional[int] |
| 537 | + storage_options: Iterable[str] |
| 538 | + sysctl: Mapping[str, str] |
| 539 | + systemd: Optional[Union[bool, Literal["always"]]] |
| 540 | + tmpfs: Iterable[ValidPath] |
| 541 | + tty: bool |
| 542 | + tz: Optional[str] |
| 543 | + ulimit: Iterable[str] |
| 544 | + user: Optional[str] |
| 545 | + userns: Optional[str] |
| 546 | + uts: Optional[str] |
| 547 | + volumes: Iterable[python_on_whales.components.volume.cli_wrapper.VolumeDefinition] |
| 548 | + volume_driver: Optional[str] |
| 549 | + volumes_from: Iterable[ValidContainer] |
| 550 | + workdir: Optional[ValidPath] |
| 551 | + |
| 552 | + |
446 | 553 | class ContainerCLI(DockerCLICaller): |
447 | 554 | def __init__(self, *args, **kwargs): |
448 | 555 | super().__init__(*args, **kwargs) |
@@ -1358,6 +1465,39 @@ def remove( |
1358 | 1465 |
|
1359 | 1466 | run(full_cmd) |
1360 | 1467 |
|
| 1468 | + @overload |
| 1469 | + def run( |
| 1470 | + self, |
| 1471 | + image: python_on_whales.components.image.cli_wrapper.ValidImage, |
| 1472 | + command: Sequence[str] = ..., |
| 1473 | + *, |
| 1474 | + detach: Literal[True], |
| 1475 | + stream: bool = ..., |
| 1476 | + **kwargs: Unpack[RunArgs], |
| 1477 | + ) -> Container: ... |
| 1478 | + |
| 1479 | + @overload |
| 1480 | + def run( |
| 1481 | + self, |
| 1482 | + image: python_on_whales.components.image.cli_wrapper.ValidImage, |
| 1483 | + command: Sequence[str] = ..., |
| 1484 | + *, |
| 1485 | + detach: Literal[False] = ..., |
| 1486 | + stream: Literal[True], |
| 1487 | + **kwargs: Unpack[RunArgs], |
| 1488 | + ) -> Iterable[Tuple[str, bytes]]: ... |
| 1489 | + |
| 1490 | + @overload |
| 1491 | + def run( |
| 1492 | + self, |
| 1493 | + image: python_on_whales.components.image.cli_wrapper.ValidImage, |
| 1494 | + command: Sequence[str] = ..., |
| 1495 | + *, |
| 1496 | + detach: Literal[False] = ..., |
| 1497 | + stream: Literal[False] = ..., |
| 1498 | + **kwargs: Unpack[RunArgs], |
| 1499 | + ) -> str: ... |
| 1500 | + |
1361 | 1501 | def run( |
1362 | 1502 | self, |
1363 | 1503 | image: python_on_whales.components.image.cli_wrapper.ValidImage, |
|
0 commit comments