Hello, On Tue, Mar 18, 2025 at 12:27:26PM +0100, Ahmad Fatoum wrote: > Hello Uwe, > > On 3/18/25 12:03, Uwe Kleine-König wrote: > > On Tue, Mar 18, 2025 at 09:25:04AM +0100, Ahmad Fatoum wrote: > >> fsw.end_node() > >> - seq = 0 > >> with fsw.add_node('configurations'): > >> - for model, compat, files in entries: > >> - seq += 1 > >> - with fsw.add_node(f'conf-{seq}'): > >> + for dtbname, model, compat, files in entries: > >> + with fsw.add_node(f'conf-{dtbname}'): > > > > Funny/surprising semantic of fsw.add_node (i.e. fsw refers to the new > > node in the with-body?) > > Yes. I suspect it's to ensure that a node end tag is inserted > after the properties. > > >> - entries.append([model, compat, files_seq]) > >> + dtbname = os.path.basename(fname) > >> + ndtbs_seen = len(dtbs_seen) > >> + dtbs_seen.add(dtbname) > >> + if len(dtbs_seen) == ndtbs_seen: > >> + raise RuntimeError(f"Duplicate file name '{dtbname}' during FIT creation") > >> + > >> + entries.append([dtbname, model, compat, files_seq]) > > > > dtbname = os.path.basename(fname) > > if dtbname in dtbs_seen: > > raise RuntimeError(...) > > dtbs_seen.add(dtbname) > > entries.append(...) > > > > looks more pythonic (to me). > > I dislike iterating twice over the dtbs. I wrote it this way, > because I assumed calling len on the set is O(1). I would expect that both `dtbname in dtbs_seen` and `dtbs_seen.add(dtbname)` is O(1) (in the absense of hash collisions). Best regards Uwe