PLW0603: fix
This commit is contained in:
@@ -13,7 +13,7 @@ import uuid
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from contextlib import _GeneratorContextManager
|
from contextlib import _GeneratorContextManager
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from functools import cached_property
|
from functools import cache, cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import NamedTemporaryFile, TemporaryDirectory
|
from tempfile import NamedTemporaryFile, TemporaryDirectory
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@@ -22,16 +22,10 @@ from colorama import Fore, Style
|
|||||||
|
|
||||||
from .logger import AbstractLogger, CompositeLogger, TerminalLogger
|
from .logger import AbstractLogger, CompositeLogger, TerminalLogger
|
||||||
|
|
||||||
# Global flag to track if test environment has been initialized
|
|
||||||
_test_env_initialized = False
|
|
||||||
|
|
||||||
|
|
||||||
|
@cache
|
||||||
def init_test_environment() -> None:
|
def init_test_environment() -> None:
|
||||||
"""Set up the test environment (network bridge, /etc/passwd) once."""
|
"""Set up the test environment (network bridge, /etc/passwd) once."""
|
||||||
global _test_env_initialized
|
|
||||||
if _test_env_initialized:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Set up network bridge
|
# Set up network bridge
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["ip", "link", "add", "br0", "type", "bridge"],
|
["ip", "link", "add", "br0", "type", "bridge"],
|
||||||
@@ -90,8 +84,6 @@ nogroup:x:65534:
|
|||||||
errno = ctypes.get_errno()
|
errno = ctypes.get_errno()
|
||||||
raise OSError(errno, os.strerror(errno), "Failed to mount group")
|
raise OSError(errno, os.strerror(errno), "Failed to mount group")
|
||||||
|
|
||||||
_test_env_initialized = True
|
|
||||||
|
|
||||||
|
|
||||||
# Load the C library
|
# Load the C library
|
||||||
libc = ctypes.CDLL("libc.so.6", use_errno=True)
|
libc = ctypes.CDLL("libc.so.6", use_errno=True)
|
||||||
|
|||||||
@@ -1,21 +1,14 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
from functools import cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from clan_lib.cmd import Log, RunOpts, run
|
from clan_lib.cmd import Log, RunOpts, run
|
||||||
from clan_lib.nix import nix_shell
|
from clan_lib.nix import nix_shell
|
||||||
|
|
||||||
_works: bool | None = None
|
|
||||||
|
|
||||||
|
|
||||||
|
@cache
|
||||||
def bubblewrap_works() -> bool:
|
def bubblewrap_works() -> bool:
|
||||||
global _works
|
|
||||||
if _works is None:
|
|
||||||
_works = _bubblewrap_works()
|
|
||||||
return _works
|
|
||||||
|
|
||||||
|
|
||||||
def _bubblewrap_works() -> bool:
|
|
||||||
real_bash_path = Path("bash")
|
real_bash_path = Path("bash")
|
||||||
if os.environ.get("IN_NIX_SANDBOX"):
|
if os.environ.get("IN_NIX_SANDBOX"):
|
||||||
bash_executable_path = Path(str(shutil.which("bash")))
|
bash_executable_path = Path(str(shutil.which("bash")))
|
||||||
|
|||||||
Reference in New Issue
Block a user