Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions cognite/extractorutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from types import TracebackType
from typing import Any, Generic, TypeVar

from dotenv import find_dotenv, load_dotenv
from dotenv import load_dotenv

from cognite.client import CogniteClient
from cognite.client.data_classes import ExtractionPipeline, ExtractionPipelineRun
Expand Down Expand Up @@ -250,12 +250,11 @@ def __enter__(self) -> "Extractor":

if str(os.getenv("COGNITE_FUNCTION_RUNTIME", False)).lower() != "true":
# Environment Variables
env_file_path = find_dotenv(usecwd=True)
if env_file_path:
load_dotenv(dotenv_path=env_file_path, override=True)
dotenv_message = f"Successfully ingested environment variables from {env_file_path}"
env_file_found = load_dotenv(dotenv_path="./.env", override=True)
if env_file_found:
dotenv_message = "Successfully ingested environment variables from './.env'"
else:
dotenv_message = "No .env file found"
dotenv_message = "No .env file found at {Path.cwd() / '.env'}"
else:
dotenv_message = "No .env file imported when using Cognite Functions"

Expand Down
8 changes: 5 additions & 3 deletions cognite/extractorutils/configtools/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, config: dict | None):
self.client: SecretClient | None = None

def _init_client(self) -> None:
from dotenv import find_dotenv, load_dotenv
from dotenv import load_dotenv

if not self.config:
raise InvalidConfigError(
Expand Down Expand Up @@ -98,8 +98,10 @@ def _init_client(self) -> None:

_logger.info("Using Azure ClientSecret credentials to access KeyVault")

dotenv_path = find_dotenv(usecwd=True)
load_dotenv(dotenv_path=dotenv_path, override=True)
env_file_found = load_dotenv("./.env", override=True)

if not env_file_found:
_logger.info(f"Local environment file not found at {Path.cwd() / '.env'}")

if all(param in self.config for param in auth_parameters):
tenant_id = os.path.expandvars(self.config.get("tenant-id", None))
Expand Down