Skip to content

Commit

Permalink
Lookup edgedb.toml recursively in parent directories (#245)
Browse files Browse the repository at this point in the history
fix #244

Co-authored-by: Elvis Pranskevichus <elvis@edgedb.com>
  • Loading branch information
fmoor and elprans authored Oct 26, 2021
1 parent 44e279f commit d9a12b8
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions edgedb/con_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,8 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
if instance_name:
dsn = instance_name
else:
dir = os.getcwd()
if not os.path.exists(os.path.join(dir, 'edgedb.toml')):
raise errors.ClientConnectionError(
f'no `edgedb.toml` found and '
f'no connection options specified'
)
stash_dir = _stash_path(dir)
toml = find_edgedb_toml()
stash_dir = _stash_path(os.path.dirname(toml))
if os.path.exists(stash_dir):
with open(os.path.join(stash_dir, 'instance-name'), 'rt') as f:
dsn = f.read().strip()
Expand Down Expand Up @@ -423,6 +418,33 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
return addrs, params


def find_edgedb_toml():
dir = os.getcwd()
dev = os.stat(dir).st_dev

while True:
toml = os.path.join(dir, 'edgedb.toml')
if not os.path.isfile(toml):
parent = os.path.basename(dir)
if parent == dir:
raise errors.ClientConnectionError(
f'no `edgedb.toml` found and '
f'no connection options specified'
)
parent_dev = os.stat(parent).st_dev
if parent_dev != dev:
raise errors.ClientConnectionError(
f'no `edgedb.toml` found and '
f'no connection options specified'
f'(stopped searching for `edgedb.toml` at file system'
f'boundary {dir!r})'
)
dir = parent
dev = parent_dev
continue
return toml


def parse_connect_arguments(*, dsn, host, port, user, password,
database, admin,
tls_ca_file, tls_verify_hostname,
Expand Down

0 comments on commit d9a12b8

Please sign in to comment.