Mercurial > hgrepos > Python > libs > ConfigMix
changeset 43:0e9f1f875ab0
A new PY variable namespace with some variables about the Python implementation and version
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Tue, 19 Apr 2016 12:22:15 +0200 |
| parents | d6e69d108a35 |
| children | b42e9936df2d |
| files | configmix/variables.py |
| diffstat | 1 files changed, 22 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/configmix/variables.py Thu Apr 07 23:23:17 2016 +0200 +++ b/configmix/variables.py Tue Apr 19 12:22:15 2016 +0200 @@ -35,9 +35,30 @@ raise KeyError("key %r not found in the namespace" % name) +def _pylookup(name, default=_MARKER): + """Lookup a Python specific variable""" + import platform + if name == "version": + return u(platform.python_version()) + elif name == "implementation": + return u(platform.python_implementation()) + elif name == "version_maj_min": + t = platform.python_version_tuple() + return u('.'.join(t[:2])) + elif name == "version_maj": + t = platform.python_version_tuple() + return u(t[0]) + else: + if default is _MARKER: + raise KeyError("variable %r not found in namespace PY" % name) + else: + return default + + _varns_registry = { "ENV": _envlookup, - "OS": _oslookup + "OS": _oslookup, + "PY": _pylookup }
