MCPcopy Index your code
hub / github.com/ampproject/amphtml / checkPythonVersion

Function checkPythonVersion

build-system/common/check-package-manager.js:204–249  ·  view source on GitHub ↗

* Checks if the local version of python is 2.7 or 3

()

Source from the content-addressed store, hash-verified

202 * Checks if the local version of python is 2.7 or 3
203 */
204function checkPythonVersion() {
205 // Python 2.7 is EOL but still supported
206 // Python 3.6+ are still supported
207 // https://devguide.python.org/#status-of-python-branches
208 const recommendedVersion = '2.7 or 3.6+';
209 const recommendedVersionRegex = /^2\.7|^3\.(?:[6-9]|1\d)/;
210
211 // Python2 prints its version to stderr (fixed in Python 3.4)
212 // See: https://bugs.python.org/issue18338
213 const pythonVersionResult = getStdout('python --version 2>&1').trim();
214 const pythonVersion = pythonVersionResult.match(/Python (.*?)$/);
215 if (pythonVersion && pythonVersion.length == 2) {
216 const versionNumber = pythonVersion[1];
217 if (recommendedVersionRegex.test(versionNumber)) {
218 console.log(
219 green('Detected'),
220 cyan('python'),
221 green('version'),
222 cyan(versionNumber) + green('.')
223 );
224 } else {
225 console.log(
226 yellow('WARNING: Detected python version'),
227 cyan(versionNumber) +
228 yellow('. Recommended version for AMP development is'),
229 cyan(recommendedVersion) + yellow('.')
230 );
231 console.log(
232 yellow('⤷ To fix this, install a supported version from'),
233 cyan('https://www.python.org/downloads/') + yellow('.')
234 );
235 }
236 } else {
237 console.log(
238 yellow('WARNING: Could not determine the local version of python.')
239 );
240 console.log(
241 yellow('⤷ To fix this, make sure'),
242 cyan('python'),
243 yellow('is in your'),
244 cyan('PATH'),
245 yellow('and is version'),
246 cyan(recommendedVersion) + yellow('.')
247 );
248 }
249}
250
251/**
252 * Runs checks for the package manager and tooling being used.

Callers 1

mainFunction · 0.85

Calls 6

getStdoutFunction · 0.85
greenFunction · 0.85
cyanFunction · 0.85
yellowFunction · 0.85
testMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected