Skip to content

Commit f1085bb

Browse files
committed
fix: load .env from current working directory, not package location
load_dotenv() without arguments searches from the calling module's directory. When zad is installed via uv tool install, this means it looks in the package install path instead of the user's project directory. Fixed by passing dotenv_path='.env' which resolves from CWD. This was the root cause of -p being "required" even after config init had saved ZAD_PROJECT_ID to .env.
1 parent 7bc7c81 commit f1085bb

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/zad_cli/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@ def main() -> None:
112112
"""CLI entrypoint."""
113113
from dotenv import load_dotenv
114114

115-
load_dotenv()
115+
load_dotenv(dotenv_path=".env")
116116
app()

tests/test_cli.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,21 @@ def test_global_flag_after_subcommand():
194194
)
195195
err = _strip_ansi(result.stderr)
196196
assert "No such option" not in err
197+
198+
199+
def test_dotenv_loaded_from_cwd(tmp_path):
200+
"""'.env' in the user's CWD should be loaded even when zad is installed elsewhere."""
201+
env_file = tmp_path / ".env"
202+
env_file.write_text("ZAD_API_KEY=test-key-from-cwd\nZAD_PROJECT_ID=test-proj\n")
203+
# Remove ZAD vars from env so load_dotenv can set them from .env
204+
clean_env = {k: v for k, v in _PLAIN_ENV.items() if not k.startswith("ZAD_")}
205+
result = subprocess.run(
206+
[sys.executable, "-m", "zad_cli", "project", "status"],
207+
capture_output=True,
208+
text=True,
209+
cwd=str(tmp_path),
210+
env=clean_env,
211+
)
212+
err = _strip_ansi(result.stderr)
213+
# Should NOT complain about missing project - it should read it from .env
214+
assert "project is required" not in err

0 commit comments

Comments
 (0)