Permalink
Browse files

Handle umbrella projects (start server on parent project)

Closes #48
Closes #53
  • Loading branch information...
1 parent 1cf5f74 commit 5676821017156f8704028a5fd69295820e8ae396 @carloslima carloslima committed Oct 30, 2016
Showing with 16 additions and 10 deletions.
  1. +14 −2 alchemist.py
  2. +2 −8 alchemist_client
View
@@ -13,6 +13,7 @@ class AlchemistClient:
def __init__(self, **kw):
self._cwd = kw.get('cwd', '')
+ self._cwd = self.get_project_base_dir()
self._ansi = kw.get('ansi', True)
self._debug = kw.get('debug', False)
self._alchemist_script = kw.get('alchemist_script', None)
@@ -354,6 +355,17 @@ def get_project_base_dir(self, running_servers_logs=None):
>>> alchemist = AlchemistClient(cwd=p01_lib_dir)
>>> alchemist.get_project_base_dir([]) == p01_dir
True
+ >>> #find directory of parent when running inside a nested project
+ >>> apps = os.path.join(p01_dir, "apps")
+ >>> os.mkdir(apps)
+ >>> nested = os.path.join(apps, "nested_project")
+ >>> os.mkdir(nested)
+ >>> nested_lib = os.path.join(nested, "lib")
+ >>> os.mkdir(nested_lib)
+ >>> open(os.path.join(nested, "mix.exs"), 'a').close()
+ >>> alchemist = AlchemistClient(cwd=nested_lib)
+ >>> alchemist.get_project_base_dir([]) == p01_dir
+ True
"""
if running_servers_logs == None:
@@ -363,14 +375,14 @@ def get_project_base_dir(self, running_servers_logs=None):
for i in range(len(paths)):
project_dir = os.sep.join(paths[:len(paths)-i])
log_tmp = "%s" % project_dir.replace("/", "zS")
- if log_tmp in running_servers_logs:
+ if log_tmp and log_tmp in running_servers_logs:
return project_dir
if os.path.exists(os.path.join(project_dir, "mix.exs")):
mix_dir.append(project_dir)
if len(mix_dir):
- return mix_dir.pop(0)
+ return mix_dir.pop()
return self._cwd
View
@@ -52,9 +52,7 @@ def main(argv):
ansi = False
if os.path.exists(cwd.strip()) == False:
raise Exception("working directory [%s] doesn't exist" % cwd)
- a = AlchemistClient()
- cwd = a.get_project_base_dir(os.path.abspath(arg))
- cwd = os.path.abspath(arg)
+ cwd = os.path.abspath(cwd)
if cmd == "":
cmd = read_stdin()
if alchemist_script == "":
@@ -76,8 +74,4 @@ def where_am_i():
if __name__ == "__main__":
- try:
- main(sys.argv[1:])
- except Exception as e:
- print("error: %s" % e.message)
- sys.exit(1)
+ main(sys.argv[1:])

0 comments on commit 5676821

Please sign in to comment.