From aae37bdad0797322a123fd36ae5ccbfea02dd9e1 Mon Sep 17 00:00:00 2001 From: sal Date: Thu, 16 Jan 2025 15:28:23 -0500 Subject: [PATCH] module --- commune/README.md | 25 ------------------------- commune/module.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 25 deletions(-) delete mode 100644 commune/README.md diff --git a/commune/README.md b/commune/README.md deleted file mode 100644 index db1e6f000..000000000 --- a/commune/README.md +++ /dev/null @@ -1,25 +0,0 @@ -xA module is a colleciton of functions as well as data or state -variables. The functions can be called from the command line interface or through the API. The data or state variables can be accessed and modified through the API. There is no blockchain or database in the module. The module is a simple way to organize code and data. To define a module, just define a class - -To make a module create a name - -{name}/module.py - -Then do this - -```python -class Module: - def __init__(self): - self.data = {} - def forward(self, a=1, b=2): - return a + b -``` - -To call it from the command line interface do this - -```bash -c {name}/forward a=1 b=2 -or -c.module(name).forward(a=1, b=2) -``` - diff --git a/commune/module.py b/commune/module.py index 13232ede8..d07a843f5 100755 --- a/commune/module.py +++ b/commune/module.py @@ -105,6 +105,12 @@ def ask(*args, **kwargs): return c.ask(*args, **kwargs) module.ask = ask return module + + + @classmethod + def getfile(cls, obj=None) -> str: + obj = cls.resolve_module(obj) + return inspect.getfile(obj) @classmethod def filepath(cls, obj=None) -> str: @@ -2041,6 +2047,12 @@ def run_test(self, module=None, parallel=True): return fn2result + def readmes(self, path='./', search=None): + files = c.files(path) + readmes = [f for f in files if f.endswith('.md')] + return readmes + + c.add_routes() Module = c # Module is alias of c