Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

silent option added to 'from_pyfile' to mirror 'from_envvar'.

  • Loading branch information...
commit 5cc40f4728d5b5356cf49b7dfaa2b130e0b0aedf 1 parent b3fc9eb
@akavlie akavlie authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 flask/
11 flask/
@@ -83,13 +83,13 @@ def __init__(self, root_path, defaults=None):
def from_envvar(self, variable_name, silent=False):
"""Loads a configuration from an environment variable pointing to
- a configuration file. This basically is just a shortcut with nicer
+ a configuration file. This is basically just a shortcut with nicer
error messages for this line of code::
:param variable_name: name of the environment variable
- :param silent: set to `True` if you want silent failing for missing
+ :param silent: set to `True` if you want silent to fail for missing
adamrt added a note

This is worse.

akavlie added a note


@kennethreitz Collaborator

if you want to silence missing failures ?

akavlie added a note

Oh right, I took "silent" to be a reference to the flag in this case. I'll fix it.
"silent failure" would be best here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
:return: bool. `True` if able to load config, `False` otherwise.
@@ -105,7 +105,7 @@ def from_envvar(self, variable_name, silent=False):
return True
- def from_pyfile(self, filename):
+ def from_pyfile(self, filename, silent=False):
"""Updates the values in the config from a Python file. This function
behaves as if the file was imported as module with the
:meth:`from_object` function.
@@ -113,6 +113,8 @@ def from_pyfile(self, filename):
:param filename: the filename of the config. This can either be an
absolute filename or a filename relative to the
root path.
+ :param silent: set to `True` if you want silent to fail for missing
+ files.
filename = os.path.join(self.root_path, filename)
d = imp.new_module('config')
@@ -120,9 +122,12 @@ def from_pyfile(self, filename):
execfile(filename, d.__dict__)
except IOError, e:
+ if silent and e.errno in (errno.ENOENT, errno.EISDIR):
+ return False
e.strerror = 'Unable to load configuration file (%s)' % e.strerror
+ return True
def from_object(self, obj):
"""Updates the values from the given object. An object can be of one
Please sign in to comment.
Something went wrong with that request. Please try again.