mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-24 18:45:52 +03:00
Add option to definitions.py to search for functions a function refers to
This commit is contained in:
parent
48b2e853a8
commit
4ebb688f4f
1 changed files with 22 additions and 1 deletions
|
@ -86,9 +86,12 @@ def used_names(prefix, item, defs, names):
|
||||||
for name, funcs in defs.get('class', {}).items():
|
for name, funcs in defs.get('class', {}).items():
|
||||||
used_names(prefix + name + ".", name, funcs, names)
|
used_names(prefix + name + ".", name, funcs, names)
|
||||||
|
|
||||||
|
path = prefix.rstrip('.')
|
||||||
for used in defs.get('uses', ()):
|
for used in defs.get('uses', ()):
|
||||||
if used in names:
|
if used in names:
|
||||||
names[used].setdefault('used', {}).setdefault(item, []).append(prefix.rstrip('.'))
|
if item:
|
||||||
|
names[item].setdefault('uses', []).append(used)
|
||||||
|
names[used].setdefault('used', {}).setdefault(item, []).append(path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -113,6 +116,10 @@ if __name__ == '__main__':
|
||||||
"--referrers", default=0, type=int,
|
"--referrers", default=0, type=int,
|
||||||
help="Include referrers up to the given depth"
|
help="Include referrers up to the given depth"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--referred", default=0, type=int,
|
||||||
|
help="Include referred down to the given depth"
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--format", default="yaml",
|
"--format", default="yaml",
|
||||||
help="Output format, one of 'yaml' or 'dot'"
|
help="Output format, one of 'yaml' or 'dot'"
|
||||||
|
@ -161,6 +168,20 @@ if __name__ == '__main__':
|
||||||
continue
|
continue
|
||||||
result[name] = definition
|
result[name] = definition
|
||||||
|
|
||||||
|
referred_depth = args.referred
|
||||||
|
referred = set()
|
||||||
|
while referred_depth:
|
||||||
|
referred_depth -= 1
|
||||||
|
for entry in result.values():
|
||||||
|
for uses in entry.get("uses", ()):
|
||||||
|
referred.add(uses)
|
||||||
|
for name, definition in names.items():
|
||||||
|
if not name in referred:
|
||||||
|
continue
|
||||||
|
if ignore and any(pattern.match(name) for pattern in ignore):
|
||||||
|
continue
|
||||||
|
result[name] = definition
|
||||||
|
|
||||||
if args.format == 'yaml':
|
if args.format == 'yaml':
|
||||||
yaml.dump(result, sys.stdout, default_flow_style=False)
|
yaml.dump(result, sys.stdout, default_flow_style=False)
|
||||||
elif args.format == 'dot':
|
elif args.format == 'dot':
|
||||||
|
|
Loading…
Reference in a new issue