]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
util: gather three small utility functions together
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 2 Mar 2024 10:38:49 +0000 (11:38 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 2 Mar 2024 13:54:59 +0000 (14:54 +0100)
Esp. the two math-related ones can be considered related.

mkosi/util.py

index a375dd8058379752ec9b412b2ad96d378171d09c..38d07608a6fa5ee43cdcf3e0d15d78eacf4a2daa 100644 (file)
@@ -47,6 +47,18 @@ def tuplify(f: Callable[..., Iterable[T]]) -> Callable[..., tuple[T, ...]]:
     return functools.update_wrapper(wrapper, f)
 
 
+def one_zero(b: bool) -> str:
+    return "1" if b else "0"
+
+
+def is_power_of_2(x: int) -> bool:
+    return x > 0 and (x & x - 1 == 0)
+
+
+def round_up(x: int, blocksize: int = 4096) -> int:
+    return (x + blocksize - 1) // blocksize * blocksize
+
+
 @dictify
 def read_env_file(path: Path) -> Iterator[tuple[str, str]]:
     with path.open() as f:
@@ -155,10 +167,6 @@ class StrEnum(enum.Enum):
         return list(map(str, cls))
 
 
-def one_zero(b: bool) -> str:
-    return "1" if b else "0"
-
-
 @contextlib.contextmanager
 def umask(mask: int) -> Iterator[None]:
     old = os.umask(mask)
@@ -168,10 +176,6 @@ def umask(mask: int) -> Iterator[None]:
         os.umask(old)
 
 
-def is_power_of_2(x: int) -> bool:
-    return x > 0 and (x & x - 1 == 0)
-
-
 @contextlib.contextmanager
 def resource_path(mod: ModuleType) -> Iterator[Path]:
 
@@ -268,7 +272,3 @@ def resource_path(mod: ModuleType) -> Iterator[Path]:
     t = importlib.resources.files(mod)
     with as_file(t) as p:
         yield p
-
-
-def round_up(x: int, blocksize: int = 4096) -> int:
-    return (x + blocksize - 1) // blocksize * blocksize