|
3 | 3 | import python
|
4 | 4 |
|
5 | 5 | /** the Python major version number */
|
6 |
| -int major_version() { |
7 |
| - explicit_major_version(result) |
8 |
| - or |
9 |
| - not explicit_major_version(_) and |
10 |
| - /* If there is more than one version, prefer 2 for backwards compatibility */ |
11 |
| - (if py_flags_versioned("version.major", "2", "2") then result = 2 else result = 3) |
12 |
| -} |
| 6 | +int major_version() { full_python_analysis_version(result, _, _) } |
13 | 7 |
|
14 | 8 | /** the Python minor version number */
|
15 |
| -int minor_version() { |
16 |
| - exists(string v | py_flags_versioned("version.minor", v, major_version().toString()) | |
17 |
| - result = v.toInt() |
18 |
| - ) |
19 |
| -} |
| 9 | +int minor_version() { full_python_analysis_version(_, result, _) } |
20 | 10 |
|
21 | 11 | /** the Python micro version number */
|
22 |
| -int micro_version() { |
23 |
| - exists(string v | py_flags_versioned("version.micro", v, major_version().toString()) | |
24 |
| - result = v.toInt() |
25 |
| - ) |
| 12 | +int micro_version() { full_python_analysis_version(_, _, result) } |
| 13 | + |
| 14 | +/** Gets the latest supported minor version for the given major version. */ |
| 15 | +private int latest_supported_minor_version(int major) { |
| 16 | + major = 2 and result = 7 |
| 17 | + or |
| 18 | + major = 3 and result = 11 |
26 | 19 | }
|
27 | 20 |
|
28 |
| -private predicate explicit_major_version(int v) { |
29 |
| - exists(string version | py_flags_versioned("language.version", version, _) | |
30 |
| - version.charAt(0) = "2" and v = 2 |
31 |
| - or |
32 |
| - version.charAt(0) = "3" and v = 3 |
| 21 | +private predicate full_python_analysis_version(int major, int minor, int micro) { |
| 22 | + exists(string version_string | py_flags_versioned("language.version", version_string, _) | |
| 23 | + major = version_string.regexpFind("\\d+", 0, _).toInt() and |
| 24 | + ( |
| 25 | + minor = version_string.regexpFind("\\d+", 1, _).toInt() |
| 26 | + or |
| 27 | + not exists(version_string.regexpFind("\\d+", 1, _)) and |
| 28 | + minor = latest_supported_minor_version(major) |
| 29 | + ) and |
| 30 | + ( |
| 31 | + micro = version_string.regexpFind("\\d+", 2, _).toInt() |
| 32 | + or |
| 33 | + not exists(version_string.regexpFind("\\d+", 2, _)) and micro = 0 |
| 34 | + ) |
33 | 35 | )
|
34 | 36 | }
|
0 commit comments