Skip to content

Commit b6df9cc

Browse files
committed
Implement upgrading built-in Python from 3.9 to 3.11
1 parent 8f79d83 commit b6df9cc

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

src/installer/stages/platformio-core.js

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,21 @@ export default class PlatformIOCoreStage extends BaseStage {
4848
throw new Error('PlatformIO Core has not been installed yet!');
4949
}
5050
}
51-
// check that PIO Core is installed and load its state an patch OS environ
51+
// check that PIO Core is installed
5252
await this.loadCoreState();
53+
54+
// check if outdated built-in Python
55+
if (await this.isBuiltinPythonOutdated()) {
56+
return false;
57+
}
58+
59+
// Setup `platformio` CLI globally for a Node.JS process
60+
if (this.params.useBuiltinPIOCore) {
61+
proc.extendOSEnvironPath('PLATFORMIO_PATH', [
62+
core.getEnvBinDir(),
63+
core.getEnvDir(),
64+
]);
65+
}
5366
this.status = BaseStage.STATUS_SUCCESSED;
5467
return true;
5568
}
@@ -86,16 +99,6 @@ export default class PlatformIOCoreStage extends BaseStage {
8699
console.info('PIO Core State', coreState);
87100
core.setCoreState(coreState);
88101
await fs.unlink(stateJSONPath); // cleanup
89-
90-
// Add PIO Core virtualenv to global PATH
91-
// Setup `platformio` CLI globally for a Node.JS process
92-
if (this.params.useBuiltinPIOCore) {
93-
proc.extendOSEnvironPath('PLATFORMIO_PATH', [
94-
core.getEnvBinDir(),
95-
core.getEnvDir(),
96-
]);
97-
}
98-
99102
return true;
100103
}
101104

@@ -106,6 +109,37 @@ export default class PlatformIOCoreStage extends BaseStage {
106109
);
107110
}
108111

112+
async isBuiltinPythonOutdated() {
113+
if (!this.params.useBuiltinPython) {
114+
return false;
115+
}
116+
const builtInPythonDir = PlatformIOCoreStage.getBuiltInPythonDir();
117+
const coreState = core.getCoreState();
118+
try {
119+
await fs.access(builtInPythonDir);
120+
if (!coreState.python_version.startsWith('3.9.')) {
121+
throw new Error('Not 3.9 Python in penv');
122+
}
123+
const pkgVersion = (
124+
await misc.loadJSON(path.join(builtInPythonDir, 'package.json'))
125+
).version;
126+
if (!pkgVersion.startsWith('1.309')) {
127+
throw new Error('Not 3.9 Python package');
128+
}
129+
} catch (err) {
130+
return false;
131+
}
132+
if ((coreState.system || '').startsWith('windows')) {
133+
try {
134+
await fs.unlink(path.join(builtInPythonDir, 'python.exe'));
135+
} catch (err) {
136+
return false;
137+
}
138+
}
139+
console.info('Upgrading built-in Python...');
140+
return true;
141+
}
142+
109143
async whereIsPython({ prompt = false } = {}) {
110144
let status = this.params.pythonPrompt.STATUS_TRY_AGAIN;
111145
this.configureBuiltInPython();

0 commit comments

Comments
 (0)