MCPcopy Create free account
hub / github.com/actions/setup-python / getVersionInputFromPipfileFile

Function getVersionInputFromPipfileFile

src/utils.ts:355–387  ·  view source on GitHub ↗
(versionFile: string)

Source from the content-addressed store, hash-verified

353 * Python version extracted from the Pipfile file.
354 */
355export function getVersionInputFromPipfileFile(versionFile: string): string[] {
356 core.debug(`Trying to resolve version from ${versionFile}`);
357
358 if (!fs.existsSync(versionFile)) {
359 core.warning(`File ${versionFile} does not exist.`);
360 return [];
361 }
362 let pipfileFile = fs.readFileSync(versionFile, 'utf8');
363 // Normalize the line endings in the pipfileFile
364 pipfileFile = pipfileFile.replace(/\r\n/g, '\n');
365
366 const pipfileConfig = toml.parse(pipfileFile);
367 const keys = ['requires'];
368
369 if (!('requires' in pipfileConfig)) {
370 core.warning(`No Python version found in ${versionFile}`);
371 return [];
372 }
373 if ('python_full_version' in (pipfileConfig['requires'] as toml.JsonMap)) {
374 // specifies a full python version
375 keys.push('python_full_version');
376 } else {
377 keys.push('python_version');
378 }
379 const versions = [];
380 const version = extractValue(pipfileConfig, keys);
381 if (version !== undefined) {
382 versions.push(version);
383 }
384
385 core.info(`Extracted ${versions} from ${versionFile}`);
386 return versions;
387}
388
389/**
390 * Python version extracted from a plain, .tool-versions, Pipfile or TOML file.

Callers 1

getVersionInputFromFileFunction · 0.85

Calls 1

extractValueFunction · 0.85

Tested by

no test coverage detected