2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-24 15:38:25 +00:00

refactor: change_working_directory optimizations

This commit is contained in:
Gavin D'souza 2020-02-02 00:19:58 +05:30
parent 2257f86fee
commit 92cd942fcf

View File

@ -119,21 +119,21 @@ def get_frappe_help(bench_path='.'):
def find_parent_bench(path):
"""Checks if parent directories are benches"""
path = os.path.abspath(path)
is_bench = is_bench_directory(directory=path)
if is_bench_directory(directory=path):
return path
home_path = os.path.expanduser("~")
root_path = os.path.abspath(os.sep)
if path not in {home_path, root_path}:
if is_bench:
return path
dir_list = os.path.split(path)
parent_dir = dir_list[0] if type(dir_list) == tuple else dir_list
# NOTE: the os.path.split assumes that given path is absolute
parent_dir = os.path.split(path)[0]
return find_parent_bench(parent_dir)
def change_working_directory():
"""Allows bench commands to be run from anywhere inside a bench directory"""
bench_path = find_parent_bench(".") or os.path.abspath(".")
cur_dir = os.path.abspath(".")
bench_path = find_parent_bench(cur_dir)
if bench_path:
os.chdir(bench_path)