Skip to content

Commit

Permalink
FABulous: Extend .env default paths and update gitignore
Browse files Browse the repository at this point in the history
Extend default paths for .env files to common folders.

Add ".env" and "venv" to gitignore.

Signed-off-by: Jonas K. <[email protected]>
  • Loading branch information
EverythingElseWasAlreadyTaken committed Sep 30, 2024
1 parent e2f2e85 commit c8360bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
demo/
**/__pycache__
*.egg-info/
.venv
.venv
venv
.env

18 changes: 14 additions & 4 deletions FABulous/FABulous.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def setup_global_env_vars(args: argparse.Namespace) -> None:
logger.info(f"FAB_ROOT set to {fabulousRoot}")

# Load the .env file and make env variables available globally
fabDir = Path(os.getenv("FAB_ROOT"))
if args.globalDotEnv:
gde = Path(args.globalDotEnv)
if gde.is_file():
Expand All @@ -107,12 +108,15 @@ def setup_global_env_vars(args: argparse.Namespace) -> None:
logger.info(f"Load global .env file from {gde.joinpath('.env')}")
else:
logger.warning(f"No global .env file found at {gde}")
elif fabDir.joinpath(".env").exists() and fabDir.joinpath(".env").is_file():
load_dotenv(fabDir.joinpath(".env"))
logger.info(f"Loaded global .env file from {fabulousRoot}/.env")
elif (
Path(os.getenv("FAB_ROOT")).joinpath(".env").exists()
and Path(os.getenv("FAB_ROOT")).joinpath(".env").is_file()
fabDir.parent.joinpath(".env").exists()
and fabDir.parent.joinpath(".env").is_file()
):
load_dotenv(Path(os.getenv("FAB_ROOT")).joinpath(".env"))
logger.info(f"Loaded global .env file from {fabulousRoot}/.env")
load_dotenv(fabDir.parent.joinpath(".env"))
logger.info(f"Loaded global .env file from {fabDir.parent.joinpath('.env')}")
else:
logger.warning("No global .env file found")

Expand Down Expand Up @@ -141,6 +145,12 @@ def setup_project_env_vars(args: argparse.Namespace) -> None:
elif fabDir.joinpath(".env").exists() and fabDir.joinpath(".env").is_file():
load_dotenv(fabDir.joinpath(".env"))
logger.info(f"Loaded project .env file from {fabDir}/.env')")
elif (
fabDir.parent.joinpath(".env").exists()
and fabDir.parent.joinpath(".env").is_file()
):
load_dotenv(fabDir.parent.joinpath(".env"))
logger.info(f"Loaded project .env file from {fabDir.parent.joinpath('.env')}")
else:
logger.warning("No project .env file found")

Expand Down

0 comments on commit c8360bf

Please sign in to comment.