-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* only use semver types on Web. * fix compile
- Loading branch information
Showing
13 changed files
with
65 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/platform/pythonEnvironments/info/pythonVersion.node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Convert a Python version string. | ||
* | ||
* The supported formats are: | ||
* | ||
* * MAJOR.MINOR.MICRO-RELEASE_LEVEL | ||
* | ||
* (where RELEASE_LEVEL is one of {alpha,beta,candidate,final}) | ||
* | ||
* Everything else, including an empty string, results in `undefined`. | ||
*/ | ||
// Eventually we will want to also support the release serial | ||
// (e.g. beta1, candidate3) and maybe even release abbreviations | ||
|
||
import { SemVer } from 'semver'; | ||
import { PythonVersion } from './pythonVersion'; | ||
|
||
// (e.g. 3.9.2b1, 3.8.10rc3). | ||
export function parsePythonVersion(raw: string): PythonVersion | undefined { | ||
if (!raw || raw.trim().length === 0) { | ||
return; | ||
} | ||
const versionParts = (raw || '') | ||
.split('.') | ||
.map((item) => item.trim()) | ||
.filter((item) => item.length > 0) | ||
.filter((_, index) => index < 4); | ||
|
||
if (versionParts.length > 0 && versionParts[versionParts.length - 1].indexOf('-') > 0) { | ||
const lastPart = versionParts[versionParts.length - 1]; | ||
versionParts[versionParts.length - 1] = lastPart.split('-')[0].trim(); | ||
versionParts.push(lastPart.split('-')[1].trim()); | ||
} | ||
while (versionParts.length < 4) { | ||
versionParts.push(''); | ||
} | ||
// Exclude PII from `version_info` to ensure we don't send this up via telemetry. | ||
for (let index = 0; index < 3; index += 1) { | ||
versionParts[index] = /^\d+$/.test(versionParts[index]) ? versionParts[index] : '0'; | ||
} | ||
if (['alpha', 'beta', 'candidate', 'final'].indexOf(versionParts[3]) === -1) { | ||
versionParts.pop(); | ||
} | ||
const numberParts = `${versionParts[0]}.${versionParts[1]}.${versionParts[2]}`; | ||
const rawVersion = versionParts.length === 4 ? `${numberParts}-${versionParts[3]}` : numberParts; | ||
return new SemVer(rawVersion); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters