Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_ensure_a_list():
# No data is empty list
assert ensure_a_list(None) == []
# Sequence types is only converted
assert ensure_a_list([1, 2]) == [1, 2]
assert ensure_a_list((1, 2)) == [1, 2]
assert ensure_a_list({1, 2}) == [1, 2]
# A string is trimmed_splitted
assert ensure_a_list("ab.toml") == ["ab.toml"]
assert ensure_a_list("ab.toml,cd.toml") == ["ab.toml", "cd.toml"]
assert ensure_a_list("ab.toml;cd.toml") == ["ab.toml", "cd.toml"]
# other types get wrapped in a list
assert ensure_a_list(1) == [1]
def test_ensure_a_list():
# No data is empty list
assert ensure_a_list(None) == []
# Sequence types is only converted
assert ensure_a_list([1, 2]) == [1, 2]
assert ensure_a_list((1, 2)) == [1, 2]
assert ensure_a_list({1, 2}) == [1, 2]
# A string is trimmed_splitted
assert ensure_a_list("ab.toml") == ["ab.toml"]
assert ensure_a_list("ab.toml,cd.toml") == ["ab.toml", "cd.toml"]
assert ensure_a_list("ab.toml;cd.toml") == ["ab.toml", "cd.toml"]
# other types get wrapped in a list
assert ensure_a_list(1) == [1]
def test_ensure_a_list():
# No data is empty list
assert ensure_a_list(None) == []
# Sequence types is only converted
assert ensure_a_list([1, 2]) == [1, 2]
assert ensure_a_list((1, 2)) == [1, 2]
assert ensure_a_list({1, 2}) == [1, 2]
# A string is trimmed_splitted
assert ensure_a_list("ab.toml") == ["ab.toml"]
assert ensure_a_list("ab.toml,cd.toml") == ["ab.toml", "cd.toml"]
assert ensure_a_list("ab.toml;cd.toml") == ["ab.toml", "cd.toml"]
# other types get wrapped in a list
assert ensure_a_list(1) == [1]
def test_ensure_a_list():
# No data is empty list
assert ensure_a_list(None) == []
# Sequence types is only converted
assert ensure_a_list([1, 2]) == [1, 2]
assert ensure_a_list((1, 2)) == [1, 2]
assert ensure_a_list({1, 2}) == [1, 2]
# A string is trimmed_splitted
assert ensure_a_list("ab.toml") == ["ab.toml"]
assert ensure_a_list("ab.toml,cd.toml") == ["ab.toml", "cd.toml"]
assert ensure_a_list("ab.toml;cd.toml") == ["ab.toml", "cd.toml"]
# other types get wrapped in a list
assert ensure_a_list(1) == [1]
def load_includes(self, env, silent, key):
"""Do we have any nested includes we need to process?"""
includes = self.get("DYNACONF_INCLUDE", [])
includes.extend(ensure_a_list(self.get("INCLUDES_FOR_DYNACONF")))
if includes:
self.logger.debug("Processing includes %s", includes)
self.load_file(path=includes, env=env, silent=silent, key=key)
# ensure env vars are the last thing loaded after all includes
last_loader = self.loaders and self.loaders[-1]
if last_loader and last_loader == env_loader:
last_loader.load(self, env, silent, key)
def load_file(self, path=None, env=None, silent=True, key=None):
"""Programmatically load files from ``path``.
:param path: A single filename or a file list
:param env: Which env to load from file (default current_env)
:param silent: Should raise errors?
:param key: Load a single key?
"""
env = (env or self.current_env).upper()
files = ensure_a_list(path)
if files:
self.logger.debug("Got %s files to process", files)
already_loaded = set()
for _filename in files:
self.logger.debug("Processing file %s", _filename)
if py_loader.try_to_load_from_py_module_name(
obj=self, name=_filename, silent=True
):
# if it was possible to load from module name
# continue the loop.
continue
filepath = os.path.join(
self._root_path or os.getcwd(), _filename
)
obj, settings_module=None, env=None, silent=True, key=None, filename=None
):
"""Loads from defined settings module
:param obj: A dynaconf instance
:param settings_module: A path or a list of paths e.g settings.toml
:param env: Env to look for data defaults: development
:param silent: Boolean to raise loading errors
:param key: Load a single key if provided
:param filename: optional filename to override the settings_module
"""
if filename is None:
settings_module = settings_module or obj.settings_module
if not settings_module: # pragma: no cover
return
files = ensure_a_list(settings_module)
else:
files = ensure_a_list(filename)
files.extend(ensure_a_list(obj.get("SECRETS_FOR_DYNACONF", None)))
found_files = []
modules_names = []
for item in files:
item = str(item) # Ensure str in case of LocalPath/Path is passed.
if item.endswith(ct.ALL_EXTENSIONS + (".py",)):
p_root = obj._root_path or (
os.path.dirname(found_files[0]) if found_files else None
)
found = obj.find_file(item, project_root=p_root)
if found:
found_files.append(found)
def load(self, filename=None, key=None, silent=True):
"""
Reads and loads in to `self.obj` a single key or all keys from source
:param filename: Optional filename to load
:param key: if provided load a single key
:param silent: if load erros should be silenced
"""
filename = filename or self.obj.get(self.identifier.upper())
if not filename:
return
if not isinstance(filename, (list, tuple)):
split_files = ensure_a_list(filename)
if all([f.endswith(self.extensions) for f in split_files]): # noqa
files = split_files # it is a ['file.ext', ...]
else: # it is a single config as string
files = [filename]
else: # it is already a list/tuple
files = filename
self.obj._loaded_files.extend(files)
env_list = build_env_list(self.obj, self.env)
# load all envs
self._read(files, env_list, silent, key)