Skip to content

Commit

Permalink
Simplify env loading
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOsika committed Aug 13, 2023
1 parent 5d6542e commit 61a4890
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion gpt_engineer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

11 changes: 2 additions & 9 deletions gpt_engineer/main.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 61a4890

Please sign in to comment.