diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-05-28 11:31:03 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-05-28 12:49:20 +0200 |
commit | 0fe547cd982c616b08c2a21c9ae7d4ab72619037 (patch) | |
tree | a41d6577ea8d8a306e69b46f81c021b4d605a827 | |
parent | spec: Fix attribute references (diff) | |
download | rtems-central-0fe547cd982c616b08c2a21c9ae7d4ab72619037.tar.bz2 |
items: Add ItemCache.types
-rw-r--r-- | rtemsspec/items.py | 14 | ||||
-rw-r--r-- | rtemsspec/tests/test_items_itemcache.py | 2 |
2 files changed, 13 insertions, 3 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py index bfd0dac1..ee5a9fb8 100644 --- a/rtemsspec/items.py +++ b/rtemsspec/items.py @@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-2-Clause """ This module provides specification items and an item cache. """ -# Copyright (C) 2019, 2020 embedded brains GmbH (http://www.embedded-brains.de) +# Copyright (C) 2019, 2021 embedded brains GmbH (http://www.embedded-brains.de) # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -31,7 +31,7 @@ import pickle import string import stat from typing import Any, Callable, Dict, Iterable, Iterator, List, NamedTuple, \ - Optional, Tuple, Union + Optional, Set, Tuple, Union import yaml @@ -592,6 +592,7 @@ class ItemCache: post_process_load: Optional[Callable[[ItemMap], None]] = None): self._items = {} # type: ItemMap + self._types = set() # type: Set[str] self._updates = 0 cache_dir = os.path.abspath(config["cache-directory"]) for index, path in enumerate(config["paths"]): @@ -624,6 +625,11 @@ class ItemCache: """ Returns the map of all specification items. """ return self._items + @property + def types(self) -> Set[str]: + """ Returns the types of the items. """ + return self._types + def add_volatile_item(self, path: str, uid: str) -> Item: """ Adds an item stored in the specified file to the cache and returns it. @@ -700,7 +706,9 @@ class ItemCache: type_name = value[spec_type.key] path.append(type_name) spec_type = spec_type.refinements[type_name] - item["_type"] = "/".join(path) + the_type = "/".join(path) + item["_type"] = the_type + self._types.add(the_type) class EmptyItemCache(ItemCache): diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py index 2e6c64c7..81e2db70 100644 --- a/rtemsspec/tests/test_items_itemcache.py +++ b/rtemsspec/tests/test_items_itemcache.py @@ -45,6 +45,8 @@ def test_load(tmpdir): item_count = len(items) item_cache = ItemCache(config, post_process_load) + assert len(item_cache.types) == 1 + assert list(item_cache.types)[0] == "" assert item_count == len(item_cache.all) assert item_cache.updates cache_dir = config["cache-directory"] |