Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Apr 7, 2024
1 parent 6e2f715 commit e97aef9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion commune/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class cli(c.Module):

def __init__(self,
args = None,
module = None,
module = 'module',
new_event_loop: bool = True,
verbose = True,
save: bool = True):
Expand Down
17 changes: 13 additions & 4 deletions commune/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ def put(cls,

if encrypt or password != None:
v = c.encrypt(v, password=password)

if not c.jsonable(v):
v = c.serialize(v)

data = {'data': v, 'encrypted': encrypt, 'timestamp': c.timestamp()}

Expand Down Expand Up @@ -1512,14 +1515,14 @@ def find_python_classes(cls, path:str , class_index:int=0, search:str = None, st


@classmethod
def path2objectpath(cls, path:str = None, search=['c.Module'], tree=None) -> str:
def path2objectpath(cls, path:str = None, tree=None) -> str:
path = path or cls.filepath()
tree = tree or 'commune'
tree_path = cls.tree2path()[tree]

if path.endswith('module/module.py'):
return 'commune.Module'
python_classes = cls.find_python_classes(path, search=search)
python_classes = cls.find_python_classes(path)
if len(python_classes) == 0:
return None

Expand All @@ -1544,6 +1547,7 @@ def get_module(cls,
path = path or 'module'
tree = tree or 'commune'
module = None
c.print(f'Importing {path}', color='green', verbose=verbose)


if cache:
Expand All @@ -1553,11 +1557,16 @@ def get_module(cls,
else:
c.module_cache[tree] = {}


c.print(f'Importing {module}', color='green', verbose=verbose)

if module == None:
if path == 'tree':
module = c.import_object('commune.tree.Tree')
else:
# convert the simple to path
c.print(f'FACKKKKKK {path}', color='green', verbose=verbose)

path = c.simple2path(path, tree=tree)
object_path = c.path2objectpath(path, tree=tree)
module = c.import_object(object_path)
Expand Down Expand Up @@ -2761,8 +2770,8 @@ def serve(cls,
address = c.ip() + ':' + str(remote_kwargs['port'])
return {'success':True, 'name': server_name, 'address':address, 'kwargs':kwargs}


module_class = cls.resolve_module(module)
c.print(f'Serving {server_name} on port {port} {module}', color='green')
module_class = c.module(module)
kwargs.update(extra_kwargs)

if mnemonic != None:
Expand Down
1 change: 0 additions & 1 deletion commune/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def update_namespace(cls,
addresses = [ip+':'+str(p) for p in c.used_ports()]
future2address = {}
for address in addresses:
c.print(f'Updating {address}', color='yellow')
f = c.submit(c.call, params=[address+'/server_name'], timeout=timeout)
future2address[f] = address
futures = list(future2address.keys())
Expand Down
2 changes: 1 addition & 1 deletion sandbox.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import commune as c
c.print(c.module('miner', tree='bittensor').filepath())
c.print(c.module('vali'))
2 changes: 1 addition & 1 deletion subnet/subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Subnet(c.Module):
def __init__(self, network = 'local'):
self.init(locals()) # send locals() to init
self.set_config(locals()) # send locals() to init

def test(self, n=3):
for i in range(n):
Expand Down
5 changes: 2 additions & 3 deletions subnet/vali.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import commune as c

Vali = c.module("vali")
class Vali(Vali):
class Vali(c.module("vali")):
def __init__(self,
network='local', # the network is local
netuid = 1,
search = None,
**kwargs):
# send locals() to init
self.init(locals())
self.init_vali(locals())

def score_module(self, module):
a = 1
Expand Down

0 comments on commit e97aef9

Please sign in to comment.