From c3c6d281337d3c78b283304785e31f0e05cff6fc Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Tue, 24 Nov 2015 13:32:27 +0100 Subject: [PATCH] Configuration by environment variable is optional --- doc/install.rst | 2 +- mutalyzer/config/__init__.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/doc/install.rst b/doc/install.rst index dda788a0..b2b1f176 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -42,7 +42,7 @@ The impatient can run Mutalyzer without a database server and more such nonsense with the following steps:: $ pip install -r requirements.txt - $ MUTALYZER_SETTINGS=/dev/null python -m mutalyzer.entrypoints.website + $ python -m mutalyzer.entrypoints.website This starts the website frontend on the reported port using an in-memory SQLite database. diff --git a/mutalyzer/config/__init__.py b/mutalyzer/config/__init__.py index 462a490e..13c03443 100644 --- a/mutalyzer/config/__init__.py +++ b/mutalyzer/config/__init__.py @@ -16,6 +16,8 @@ from __future__ import unicode_literals import collections import os +import warnings + import flask.config @@ -65,10 +67,15 @@ class LazySettings(util.LazyObject): self._wrapped = Settings() self._wrapped.from_object('mutalyzer.config.default_settings') if from_environment: - # Todo: We crash if the environment variable is not set. Perhaps - # it is more user-friendly if we fall back on ./settings.py or - # ~/mutalyzer_settings.py or something if it exists. - self._wrapped.from_envvar(ENVIRONMENT_VARIABLE) + if ENVIRONMENT_VARIABLE in os.environ: + self._wrapped.from_envvar(ENVIRONMENT_VARIABLE) + else: + warnings.warn('The environment variable \'%s\' is not set ' + 'and as such default configuration settings ' + 'are used. Set this variable and make it point ' + 'to a configuration file to customize ' + 'configuration.' % ENVIRONMENT_VARIABLE, + RuntimeWarning) def configure(self, settings): """ -- GitLab