Repository: geldata/gel
Pull request: Propagate dev_mode and psql path to CLI
Fixes edgedb/edgedb-cli#32

Requires edgedb/edgedb-cli#34 to be applied first.

Problem statement:
\psql should use our postgres/bin, not the system one
```
yury> \psql
Error executing command: Error running "psql" "-h" "/Users/yury/.edgedb" "-U" "edgedb" "-p" "55043" "-d" "edgedb"
```

^ I don't have system postgres, so there's no `psql` command in my `$PATH`.

Our Python repl code does this to locate the `psql` we built as part of our vendored postgres:

```
        pg_config = buildmeta.get_pg_config_path()
        psql = pg_config.parent / 'psql'
```

Please find a way to replicate this functionality.

Hints from issue discussion:
Python does that because it is in the same package as edgedb itself. When we use current CLI tools we can use them against *multiple different* edgedb servers, including ones not installed locally.

So to replicate that, we need to expose postgres directory from the edgedb server itself. And that still doesn't work if you have edgedb in a docker container or remotely. 

So I expect this to be postponed until we have `edgedb setup` which may be able to find distributions on the current machine (I'm still not sure it's easy to figure out which distribution to use in that case too).
`\psql` is a development feature, so it always implies the local EdgeDB build.  Whether the server is remote or not doesn't matter as long as it exposes the underlying Postgres connection parameters.
> `\psql` is a development feature, so it always implies the local EdgeDB build. Whether the server is remote or not doesn't matter as long as it exposes the underlying Postgres connection parameters.

Connection parameters yes. But we're discussing the path of the `psql` binary.
> But we're discussing the path of the `psql` binary.

Again, this is a devmode feature. We assume that both the `edgedb-cli` *and* the EdgeDB build are produced by the same `setup.py` run.  In this sense, there's absolutely no difference between the Rust CLI and the Python CLI.
And `\psql` shouldn't even be visible in `\h` or otherwise available if its a non-dev build of edgedb.
So I'm going to do following:
1. Expose some env variable during `cargo install`
2. Check that as the first directory for `psql` tool, falling back to `PATH`
I'm not sure what you mean by (1), but (2) makes sense. I'll wait for a PR!

Commit message: Propagate dev_mode and psql path to CLI

Fixes edgedb/edgedb-cli#32

Patch to review:
diff --git a/setup.py b/setup.py
index fbd37381820..7014a9d9649 100644
--- a/setup.py
+++ b/setup.py
@@ -298,10 +298,12 @@ class develop(setuptools_develop.develop):
     def run(self, *args, **kwargs):
         _check_rust()
         build = self.get_finalized_command('build')
+        build_base = pathlib.Path('build').resolve()
         rust_tmp = pathlib.Path(build.build_temp) / 'rust' / 'cli'
         rust_root = pathlib.Path(build.build_base) / 'cli'
         env = dict(os.environ)
         env['CARGO_TARGET_DIR'] = str(rust_tmp)
+        env['PSQL_DEFAULT_PATH'] = build_base / 'postgres' / 'install' / 'bin'
 
         subprocess.run(
             [
@@ -310,6 +312,7 @@ def run(self, *args, **kwargs):
                 '--git', EDGEDBCLI_REPO,
                 '--bin', 'edgedb',
                 '--root', rust_root,
+                '--features=dev_mode',
             ],
             env=env,
             check=True,
@@ -332,7 +335,7 @@ def run(self, *args, **kwargs):
         super().run(*args, **kwargs)
 
         _compile_parsers(pathlib.Path('build/lib'), inplace=True)
-        _compile_postgres(pathlib.Path('build').resolve())
+        _compile_postgres(build_base)
 
 
 class gen_build_cache_key(setuptools.Command):


Code review comments:
diff_hunk: @@ -298,10 +298,12 @@ class develop(setuptools_develop.develop):
     def run(self, *args, **kwargs):
         _check_rust()
         build = self.get_finalized_command('build')
+        build_base = pathlib.Path('build').resolve()
path: setup.py
text: @user1:
Use `build.build_base` here.

@author:
Rather than fixing this. I've updated all `Path('build')` invocations to use `build_base` everywhere as a separate commit.