Skip to content

Commit

Permalink
Merge pull request #58 from guardrails-ai/dtam/fix_config_path_none_h…
Browse files Browse the repository at this point in the history
…andling

pull default config from where were running the start command from
  • Loading branch information
CalebCourier authored Jul 16, 2024
2 parents c33f718 + 3908ef4 commit 9696713
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ open-api-spec.yml
requirements-lock-old.txt
opensearch
build
*.egg-info
*.egg-info
config.py
3 changes: 1 addition & 2 deletions guardrails_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def __call__(self, environ, start_response):


def register_config(config: Optional[str] = None):
default_config_file = os.path.join(os.path.dirname(__file__), "config.py")

default_config_file = os.path.join(os.getcwd(), "./config.py")
config_file = config or default_config_file
config_file_path = os.path.abspath(config_file)
if os.path.isfile(config_file_path):
Expand Down
6 changes: 3 additions & 3 deletions guardrails_api/utils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import os

def valid_configuration(config: Optional[str]=""):
default_config_file = os.path.join(os.path.dirname(__file__), "config.py")
default_config_file = os.path.join(os.getcwd(), "./config.py")

config_file_path = os.path.abspath(config)
default_config_file_path = os.path.abspath(default_config_file)
# If config.py is not present and
# if a config filepath is not passed and
# if postgres is not there (i.e. we’re using in-mem db)
# then raise ConfigurationError
has_default_config_file = os.path.isfile(default_config_file_path)
has_config_file = config != "" and os.path.isfile(config_file_path)

has_config_file = (config != "" and config is not None) and os.path.isfile(os.path.abspath(config))
if not has_default_config_file and not has_config_file and not postgres_is_enabled():
raise ConfigurationError("Can not start. Configuration not provided and default"
" configuration not found and postgres is not enabled.")
Expand Down

0 comments on commit 9696713

Please sign in to comment.