Returns a parsed version of Python's sys.version as tuple (name, version, branch, revision, buildno, builddate, compiler) referring to the Python implementation name, version, branch, revision, build number, build date/time as string and the compiler identification s
(sys_version=None)
| 1126 | _sys_version_cache = {} |
| 1127 | |
| 1128 | def _sys_version(sys_version=None): |
| 1129 | |
| 1130 | """ Returns a parsed version of Python's sys.version as tuple |
| 1131 | (name, version, branch, revision, buildno, builddate, compiler) |
| 1132 | referring to the Python implementation name, version, branch, |
| 1133 | revision, build number, build date/time as string and the compiler |
| 1134 | identification string. |
| 1135 | |
| 1136 | Note that unlike the Python sys.version, the returned value |
| 1137 | for the Python version will always include the patchlevel (it |
| 1138 | defaults to '.0'). |
| 1139 | |
| 1140 | The function returns empty strings for tuple entries that |
| 1141 | cannot be determined. |
| 1142 | |
| 1143 | sys_version may be given to parse an alternative version |
| 1144 | string, e.g. if the version was read from a different Python |
| 1145 | interpreter. |
| 1146 | |
| 1147 | """ |
| 1148 | # Get the Python version |
| 1149 | if sys_version is None: |
| 1150 | sys_version = sys.version |
| 1151 | |
| 1152 | # Try the cache first |
| 1153 | result = _sys_version_cache.get(sys_version, None) |
| 1154 | if result is not None: |
| 1155 | return result |
| 1156 | |
| 1157 | if sys.platform.startswith('java'): |
| 1158 | # Jython |
| 1159 | jython_sys_version_parser = re.compile( |
| 1160 | r'([\w.+]+)\s*' # "version<space>" |
| 1161 | r'\(#?([^,]+)' # "(#buildno" |
| 1162 | r'(?:,\s*([\w ]*)' # ", builddate" |
| 1163 | r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>" |
| 1164 | r'\[([^\]]+)\]?', re.ASCII) # "[compiler]" |
| 1165 | name = 'Jython' |
| 1166 | match = jython_sys_version_parser.match(sys_version) |
| 1167 | if match is None: |
| 1168 | raise ValueError( |
| 1169 | 'failed to parse Jython sys.version: %s' % |
| 1170 | repr(sys_version)) |
| 1171 | version, buildno, builddate, buildtime, _ = match.groups() |
| 1172 | if builddate is None: |
| 1173 | builddate = '' |
| 1174 | compiler = sys.platform |
| 1175 | |
| 1176 | elif "PyPy" in sys_version: |
| 1177 | # PyPy |
| 1178 | pypy_sys_version_parser = re.compile( |
| 1179 | r'([\w.+]+)\s*' |
| 1180 | r'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*' |
| 1181 | r'\[PyPy [^\]]+\]?') |
| 1182 | |
| 1183 | name = "PyPy" |
| 1184 | match = pypy_sys_version_parser.match(sys_version) |
| 1185 | if match is None: |
no test coverage detected