Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/variables.py @ 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 | 3ee21f868440 |
| children | b42e9936df2d |
comparison
equal
deleted
inserted
replaced
| 42:d6e69d108a35 | 43:0e9f1f875ab0 |
|---|---|
| 33 if name == "cwd": | 33 if name == "cwd": |
| 34 return native_os_str_to_text(os.getcwd()) | 34 return native_os_str_to_text(os.getcwd()) |
| 35 raise KeyError("key %r not found in the namespace" % name) | 35 raise KeyError("key %r not found in the namespace" % name) |
| 36 | 36 |
| 37 | 37 |
| 38 def _pylookup(name, default=_MARKER): | |
| 39 """Lookup a Python specific variable""" | |
| 40 import platform | |
| 41 if name == "version": | |
| 42 return u(platform.python_version()) | |
| 43 elif name == "implementation": | |
| 44 return u(platform.python_implementation()) | |
| 45 elif name == "version_maj_min": | |
| 46 t = platform.python_version_tuple() | |
| 47 return u('.'.join(t[:2])) | |
| 48 elif name == "version_maj": | |
| 49 t = platform.python_version_tuple() | |
| 50 return u(t[0]) | |
| 51 else: | |
| 52 if default is _MARKER: | |
| 53 raise KeyError("variable %r not found in namespace PY" % name) | |
| 54 else: | |
| 55 return default | |
| 56 | |
| 57 | |
| 38 _varns_registry = { | 58 _varns_registry = { |
| 39 "ENV": _envlookup, | 59 "ENV": _envlookup, |
| 40 "OS": _oslookup | 60 "OS": _oslookup, |
| 61 "PY": _pylookup | |
| 41 } | 62 } |
| 42 | 63 |
| 43 | 64 |
| 44 def lookup_varns(name): | 65 def lookup_varns(name): |
| 45 return _varns_registry[_normalized(name)] | 66 return _varns_registry[_normalized(name)] |
