From 8da9e93979e207c42833539d7df31357ed64864b Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Sat, 20 Sep 2025 15:26:17 -0700 Subject: [PATCH 1/3] Add failing test --- cmd/dbc/install_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cmd/dbc/install_test.go b/cmd/dbc/install_test.go index d958def9..9834291f 100644 --- a/cmd/dbc/install_test.go +++ b/cmd/dbc/install_test.go @@ -120,6 +120,36 @@ func (suite *SubcommandTestSuite) TestInstallVenv() { "\nInstalled test-driver-1 1.1.0 to "+filepath.Join(suite.tempdir, "etc", "adbc", "drivers")+"\n", suite.runCmd(m)) } +func (suite *SubcommandTestSuite) TestInstallEnvironmentPrecedence() { + // Like the driver managers, dbc follows a precedence chain when + // ADBC_DRIVER_MANAGER, VIRTUAL_ENV, and CONDA_PREFIX are set with each + // variable overriding the next. + driver_path := filepath.Join(suite.tempdir, "driver_path") + venv_path := filepath.Join(suite.tempdir, "venv_path") + conda_path := filepath.Join(suite.tempdir, "conda_path") + os.Setenv("ADBC_DRIVER_PATH", driver_path) + os.Setenv("VIRTUAL_ENV", venv_path) + os.Setenv("CONDA_PREFIX", conda_path) + + m := InstallCmd{Driver: "test-driver-1", Level: config.ConfigEnv}. + GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg}) + suite.runCmd(m) + + suite.FileExists(filepath.Join(driver_path, "test-driver-1.toml")) + suite.NoFileExists(filepath.Join(venv_path, "test-driver-1.toml")) + suite.NoFileExists(filepath.Join(conda_path, "test-driver-1.toml")) + + os.Unsetenv("ADBC_DRIVER_PATH") + suite.FileExists(filepath.Join(venv_path, "test-driver-1.toml")) + suite.NoFileExists(filepath.Join(conda_path, "test-driver-1.toml")) + + os.Unsetenv("VIRTUAL_ENV") + suite.FileExists(filepath.Join(conda_path, "test-driver-1.toml")) + + os.Unsetenv("CONDA_PREFIX") + suite.FileExists(filepath.Join(suite.tempdir, "test-driver-1.toml")) +} + func (suite *SubcommandTestSuite) TestInstallCondaPrefix() { os.Unsetenv("ADBC_DRIVER_PATH") os.Setenv("CONDA_PREFIX", suite.tempdir) From bde239fda77c7269180a7b29fd2dd69733929039 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Mon, 22 Sep 2025 15:20:53 -0400 Subject: [PATCH 2/3] fix location and test --- cmd/dbc/install_test.go | 15 +++++++++------ config/dirs_unixlike.go | 6 +++++- config/dirs_windows.go | 6 +++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/cmd/dbc/install_test.go b/cmd/dbc/install_test.go index 9834291f..a4b240d5 100644 --- a/cmd/dbc/install_test.go +++ b/cmd/dbc/install_test.go @@ -140,14 +140,17 @@ func (suite *SubcommandTestSuite) TestInstallEnvironmentPrecedence() { suite.NoFileExists(filepath.Join(conda_path, "test-driver-1.toml")) os.Unsetenv("ADBC_DRIVER_PATH") - suite.FileExists(filepath.Join(venv_path, "test-driver-1.toml")) - suite.NoFileExists(filepath.Join(conda_path, "test-driver-1.toml")) + m = InstallCmd{Driver: "test-driver-1", Level: config.ConfigEnv}. + GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg}) + suite.runCmd(m) + suite.FileExists(filepath.Join(venv_path, "etc", "adbc", "drivers", "test-driver-1.toml")) + suite.NoFileExists(filepath.Join(conda_path, "etc", "adbc", "drivers", "test-driver-1.toml")) os.Unsetenv("VIRTUAL_ENV") - suite.FileExists(filepath.Join(conda_path, "test-driver-1.toml")) - - os.Unsetenv("CONDA_PREFIX") - suite.FileExists(filepath.Join(suite.tempdir, "test-driver-1.toml")) + m = InstallCmd{Driver: "test-driver-1", Level: config.ConfigEnv}. + GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg}) + suite.runCmd(m) + suite.FileExists(filepath.Join(conda_path, "etc", "adbc", "drivers", "test-driver-1.toml")) } func (suite *SubcommandTestSuite) TestInstallCondaPrefix() { diff --git a/config/dirs_unixlike.go b/config/dirs_unixlike.go index 0486ea0c..57069421 100644 --- a/config/dirs_unixlike.go +++ b/config/dirs_unixlike.go @@ -84,7 +84,11 @@ func GetDriver(cfg Config, driverName string) (DriverInfo, error) { } func CreateManifest(cfg Config, driver DriverInfo) (err error) { - return createDriverManifest(cfg.Location, driver) + loc, err := EnsureLocation(cfg) + if err != nil { + return err + } + return createDriverManifest(loc, driver) } func UninstallDriver(cfg Config, info DriverInfo) error { diff --git a/config/dirs_windows.go b/config/dirs_windows.go index 1d157a48..5e340650 100644 --- a/config/dirs_windows.go +++ b/config/dirs_windows.go @@ -219,7 +219,11 @@ func CreateManifest(cfg Config, driver DriverInfo) (err error) { if cfg.Location == "" { return fmt.Errorf("cannot write manifest to env config without %s set", adbcEnvVar) } - return createDriverManifest(cfg.Location, driver) + loc, err := EnsureLocation(cfg) + if err != nil { + return err + } + return createDriverManifest(loc, driver) } var k registry.Key From ee3f0e77d56c96ccd953c4c3b60682adf7b9d016 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Mon, 22 Sep 2025 15:23:19 -0400 Subject: [PATCH 3/3] don't forget to unset the conda_prefix --- cmd/dbc/install_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/dbc/install_test.go b/cmd/dbc/install_test.go index a4b240d5..45eab756 100644 --- a/cmd/dbc/install_test.go +++ b/cmd/dbc/install_test.go @@ -151,6 +151,8 @@ func (suite *SubcommandTestSuite) TestInstallEnvironmentPrecedence() { GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg}) suite.runCmd(m) suite.FileExists(filepath.Join(conda_path, "etc", "adbc", "drivers", "test-driver-1.toml")) + + os.Unsetenv("CONDA_PREFIX") } func (suite *SubcommandTestSuite) TestInstallCondaPrefix() {