Skip to content

Commit

Permalink
pyln-client: Remove category, description and long description from m…
Browse files Browse the repository at this point in the history
…ethods

Removed deprecated fields from pyln methods.

Changelog-Removed: pyln-client: Removed `category`, `description`, and `long descriptions` from pyln-client.
  • Loading branch information
ShahanaFarooqui committed Jan 20, 2025
1 parent 2f64283 commit d0e37fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
40 changes: 8 additions & 32 deletions contrib/pyln-client/pyln/client/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ class Method(object):
"""
def __init__(self, name: str, func: Callable[..., JSONType],
mtype: MethodType = MethodType.RPCMETHOD,
deprecated: Union[bool, List[str]] = None,
description: str = None):
deprecated: Union[bool, List[str]] = None):
self.name = name
self.func = func
self.mtype = mtype
self.background = False
self.deprecated = deprecated
self.description = description
self.before: List[str] = []
self.after: List[str] = []

Expand Down Expand Up @@ -83,9 +81,6 @@ def get_usage(self):
else:
args.append("[%s]" % arg)

if self.description is not None:
args.append("\n%s" % self.description)

return " ".join(args)


Expand Down Expand Up @@ -354,8 +349,7 @@ def convert_featurebits(

def add_method(self, name: str, func: Callable[..., Any],
background: bool = False,
deprecated: Optional[Union[bool, List[str]]] = None,
description: str = None) -> None:
deprecated: Optional[Union[bool, List[str]]] = None) -> None:
"""Add a plugin method to the dispatch table.
The function will be expected at call time (see `_dispatch`)
Expand Down Expand Up @@ -392,7 +386,7 @@ def add_method(self, name: str, func: Callable[..., Any],
)

# Register the function with the name
method = Method(name, func, MethodType.RPCMETHOD, deprecated, description)
method = Method(name, func, MethodType.RPCMETHOD, deprecated)
method.background = background
self.methods[name] = method

Expand Down Expand Up @@ -506,36 +500,25 @@ def get_option(self, name: str) -> Optional[Any]:
else:
return self.options[name].default

def async_method(self, method_name: str, category: Optional[str] = None,
desc: Optional[str] = None,
long_desc: Optional[str] = None,
def async_method(self, method_name: str,
deprecated: Optional[Union[bool, List[str]]] = None) -> NoneDecoratorType:
"""Decorator to add an async plugin method to the dispatch table.
Internally uses add_method.
"""
def decorator(f: Callable[..., None]) -> Callable[..., None]:
for attr, attr_name in [(category, "Category"), (desc, "Description"), (long_desc, "Long description")]:
if attr is not None:
self.log("{} is deprecated but defined in method {}; it will be ignored by Core Lightning".format(attr_name, method_name), level="warn")
self.add_method(method_name, f, background=True, deprecated=deprecated)
return f
return decorator

def method(self, method_name: str, category: Optional[str] = None,
desc: Optional[str] = None,
long_desc: Optional[str] = None,
deprecated: Union[bool, List[str]] = None,
description: str = None) -> JsonDecoratorType:
def method(self, method_name: str,
deprecated: Union[bool, List[str]] = None) -> JsonDecoratorType:
"""Decorator to add a plugin method to the dispatch table.
Internally uses add_method.
"""
def decorator(f: Callable[..., JSONType]) -> Callable[..., JSONType]:
for attr, attr_name in [(category, "Category"), (desc, "Description"), (long_desc, "Long description")]:
if attr is not None:
self.log("{} is deprecated but defined in method {}; it will be ignored by Core Lightning".format(attr_name, method_name), level="warn")
self.add_method(method_name, f, background=False, deprecated=deprecated, description=f.__doc__)
self.add_method(method_name, f, background=False, deprecated=deprecated)
return f
return decorator

Expand Down Expand Up @@ -948,16 +931,9 @@ def _getmanifest(self, **kwargs) -> JSONType:
doc = "Undocumented RPC method from a plugin."
doc = re.sub('\n+', ' ', doc)

# For compatibility with lightningd prior to 24.08, we must
# provide a description. Ignored by 24.08 onwards,
description = method.description
if description is None:
description = ""

methods.append({
'name': method.name,
'usage': method.get_usage(),
'description': description,
'usage': method.get_usage()
})

manifest = {
Expand Down
8 changes: 7 additions & 1 deletion contrib/pyln-client/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,15 @@ def some_method(some_arg: str = None):
manifest = p._getmanifest()
usage = p.get_usage()

print("MANIFEST")
print(manifest)
print("USAGE")
print(usage)
assert manifest['rpcmethods'][0] is False

assert manifest['rpcmethods'][0]['name'] == 'some_method'
assert "some_arg" in manifest['rpcmethods'][0]['usage']
assert "some description" in manifest['rpcmethods'][0]['usage']
assert "some_method" in usage
assert "some_arg" in usage
assert "some description" in usage
assert "some added description" in usage

0 comments on commit d0e37fb

Please sign in to comment.