Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/chameleon/config.py : 76%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import os
2import logging
4log = logging.getLogger('chameleon.config')
5environment = dict(
6 (k[10:], v) for (k, v) in (
7 ((j.lower(), x) for (j, x) in os.environ.items()))
8 if k.startswith('chameleon_')
9)
11# Define which values are read as true
12TRUE = ('y', 'yes', 't', 'true', 'on', '1')
14# If eager parsing is enabled, templates are parsed upon
15# instantiation, rather than when first called upon; this mode is
16# useful for verifying validity of templates across a project
17EAGER_PARSING = environment.pop('eager', 'false')
18EAGER_PARSING = EAGER_PARSING.lower() in TRUE
20# Debug mode is mostly useful for debugging the template engine
21# itself. When enabled, generated source code is written to disk to
22# ease step-debugging and some log levels are lowered to increase
23# output. Also, the generated source code is available in the
24# ``source`` attribute of the template instance if compilation
25# succeeded.
26DEBUG_MODE = environment.pop('debug', 'false')
27DEBUG_MODE = DEBUG_MODE.lower() in TRUE
29# If a cache directory is specified, template source code will be
30# persisted on disk and reloaded between sessions
31path = environment.pop('cache', None)
32if path is not None:
33 CACHE_DIRECTORY = os.path.abspath(path)
34 if not os.path.exists(CACHE_DIRECTORY):
35 raise ValueError(
36 "Cache directory does not exist: %s." % CACHE_DIRECTORY
37 )
38 log.info("directory cache: %s." % CACHE_DIRECTORY)
39else:
40 CACHE_DIRECTORY = None
42# When auto-reload is enabled, templates are reloaded on file change.
43AUTO_RELOAD = environment.pop('reload', 'false')
44AUTO_RELOAD = AUTO_RELOAD.lower() in TRUE
46for key in environment:
47 log.warning(
48 "unknown environment variable set: \"CHAMELEON_%s\"." % key.upper()
49 )
51# This is the slice length of the expression displayed in the
52# formatted exception string
53SOURCE_EXPRESSION_MARKER_LENGTH = 60