Skip to content

Commit

Permalink
new refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Sep 27, 2024
1 parent b57d67f commit 04b2c22
Show file tree
Hide file tree
Showing 175 changed files with 18,285 additions and 508 deletions.
149 changes: 0 additions & 149 deletions commune/README.md

This file was deleted.

46 changes: 0 additions & 46 deletions commune/aes.py

This file was deleted.

File renamed without changes.
25 changes: 7 additions & 18 deletions commune/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ def forward(self, argv=None):
for arg in c.copy(argv):
if arg.startswith('--'):
key = arg[2:].split('=')[0]
# if key == 'cwd':
# new_argv = []
# for item in c.copy(argv):
# if '--cwd' in item:
# continue
# new_argv.append(item)
# new_cmd = 'c ' + ' '.join(c.copy(new_argv))

# cwd = c.resolve_path(arg.split('=')[1])
# v = c.cmd(f'{new_cmd}', cwd=cwd)
# c.print(v)
# return new_cmd
if key in self.helper_fns:
new_argvs = self.argv()
new_argvs.remove(arg)
Expand All @@ -70,10 +58,9 @@ def forward(self, argv=None):
init_kwargs[key] = self.determine_type(value)

# any of the --flags are init kwargs
if argv[0].endswith('.py'):
argv[0] = argv[0][:-3]


if os.path.isdir(argv[0]):
argv[0] = c.path2simple(argv[0])

if ':' in argv[0]:
# {module}:{fn} arg1 arg2 arg3 ... argn
argv[0] = argv[0].replace(':', '/')
Expand Down Expand Up @@ -101,12 +88,14 @@ def forward(self, argv=None):
fn_path = f'{module_name}/{fn}'
fn_obj = getattr(module, fn)
fn_type = c.classify_fn(fn_obj)
if fn_type == 'self' or len(init_kwargs) > 0:
is_property = c.is_property(fn_obj)
print(fn_type)
if fn_type == 'self' or len(init_kwargs) > 0 or is_property:
fn_obj = getattr(module(**init_kwargs), fn)
# calling function buffer
input_msg = f'[bold]fn[/bold]: {fn_path}'

if callable(fn_obj) and not c.is_property(fn_obj):
if callable(fn_obj):
args, kwargs = self.parse_args(argv)
if len(args) > 0 or len(kwargs) > 0:
inputs = {"args":args, "kwargs":kwargs}
Expand Down
File renamed without changes.
File renamed without changes.
52 changes: 29 additions & 23 deletions commune/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,7 @@ def is_pwd(cls, module:str = None):
module = c.module(module) if module != None else cls
return module.dirpath() == c.pwd()

@classmethod
def shortcuts(cls, cache=True) -> Dict[str, str]:
return c.get_yaml(f'{cls.dirpath()}/shortcuts.yaml')


def __repr__(self) -> str:
return f'<{self.class_name()}'
def __str__(self) -> str:
Expand Down Expand Up @@ -2493,11 +2490,7 @@ def is_property(cls, fn: 'Callable') -> bool:
'''
is the function a property
'''
try:
fn = cls.get_fn(fn, ignore_module_pattern=True)
except :
return False

fn = c.get_fn(fn)
return isinstance(fn, property)

def is_fn_self(self, fn):
Expand Down Expand Up @@ -2579,18 +2572,18 @@ def has_function_arg(cls, fn, arg:str):

@classmethod
def classify_fn(cls, fn):
try:
if not callable(fn):
fn = cls.get_fn(fn)
if not callable(fn):
return 'cls'
args = cls.get_function_args(fn)
if args[0] == 'self':
return 'self'
elif args[0] == 'cls':
return 'class'
except Exception as e:
if not callable(fn):
fn = cls.get_fn(fn)
if not callable(fn):
return 'cls'
args = cls.get_function_args(fn)
if len(args) == 0:
return 'property'
if args[0] == 'self':
return 'self'
elif args[0] == 'cls':
return 'class'

return 'static'

@classmethod
Expand Down Expand Up @@ -2780,7 +2773,7 @@ def simple2path(cls,
"""
# if cls.libname in simple and '/' not in simple and cls.can_import_module(simple):
# return simple
shortcuts = c.shortcuts()
shortcuts = c.shortcuts
simple = shortcuts.get(simple, simple)

if simple.endswith(extension):
Expand Down Expand Up @@ -2898,7 +2891,6 @@ def path2simple(cls,

@classmethod
def find_classes(cls, path='./', working=False):
print(path)
path = os.path.abspath(path)
if os.path.isdir(path):
classes = []
Expand Down Expand Up @@ -3245,7 +3237,7 @@ def get_module(cls,
if path in ['module', 'c']:
return c.Module
# if the module is a valid import path
shortcuts = c.shortcuts()
shortcuts = c.shortcuts
if path in shortcuts:
path = shortcuts[path]
module = None
Expand Down Expand Up @@ -4153,6 +4145,20 @@ def fuckkkk(self):
return "fuckkkk"


shortcuts = {
'user': 'server.user',
'namespace':'server.namespace',
'client': 'server.client',
'pm2': 'server.pm2',
'serializer': 'server.serializer',
'openai' : 'model.openai',
'openrouter': 'model.openrouter',
'or' : ' model.openrouter',
'r' : 'remote',
's' : 'subspace',
}


c.add_routes()
Module = c # Module is alias of c
Module.run(__name__)
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 04b2c22

Please sign in to comment.