Changeset b3f5b7e in rtems-central


Ignore:
Timestamp:
Apr 29, 2020, 2:15:04 PM (6 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
3b9b2bd
Parents:
9dad293
git-author:
Sebastian Huber <sebastian.huber@…> (04/29/20 14:15:04)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/28/20 08:34:46)
Message:

items: Add Item.map()

Location:
rtemsqual
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • rtemsqual/applconfig.py

    r9dad293 rb3f5b7e  
    6868
    6969
    70 def _generate_feature(content: SphinxContent, item: Item, option_type: str,
    71                       _item_cache: ItemCache) -> None:
     70def _generate_feature(content: SphinxContent, item: Item,
     71                      option_type: str) -> None:
    7272    content.add_definition_item("DEFAULT CONFIGURATION:",
    7373                                _OPTION_DEFAULT_CONFIG[option_type](item))
     
    123123
    124124def _resolve_constraint_links(content: SphinxContent, item: Item,
    125                               item_cache: ItemCache,
    126125                              constraint: Dict[str, Any]) -> None:
    127126    if "links" in constraint:
     
    129128            constraint["custom"] = []
    130129        for link in reversed(constraint["links"]):
    131             other = item_cache[item.to_abs_uid(link)]
     130            other = item.map(link)
    132131            other.register_license_and_copyrights(content)
    133132            constraint["custom"].append(other["text"])
    134133
    135134
    136 def _generate_constraint(content: SphinxContent, item: Item,
    137                          item_cache: ItemCache) -> None:
     135def _generate_constraint(content: SphinxContent, item: Item) -> None:
    138136    constraint = item["appl-config-option-constraint"]
    139137    count = len(constraint)
    140138    lines = []  # type: List[str]
    141     _resolve_constraint_links(content, item, item_cache, constraint)
     139    _resolve_constraint_links(content, item, constraint)
    142140    if count == 1:
    143141        if "min" in constraint:
     
    169167
    170168def _generate_initializer_or_integer(content: SphinxContent, item: Item,
    171                                      _option_type: str,
    172                                      item_cache: ItemCache) -> None:
     169                                     _option_type: str) -> None:
    173170    default_value = item["appl-config-option-default-value"]
    174171    if not isinstance(default_value, str) or " " not in default_value:
    175172        default_value = f"The default value is {default_value}."
    176173    content.add_definition_item("DEFAULT VALUE:", default_value)
    177     _generate_constraint(content, item, item_cache)
     174    _generate_constraint(content, item)
    178175
    179176
     
    192189
    193190
    194 def _generate_content(group: Item, options: ItemMap,
    195                       item_cache: ItemCache) -> SphinxContent:
     191def _generate_content(group: Item, options: ItemMap) -> SphinxContent:
    196192    content = SphinxContent()
    197193    group.register_license_and_copyrights(content)
     
    210206        option_type = item["appl-config-option-type"]
    211207        content.add_definition_item("OPTION TYPE:", _OPTION_TYPES[option_type])
    212         _OPTION_GENERATORS[option_type](content, item, option_type, item_cache)
     208        _OPTION_GENERATORS[option_type](content, item, option_type)
    213209        content.add_definition_item("DESCRIPTION:",
    214210                                    item["appl-config-option-description"])
     
    235231        options = {}  # type: ItemMap
    236232        _gather_options(group, options)
    237         content = _generate_content(group, options, item_cache)
     233        content = _generate_content(group, options)
    238234        content.write(group_config["target"])
  • rtemsqual/items.py

    r9dad293 rb3f5b7e  
    110110class Item:
    111111    """ Objects of this class represent a specification item. """
    112     def __init__(self, uid: str, data: Any):
     112    def __init__(self, item_cache: "ItemCache", uid: str, data: Any):
     113        self._item_cache = item_cache
    113114        self._uid = uid
    114115        self._data = data
     
    136137        return os.path.normpath(
    137138            os.path.join(os.path.dirname(self.uid), abs_or_rel_uid))
     139
     140    def map(self, abs_or_rel_uid: str) -> "Item":
     141        """
     142        Maps the absolute UID or the UID relative to this item to the
     143        corresponding item.
     144        """
     145        return self._item_cache[self.to_abs_uid(abs_or_rel_uid)]
    138146
    139147    def links_to_parents(self) -> Iterator[Link]:
     
    241249                data_by_uid = pickle.load(pickle_src)
    242250        for uid, data in data_by_uid.items():
    243             item = Item(uid, data)
     251            item = Item(self, uid, data)
    244252            self._items[uid] = item
    245253            if not item["links"]:
  • rtemsqual/tests/test_content_sphinx.py

    r9dad293 rb3f5b7e  
    3030from rtemsqual.content import SphinxContent
    3131from rtemsqual.content import MacroToSphinx
    32 from rtemsqual.items import Item
     32from rtemsqual.items import Item, ItemCache
     33
     34
     35class EmptyCache(ItemCache):
     36    def __init__(self):
     37        return
    3338
    3439
     
    127132    data["glossary-term"] = "y"
    128133    terms = {}
    129     terms["x"] = Item("x", data)
     134    terms["x"] = Item(EmptyCache(), "x", data)
    130135    macro_to_sphinx.set_terms(terms)
    131136    assert "@" == macro_to_sphinx.substitute("@@")
  • rtemsqual/tests/test_items_item.py

    r9dad293 rb3f5b7e  
    2828import pytest
    2929
    30 from rtemsqual.items import Item, Link
     30from rtemsqual.items import Item, ItemCache, Link
     31
     32
     33class EmptyCache(ItemCache):
     34    def __init__(self):
     35        return
    3136
    3237
    3338def test_to_abs_uid():
    34     item = Item("/x/y", {})
     39    item = Item(EmptyCache(), "/x/y", {})
    3540    assert item.to_abs_uid("z") == "/x/z"
    3641    assert item.to_abs_uid("/z") == "/z"
     
    4045
    4146def test_uid():
    42     item = Item("x", {})
     47    item = Item(EmptyCache(), "x", {})
    4348    assert item.uid == "x"
    4449
     
    4752    data = {}
    4853    data["x"] = "y"
    49     item = Item("z", data)
     54    item = Item(EmptyCache(), "z", data)
    5055    assert "x" in item
    5156    assert "a" not in item
     
    5560    data = {}
    5661    data["x"] = "y"
    57     item = Item("z", data)
     62    item = Item(EmptyCache(), "z", data)
    5863    assert item["x"] == "y"
    5964
    6065
    6166def test_children():
    62     child = Item("c", {})
    63     parent = Item("p", {})
     67    child = Item(EmptyCache(), "c", {})
     68    parent = Item(EmptyCache(), "p", {})
    6469    parent.add_link_to_child(Link(child, {"a": "b"}))
    6570    children = [item for item in parent.children()]
     
    7378
    7479def _is_enabled(enabled, enabled_by):
    75     item = Item("i", {"enabled-by": enabled_by})
     80    item = Item(EmptyCache(), "i", {"enabled-by": enabled_by})
    7681    return item.is_enabled(enabled)
    7782
     
    102107def test_save_and_load(tmpdir):
    103108    item_file = os.path.join(tmpdir, "i.yml")
    104     item = Item("i", {"k": "v"})
     109    item = Item(EmptyCache(), "i", {"k": "v"})
    105110    item.file = item_file
    106111    assert item.file == item_file
     
    110115    assert item.file == item_file
    111116
    112     item2 = Item("i2", {})
     117    item2 = Item(EmptyCache(), "i2", {})
    113118    item2.file = item_file
    114119    with pytest.raises(KeyError):
  • rtemsqual/tests/test_items_itemcache.py

    r9dad293 rb3f5b7e  
    5252    t = ic.top_level
    5353    assert len(t) == 1
    54     assert t["/p"]["v"] == "p"
     54    p = t["/p"]
     55    assert p["v"] == "p"
     56    assert p.map("/p") == p
     57    assert p.map("p") == p
    5558    a = ic.all
    5659    assert len(a) == 2
Note: See TracChangeset for help on using the changeset viewer.