# HG changeset patch # User Franz Glasner # Date 1461061335 -7200 # Node ID 0e9f1f875ab0d0be3df3485d6f34f7b064344f01 # Parent d6e69d108a354140707d68bfee75998377cff8b2 A new PY variable namespace with some variables about the Python implementation and version diff -r d6e69d108a35 -r 0e9f1f875ab0 configmix/variables.py --- 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 }