From 61a4890ae4f2d1785229f665d6be23e4f74726c5 Mon Sep 17 00:00:00 2001 From: Anton Osika Date: Sun, 13 Aug 2023 11:12:40 +0200 Subject: [PATCH] Simplify env loading --- Makefile | 14 ++++---------- gpt_engineer/__init__.py | 1 - gpt_engineer/main.py | 11 ++--------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index a737269432..fc767855d7 100644 --- a/Makefile +++ b/Makefile @@ -34,35 +34,29 @@ create-venv: python -m venv venv #Defines a target named upgrade-pip. This target will upgrade pip to the latest version. -upgrade-pip: load-env +upgrade-pip: @echo -e "$(COLOR_CYAN)Upgrading pip...$(COLOR_RESET)" && \ source venv/bin/activate && \ pip install --upgrade pip >> /dev/null #Defines a target named install-dependencies. This target will install the dependencies. -install-dependencies: load-env +install-dependencies: @echo -e "$(COLOR_CYAN)Installing dependencies...$(COLOR_RESET)" && \ source venv/bin/activate && \ pip install -e . >> /dev/null #Defines a target named install-pre-commit. This target will install the pre-commit hooks. -install-pre-commit: load-env +install-pre-commit: @echo -e "$(COLOR_CYAN)Installing pre-commit hooks...$(COLOR_RESET)" && \ source venv/bin/activate && \ pre-commit install -#Defines a target named load-env. This target will load the environment variables from the .env file. -load-env: - @echo -e "$(COLOR_CYAN)Loading environment variables...$(COLOR_RESET)" && \ - source venv/bin/activate && \ - python -m dotenv load - #Defines a target named farewell. This target will print a farewell message. farewell: @echo -e "$(COLOR_GREEN)All done!$(COLOR_RESET)" #Defines a target named run. This target will run GPT Engineer on the folder with the given name, name was defined earlier in the Makefile. -run: load-env +run: @echo -e "$(COLOR_CYAN)Running GPT Engineer on $(COLOR_GREEN)$(name)$(COLOR_CYAN) folder...$(COLOR_RESET)" && \ source venv/bin/activate && \ gpt-engineer projects/$(name) diff --git a/gpt_engineer/__init__.py b/gpt_engineer/__init__.py index 8b13789179..e69de29bb2 100644 --- a/gpt_engineer/__init__.py +++ b/gpt_engineer/__init__.py @@ -1 +0,0 @@ - diff --git a/gpt_engineer/main.py b/gpt_engineer/main.py index 57cfa995c5..436cf71c39 100644 --- a/gpt_engineer/main.py +++ b/gpt_engineer/main.py @@ -1,10 +1,10 @@ import logging import os -from pathlib import Path from pathlib import Path import typer + from dotenv import load_dotenv from gpt_engineer.ai import AI, fallback_model @@ -15,17 +15,10 @@ app = typer.Typer() + def load_env_if_needed(): - """ - Check if API KEY env variable exist - If it doesn’t, call load_dotenv - """ if os.getenv("OPENAI_API_KEY") is None: load_dotenv() - # After attempting to load from .env, check again - if os.getenv("OPENAI_API_KEY") is None: - raise ValueError("Cannot run the program without OPENAI_API_KEY environment variable.\nPlease set it in your environment or in a .env file.") - @app.command()