Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
eval: Add support for reading from a `.env` file (#29426)
Marshall Bowersa5405fcbd709
diff --git a/.gitignore b/.gitignoreindex 93508a6eb70..f340e14508a 100644--- a/.gitignore+++ b/.gitignore@@ -32,4 +32,5 @@ Packagesxcuserdata/# Don't commit any secrets to the repo.+.env.env.secret.tomldiff --git a/Cargo.lock b/Cargo.lockindex f06b8615918..5edd5eb8864 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4548,6 +4548,12 @@ dependencies = ["syn 2.0.100",]+[[package]]+name = "dotenv"+version = "0.15.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"+[[package]]name = "dotenvy"version = "0.15.7"@@ -4970,6 +4976,7 @@ dependencies = ["collections","context_server","dirs 5.0.1",+ "dotenv","env_logger 0.11.8","extension","fs",diff --git a/Cargo.toml b/Cargo.tomlindex d90a256a9c6..d9bbb0481d0 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -437,6 +437,7 @@ dashmap = "6.0"dap-types = { git = "https://github.com/zed-industries/dap-types", rev = "be69a016ba710191b9fdded28c8b042af4b617f7" }derive_more = "0.99.17"dirs = "4.0"+dotenv = "0.15.0"ec4rs = "1.1"emojis = "0.6.1"env_logger = "0.11"diff --git a/crates/eval/Cargo.toml b/crates/eval/Cargo.tomlindex 6c754bf7ff8..21d98167084 100644--- a/crates/eval/Cargo.toml+++ b/crates/eval/Cargo.toml@@ -19,6 +19,7 @@ client.workspace = truecollections.workspace = truecontext_server.workspace = truedirs = "5.0"+dotenv.workspace = trueenv_logger.workspace = trueextension.workspace = truefs.workspace = truediff --git a/crates/eval/README.md b/crates/eval/README.mdindex 75fe7265fcb..c1543734b00 100644--- a/crates/eval/README.md+++ b/crates/eval/README.md@@ -6,6 +6,8 @@ This eval assumes the working directory is the root of the repository. Run it wicargo run -p eval```+The eval will optionally read a `.env` file in `crates/eval` if you need it to set environment variables, such as API keys.+## Explorer ToolThe explorer tool generates a self-contained HTML view from one or more threaddiff --git a/crates/eval/src/eval.rs b/crates/eval/src/eval.rsindex dcc39592ed6..f3a9624553c 100644--- a/crates/eval/src/eval.rs+++ b/crates/eval/src/eval.rs@@ -34,9 +34,12 @@ use std::collections::VecDeque;use std::env;use std::path::{Path, PathBuf};use std::rc::Rc;-use std::sync::Arc;+use std::sync::{Arc, LazyLock};use util::ResultExt as _;+static CARGO_MANIFEST_DIR: LazyLock<PathBuf> =+ LazyLock::new(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")));+#[derive(Parser, Debug)]#[command(name = "eval", disable_version_flag = true)]struct Args {@@ -57,6 +60,8 @@ struct Args {}fn main() {+ dotenv::from_filename(CARGO_MANIFEST_DIR.join(".env")).ok();+env_logger::init();let system_id = ids::get_or_create_id(&ids::eval_system_id_path()).ok();