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 Config loading code #294

Merged
merged 5 commits into from Aug 27, 2018
Merged

Fix Config loading code #294

merged 5 commits into from Aug 27, 2018

Conversation

paramsingh
Copy link
Collaborator

Action points:

  • remove config_path argument
  • Remove create_app_with_configuration method, which is no longer used independently
  • standardaise on consul_config.py or config.py in both apps
  • only use print in production
  • correctly pretty-print config in production

Copy link
Collaborator

@alastair alastair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner, thanks!

return app
if deploy_env:
print('Config file loaded!')
pprint(dict(app.config))


def create_app(debug=None, config_path=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have any code that calls create_app(config_path=...). Can we remove this argument?

return app
if not os.path.exists(config_file):
print("No config file generated. Retried %d times, exiting." % CONSUL_CONFIG_FILE_RETRY_COUNT)
sys.exit(-1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.config.from_pyfile will fail anyway if the file doesn't exist. Does that make the sys.exit unneeded?

def load_config(app):
"""Load configuration file for specified Flask app"""
config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "config.py")
for _ in range(CONSUL_CONFIG_FILE_RETRY_COUNT):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in development I'd like it much more to have a failure message immediately if I forget to copy config.py.example to config.py rather than have to wait 10 seconds for the message to appear. Is there a way that we can support both of these cases?

Also, remove extraneous parameters and sys.exit
if deploy_env:
for _ in range(CONSUL_CONFIG_FILE_RETRY_COUNT):
if not os.path.exists(config_file):
time.sleep(1)

if not os.path.exists(config_file):
print("No config file generated. Retried %d times, exiting." % CONSUL_CONFIG_FILE_RETRY_COUNT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is not strictly true in development any more. Do we care?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could fix it by indenting one level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on it.

Copy link
Collaborator

@alastair alastair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants