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

pull default config from where were running the start command from #58

Merged
merged 2 commits into from
Jul 16, 2024
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
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 != 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
Loading