Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load dotenv before config import #370

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 6 additions & 3 deletions secator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

import requests
import yaml
from dotenv import find_dotenv, load_dotenv
from dotmap import DotMap
from pydantic import AfterValidator, BaseModel, model_validator, ValidationError

from secator.rich import console, console_stdout

load_dotenv(find_dotenv(usecwd=True), override=False)

Directory = Annotated[Path, AfterValidator(lambda v: v.expanduser())]
StrExpandHome = Annotated[str, AfterValidator(lambda v: v.replace('~', str(Path.home())))]

Expand Down Expand Up @@ -245,9 +248,9 @@ def set(self, key, value, set_partial=True):
value = float(value)
elif isinstance(existing_value, Path):
value = Path(value)
except ValueError as e:
from secator.utils import debug
debug(f'Could not cast value {value} to expected type {type(existing_value).__name__}: {str(e)}', sub='config')
except ValueError:
# from secator.utils import debug
# debug(f'Could not cast value {value} to expected type {type(existing_value).__name__}: {str(e)}', sub='config')
pass
finally:
target[final_key] = value
Expand Down
2 changes: 0 additions & 2 deletions secator/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import os

from dotenv import find_dotenv, load_dotenv
from importlib.metadata import version

from secator.config import CONFIG, ROOT_FOLDER

load_dotenv(find_dotenv(usecwd=True), override=False)

# Globals
VERSION = version('secator')
Expand Down
Loading