Skip to content

Commit

Permalink
docker path reoslution fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 18, 2024
1 parent eb88ea5 commit 4e60d8b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
24 changes: 15 additions & 9 deletions commune/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,22 +1451,22 @@ def tree(cls, *args, **kwargs) -> List[str]:
def tree2path(cls, *args, **kwargs) -> List[str]:
return c.module('tree').tree2path( *args, **kwargs)

@classmethod
def default_trees(cls):
return c.m('tree').default_trees


@classmethod
def trees(cls):
return c.m('tree').trees()

@classmethod
def add_tree(cls, path:str = './', **kwargs):
return c.m('tree').add_tree(path, **kwargs)
def add_tree(cls, *args, **kwargs):
return c.m('tree').add_tree(*args, **kwargs)

@classmethod
def add_tree(cls, *args, **kwargs):
return c.m('tree').add_tree(*args, **kwargs)

@classmethod
def rm_tree(cls, path:str = './', **kwargs):
return c.m('tree').rm_tree(path, **kwargs)
def rm_tree(cls, *args, **kwargs):
return c.m('tree').rm_tree(*args, **kwargs)

def repo2module(self, repo:str, name=None, template_module='demo', **kwargs):
if not repo_path.startswith('/') and not repo_path.startswith('.') and not repo_path.startswith('~'):
Expand Down Expand Up @@ -1509,7 +1509,13 @@ def simple2objectpath(cls, path:str,path2objectpath = {'tree': 'commune.tree.tre
return object_path
@classmethod
def simple2object(cls, path:str, **kwargs) -> str:
return c.import_object(c.simple2objectpath(path, **kwargs))
path = c.simple2objectpath(path, **kwargs)
try:
return c.import_object(path)
except Exception as e:
c.print(path)
raise e



@classmethod
Expand Down
62 changes: 29 additions & 33 deletions commune/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,40 @@

class Tree(c.Module):
tree_folders_path = 'module_tree_folders'
default_tree_path = c.libpath
default_tree_name = default_tree_path.split('/')[-1]
default_trees = [default_tree_path]
root_tree_path = c.libpath
root_tree_name = root_tree_path.split('/')[-1]
root_trees = [root_tree_path]
def __init__(self, **kwargs):
self.set_config(kwargs=locals())
# c.thread(self.run_loop)

@classmethod
def simple2path(cls, path:str, tree = None, **kwargs) -> bool:
def simple2path(cls, path:str, tree = None, update=False, ignore_prefixes = ['commune', 'modules', 'commune.modules'], **kwargs) -> bool:
pwd = c.pwd()
simple_path = path
if path == c.homepath:
path = cls.default_tree_path
path = pwd + '/' + path.replace('.', '/')
path = c.pwd() + '/' + path.replace('.', '/')
if os.path.isdir(path):
paths_in_dir = os.listdir(path)
for p in paths_in_dir:
if p.endswith('.py'):
filename = p.split('.')[0].split('/')[-1]
if filename == simple_path:
path = path +'/'+ p
return path


break

if os.path.exists(path + '.py'):
path = path + '.py'
else:
tree = cls.tree(update=True, include_default=True)
is_module_in_tree = simple_path in tree
tree = {k:v for k,v in tree.items() if simple_path in k}
root_tree = cls.root_tree()
tree = cls.tree()
tree.update(root_tree)
is_module_in_tree = bool(simple_path in tree)
if not is_module_in_tree:
tree = cls.tree(update=True, include_default=True)
assert len(tree) > 0, f'No module found for {simple_path}'
path = tree[simple_path]

tree = cls.tree(update=True, include_root=True)
tree.update(root_tree)

path = tree[simple_path]

return path


Expand All @@ -54,8 +53,8 @@ def path2tree(self, **kwargs) -> str:


@classmethod
def default_tree(cls, **kwargs):
return cls.tree(path = c.libpath, include_default=False, **kwargs)
def root_tree(cls, **kwargs):
return cls.tree(path = c.libpath, include_root=False, **kwargs)

_tree_cache = {}

Expand All @@ -70,13 +69,13 @@ def tree(cls,
search=None,
update = False,
max_age = None,
include_default = False,
include_root = False,
**kwargs
) -> List[str]:
path = cls.resolve_path(path or c.pwd())
is_repo = cls.is_repo(path)
if not is_repo:
path = cls.default_tree_path
path = cls.root_tree_path
cache_path = path.split('/')[-1]
if cache_path in cls._tree_cache:
tree = cls._tree_cache[cache_path]
Expand All @@ -88,9 +87,9 @@ def tree(cls,
cls.put(cache_path, tree)
if search != None:
tree = {k:v for k,v in tree.items() if search in k}
if include_default:
default_tree = cls.default_tree()
tree = {**default_tree, **tree}
if include_root:
root_tree = cls.root_tree()
tree = {**root_tree, **tree}
return tree


Expand Down Expand Up @@ -159,7 +158,7 @@ def pwd_tree(cls):

@classmethod
def is_pwd_tree(cls):
return c.pwd() == cls.default_tree_path
return c.pwd() == cls.root_tree_path

@classmethod
def trees(cls):
Expand All @@ -179,7 +178,7 @@ def tree2path(cls, tree : str = None, **kwargs) -> str:
@classmethod
def resolve_tree(cls, tree:str=None):
if tree == None:
tree = cls.default_tree_name
tree = cls.root_tree_name
return tree


Expand Down Expand Up @@ -269,13 +268,10 @@ def find_classes(cls, path):

@classmethod
def simple2objectpath(cls, simple_path:str, **kwargs) -> str:
path = cls.simple2path(simple_path, **kwargs)
classes = cls.find_classes(path)
if path.startswith(c.libpath):
object_path = path.replace(c.libpath, '')
else:
object_path = path.replace(c.pwd(), '')

object_path = cls.simple2path(simple_path, **kwargs)
classes = cls.find_classes(object_path)
if object_path.startswith(c.libpath):
object_path = object_path[len(c.libpath):]
object_path = object_path.replace('.py', '')
object_path = object_path.replace('/', '.')
if object_path.startswith('.'):
Expand Down

0 comments on commit 4e60d8b

Please sign in to comment.