Skip to content

Commit

Permalink
storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 7, 2025
1 parent 35bbab4 commit 2065eec
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 288 deletions.
2 changes: 0 additions & 2 deletions commune/utils/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def str2python(input)-> dict:

return output_dict



def get_folder_contents_advanced(url='commune-ai/commune.git',
host_url = 'https://github.com/',
auth_token=None):
Expand Down
82 changes: 71 additions & 11 deletions modules/base/base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,73 @@

import commune as c

class Demo:
def __init__(self, a=1, b=2):
self.config = c.munch({"a": a, "b": b})

def generate(self, x:int = 1, y:int = 2) -> int:
c.print(self.config, 'This is the config, it is a Munch object')
return x + y

def test(self, x:int = 1, y:int = 2) -> int:
return self.generate(x, y)

class Base:
"""
A base class that provides fundamental functionality for commune modules.
"""
def __init__(self, **kwargs):
"""
Initialize the base class with configurable parameters.
Args:
**kwargs: Arbitrary keyword arguments to configure the instance
"""
# Store configuration as a Munch object for dot notation access
self.config = c.munch(kwargs)

def call(self, fn_name: str, *args, **kwargs):
"""
Dynamically call a method of the class.
Args:
fn_name (str): Name of the method to call
*args: Positional arguments to pass to the method
**kwargs: Keyword arguments to pass to the method
Returns:
Result of the called method
"""
if hasattr(self, fn_name):
return getattr(self, fn_name)(*args, **kwargs)
raise AttributeError(f"Method {fn_name} not found")

def get_config(self) -> dict:
"""
Get the current configuration.
Returns:
dict: Current configuration
"""
return self.config

def update_config(self, **kwargs):
"""
Update the configuration with new values.
Args:
**kwargs: New configuration parameters
"""
self.config.update(kwargs)

def test(self) -> bool:
"""
Basic test method to verify the class is working.
Returns:
bool: True if test passes
"""
try:
# Basic functionality test
self.update_config(test_key="test_value")
assert self.get_config().test_key == "test_value"
return True
except Exception as e:
c.print(f"Test failed: {str(e)}", color='red')
return False

@classmethod
def help(cls):
"""
Display help information about the class.
"""
c.print(cls.__doc__, color='green')
c.print("\nAvailable methods:", color='yellow')
for method_name in dir(cls):
if not method_name.startswith('_'):
method = getattr(cls, method_name)
if callable(method):
c.print(f"- {method_name}: {method.__doc__}", color='cyan')
Loading

0 comments on commit 2065eec

Please sign in to comment.