From 7e29b29ed798a59a010541c243d688d66690e8d7 Mon Sep 17 00:00:00 2001 From: "Dennis.Glaeser" <dennis.glaeser@iws.uni-stuttgart.de> Date: Mon, 2 Nov 2020 18:17:49 +0100 Subject: [PATCH] [doc][getparamlist] avoid duplicates --- bin/doc/getparameterlist.py | 69 +++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/bin/doc/getparameterlist.py b/bin/doc/getparameterlist.py index 8ecd8e3a70..cee3922daf 100644 --- a/bin/doc/getparameterlist.py +++ b/bin/doc/getparameterlist.py @@ -91,58 +91,51 @@ def getParamsFromFile(file): return parameters # search all *.hh files for parameters +# TODO: allow runtime args with extensions and folder(s) to be checked parameters = [] rootDir = os.path.dirname(os.path.abspath(__file__)) + "/../../dumux" for root, _, files in os.walk(rootDir): for file in files: if os.path.splitext(file)[1] == ".hh" and os.path.splitext(file)[0] != 'parameters': - parameters.append(getParamsFromFile(os.path.join(root, file))) - -# flatten the list -parameters = list(itertools.chain.from_iterable(parameters)) + parameters.extend(getParamsFromFile(os.path.join(root, file))) + +# make sorted dictionary of the entries +# treat duplicates (could have differing default values or type names - e.g. via aliases) +parameterDict = {} +for params in parameters: + key = params['paramName'] + if key in parameterDict: + parameterDict[key]['defaultValue'].append(params['defaultValue']) + parameterDict[key]['paramType'].append(params['paramType']) + else: + parameterDict[key] = params + parameterDict[key]['defaultValue'] = [params['defaultValue']] + parameterDict[key]['paramType'] = [params['paramType']] +sortedParameterDict = {key: value for key, value in sorted(parameterDict.items())} -tableEntriesWithoutGroup = [] tableEntriesWithGroup = [] +tableEntriesWithoutGroup = [] previousGroupEntry = None -for entry in sorted(parameters, key=lambda p: p['paramName']): - paramName = entry['paramName'].split('.') - if len(paramName) == 1: - group = None - else: - group = paramName[0].strip('"') - - groupEntry = group if group else '-' - if groupEntry != previousGroupEntry: - previousGroupEntry = groupEntry - if groupEntry != '-': - groupEntry = '\\b ' + groupEntry - - paramType = entry['paramType'] - paramName = '.'.join(paramName[1:]).strip('"') if group else paramName[0].strip('"') - defaultValue = entry['defaultValue'] - if not defaultValue: - defaultValue = '' +for key in sortedParameterDict: - tableEntry = ' * | {} | {} | {} | {} | TODO: explanation |'.format(groupEntry, paramName , paramType , defaultValue) + entry = sortedParameterDict[key] + hasGroup = True if entry['paramName'].count('.') != 0 else False + groupEntry = '-' if not hasGroup else entry['paramName'].split('.')[0] + paramName = entry['paramName'] if not hasGroup else entry['paramName'].partition('.')[2] - if group: - tableEntriesWithGroup.append(tableEntry) - else: - tableEntriesWithoutGroup.append(tableEntry) + # TODO: selection scheme in case of multiple occurrences? For now we use the first one + paramType = entry['paramType'][0] + defaultValue = entry['defaultValue'][0] if entry['defaultValue'][0] != None else '' + if groupEntry != previousGroupEntry: + previousGroupEntry = groupEntry + if hasGroup: groupEntry = '\\b ' + groupEntry -# Remove duplicates. This does not work if one of the duplicate entries is the first in a group due to \b. -# We deal with this case later. -tableEntriesWithoutGroup = list(OrderedDict.fromkeys(tableEntriesWithoutGroup)) -tableEntriesWithGroup = list(OrderedDict.fromkeys(tableEntriesWithGroup)) + tableEntry = ' * | {} | {} | {} | {} | TODO: explanation |'.format(groupEntry, paramName , paramType , defaultValue) -# Remove left-over duplicates from above -for i, entry in enumerate(tableEntriesWithGroup): - if '\\b' in entry: - entry = entry.replace('\\b ', '') - if entry == tableEntriesWithGroup[i+1]: - del tableEntriesWithGroup[i+1] + if hasGroup: tableEntriesWithGroup.append(tableEntry) + else: tableEntriesWithoutGroup.append(tableEntry) # combine entries tableEntries = tableEntriesWithoutGroup + tableEntriesWithGroup -- GitLab