Passed
Push — master ( 268f0c...dcff62 )
by russianidiot
01:09
created

jinja2stdout()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
dl 0
loc 13
rs 9.4285
1
#!/usr/bin/env python
2
import os
3
import jinja2
4
5
# usage: python -m jinja2stdout.module path
6
7
# 1) python -m module (running module)
8
#   known-issues: setup.py 'py_modules' requires 'package_dir' dict (not works with setup.cfg)
9
# 2) python -m package.module  (running package)
10
11
12
def get_env():
13
    pass
14
15
16
def jinja2stdout(path, searchpath=[]):
17
    if not searchpath:
18
        searchpath = [os.path.dirname(path)]
19
    extensions = ["jinja2.ext.do", 'jinja2.ext.autoescape', 'jinja2.ext.with_']
20
    env = jinja2.Environment(
21
        loader=jinja2.FileSystemLoader(searchpath),
22
        auto_reload=False,
23
        cache_size=-1,
24
        extensions=extensions
25
    )
26
    env.globals.update(os.environ)  # environment variables
27
    tmpl = env.get_template(path)
28
    return tmpl.render()
29