Skip to content

Commit

Permalink
fix parsing docstrings again
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Jan 15, 2025
1 parent 07dae3e commit de9f6d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/dipdup/codegen/substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ def event_metadata_to_jsonschema(
metadata: dict[str, Any],
) -> dict[str, Any]:
description = '\n'.join(metadata['docs']).replace(r'\[', '[').replace(r'\]', ']')
args_name = [a for a in metadata.get('args_name', ()) if a]
args_name = tuple(a for a in metadata.get('args_name', ()) if a)
if not args_name:
args_name = extract_args_name(description) # type: ignore[assignment]
args_name = extract_args_name(tuple(metadata['docs']))

schema = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'title': metadata['name'],
Expand Down
11 changes: 5 additions & 6 deletions src/dipdup/runtimes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import re
from contextlib import suppress
from copy import copy
from functools import cache
Expand All @@ -24,13 +23,13 @@


@cache
def extract_args_name(docs: list[str]) -> tuple[str, ...]:
def extract_args_name(docs: tuple[str, ...]) -> tuple[str, ...]:
docs_str = ''.join(docs).replace('\\n', '').replace('\n', '')

# find the last bracket pair, [] or ()
open_bracket = max(docs_str.rfind('['), docs_str.rfind('('))
close_bracket = max(docs_str.rfind(']'), docs_str.rfind(')'))
slice = docs_str[open_bracket + 1:close_bracket]
slice = docs_str[open_bracket + 1 : close_bracket]

return tuple(arg.strip('\\ ') for arg in slice.split(','))

Expand Down Expand Up @@ -74,7 +73,8 @@ def get_event_abi(self, qualname: str) -> dict[str, Any]:
continue
self._events[qualname] = event
found = True
else:

if not found:
raise FrameworkException(f'Event `{qualname}` not found in `{self._name}` spec')

return self._events[qualname]
Expand All @@ -86,7 +86,7 @@ def get_event_arg_names(event_abi: dict[str, Any]) -> tuple[str, ...]:

# NOTE: Old metadata
if not arg_names:
arg_names = extract_args_name(event_abi['docs'])
arg_names = extract_args_name(tuple(event_abi['docs']))

return tuple(arg_names)

Expand Down Expand Up @@ -175,7 +175,6 @@ def decode_event_args(

args = dict(zip(arg_names, args, strict=True))


payload = {}
for (key, value), type_ in zip(args.items(), arg_types, strict=True):
if isinstance(value, int):
Expand Down

0 comments on commit de9f6d6

Please sign in to comment.