ContextManager,
Deque,
Dict,
- Generator,
Iterable,
+ Iterator,
List,
NamedTuple,
NoReturn,
V = TypeVar("V")
-def dictify(f: Callable[..., Generator[Tuple[T, V], None, None]]) -> Callable[..., Dict[T, V]]:
+def dictify(f: Callable[..., Iterator[Tuple[T, V]]]) -> Callable[..., Dict[T, V]]:
def wrapper(*args: Any, **kwargs: Any) -> Dict[T, V]:
return dict(f(*args, **kwargs))
@dictify
-def read_os_release() -> Generator[Tuple[str, str], None, None]:
+def read_os_release() -> Iterator[Tuple[str, str]]:
try:
filename = "/etc/os-release"
f = open(filename)
@contextlib.contextmanager
-def open_close(path: PathString, flags: int, mode: int = 0o664) -> Generator[int, None, None]:
+def open_close(path: PathString, flags: int, mode: int = 0o664) -> Iterator[int]:
fd = os.open(path, flags | os.O_CLOEXEC, mode)
try:
yield fd
@contextlib.contextmanager
-def btrfs_forget_stale_devices(args: CommandLineArguments) -> Generator[None, None, None]:
+def btrfs_forget_stale_devices(args: CommandLineArguments) -> Iterator[None]:
# When using cached images (-i), mounting btrfs images would sometimes fail
# with EEXIST. This is likely because a stale device is leftover somewhere
# from the previous run. To fix this, we make sure to always clean up stale
@contextlib.contextmanager
-def attach_image_loopback(image: Optional[BinaryIO]) -> Generator[Optional[Path], None, None]:
+def attach_image_loopback(image: Optional[BinaryIO]) -> Iterator[Optional[Path]]:
if image is None:
yield None
return
run(["losetup", "--detach", loopdev])
@contextlib.contextmanager
-def attach_base_image(base_image: Optional[Path]) -> Generator[Optional[Path], None, None]:
+def attach_base_image(base_image: Optional[Path]) -> Iterator[Optional[Path]]:
"""Context manager that attaches/detaches the base image directory or device"""
if base_image is None:
@contextlib.contextmanager
-def luks_open(part: Partition, loopdev: Path, passphrase: Dict[str, str]) -> Generator[Path, None, None]:
+def luks_open(part: Partition, loopdev: Path, passphrase: Dict[str, str]) -> Iterator[Path]:
name = str(uuid.uuid4())
dev = part.blockdev(loopdev)
@contextlib.contextmanager
def luks_setup_all(
args: CommandLineArguments, loopdev: Optional[Path], do_run_build_script: bool
-) -> Generator[LuksSetupOutput, None, None]:
+) -> Iterator[LuksSetupOutput]:
if not args.output_format.is_disk():
yield LuksSetupOutput.empty()
return
"""
with complete_step("Removing overlay whiteout files…"):
- for entry in cast(Generator[os.DirEntry[str], None, None], scandir_recursive(path)):
+ for entry in cast(Iterator[os.DirEntry[str]], scandir_recursive(path)):
if stat_is_whiteout(entry.stat(follow_symlinks=False)):
os.unlink(entry.path)
loopdev: Optional[Path],
image: LuksSetupOutput,
root_read_only: bool = False,
-) -> Generator[None, None, None]:
+) -> Iterator[None]:
with complete_step("Mounting image…"):
realroot: Optional[Path] = None
@contextlib.contextmanager
-def mount_api_vfs(args: CommandLineArguments, root: Path) -> Generator[None, None, None]:
+def mount_api_vfs(args: CommandLineArguments, root: Path) -> Iterator[None]:
subdirs = ("proc", "dev", "sys")
with complete_step("Mounting API VFS"):
@contextlib.contextmanager
-def mount_cache(args: CommandLineArguments, root: Path) -> Generator[None, None, None]:
+def mount_cache(args: CommandLineArguments, root: Path) -> Iterator[None]:
if args.cache_path is None:
yield
return
def scandir_recursive(
root: Path,
filter: Optional[Callable[[os.DirEntry[str]], T]] = None,
-) -> Generator[T, None, None]:
+) -> Iterator[T]:
"""Recursively walk the tree starting at @root, optionally apply filter, yield non-none values"""
queue: Deque[Union[str, Path]] = collections.deque([root])
queue.append(entry.path)
-def find_files(root: Path) -> Generator[Path, None, None]:
+def find_files(root: Path) -> Iterator[Path]:
"""Generate a list of all filepaths relative to @root"""
yield from scandir_recursive(root,
lambda entry: Path(entry.path).relative_to(root))
@contextlib.contextmanager
-def suppress_stacktrace() -> Generator[None, None, None]:
+def suppress_stacktrace() -> Iterator[None]:
try:
yield
except subprocess.CalledProcessError as e:
Any,
Callable,
Dict,
- Generator,
+ Iterator,
List,
NoReturn,
Optional,
@contextlib.contextmanager
-def set_umask(mask: int) -> Generator[int, None, None]:
+def set_umask(mask: int) -> Iterator[int]:
old = os.umask(mask)
try:
yield old
@contextlib.contextmanager
-def do_delay_interrupt() -> Generator[None, None, None]:
+def do_delay_interrupt() -> Iterator[None]:
# CTRL+C is sent to the entire process group. We delay its handling in mkosi itself so the subprocess can
# exit cleanly before doing mkosi's cleanup. If we don't do this, we get device or resource is busy
# errors when unmounting stuff later on during cleanup. We only delay a single CTRL+C interrupt so that a
@contextlib.contextmanager
-def do_noop() -> Generator[None, None, None]:
+def do_noop() -> Iterator[None]:
yield
@classmethod
@contextlib.contextmanager
- def complete_step(cls, text: str, text2: Optional[str] = None) -> Generator[List[Any], None, None]:
+ def complete_step(cls, text: str, text2: Optional[str] = None) -> Iterator[List[Any]]:
cls.print_step(text)
cls.level += 1