From: Daan De Meyer Date: Sun, 7 Jul 2024 13:35:27 +0000 (+0200) Subject: Simplify parse_new_includes() X-Git-Tag: v24~50^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19cffa37df2658b9364ac14f7f691ba1fedfcb23;p=thirdparty%2Fmkosi.git Simplify parse_new_includes() We don't need to keep track of the current amount of includes since those includes are already tracked in parsed_includes and will be ignored. Slightly less efficient but this shouldn't matter here. We also store the inode in parsed_includes before we parse the config to make sure we don't try to parse it more than once. --- diff --git a/mkosi/config.py b/mkosi/config.py index 9716977a0..68b553c3c 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -3344,13 +3344,11 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu @contextlib.contextmanager def parse_new_includes() -> Iterator[None]: - current_num_of_includes = len(getattr(namespace, "include", [])) - try: yield finally: # Parse any includes that were added after yielding. - for p in getattr(namespace, "include", [])[current_num_of_includes:]: + for p in getattr(namespace, "include", []): for c in BUILTIN_CONFIGS: if p == Path(c): path = resources / c @@ -3363,6 +3361,8 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu if (st.st_dev, st.st_ino) in parsed_includes: continue + parsed_includes.add((st.st_dev, st.st_ino)) + if any(p == Path(c) for c in BUILTIN_CONFIGS): _, [config] = parse_config(["--directory", "", "--include", os.fspath(path)]) make_executable( @@ -3378,7 +3378,6 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu with chdir(path if path.is_dir() else Path.cwd()): parse_config_one(path if path.is_file() else Path(".")) - parsed_includes.add((st.st_dev, st.st_ino)) class ConfigAction(argparse.Action): def __call__(