Skip to content

Commit 1c97928

Browse files
committed
Fix style issues and build
Build the project using `npm run build` and run prettier using `npm run format`
1 parent ce7a9c1 commit 1c97928

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

__tests__/utils.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ jest.mock('@actions/core');
1212

1313
describe('parsePythonVersionFile', () => {
1414
it('handle the content of a .python-version file', () => {
15-
expect(parsePythonVersionFile('3.6')).toEqual('3.6')
15+
expect(parsePythonVersionFile('3.6')).toEqual('3.6');
1616
});
1717

1818
it('trims extra spaces at the end of the content', () => {
19-
expect(parsePythonVersionFile('3.7 ')).toEqual('3.7')
19+
expect(parsePythonVersionFile('3.7 ')).toEqual('3.7');
2020
});
2121

2222
it('parses correctly the content of .tool-version files', () => {
23-
expect(parsePythonVersionFile('python 3.7')).toEqual('3.7')
23+
expect(parsePythonVersionFile('python 3.7')).toEqual('3.7');
2424
});
2525
});
2626

dist/setup/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66921,7 +66921,7 @@ function resolveVersionInput() {
6692166921
if (!fs_1.default.existsSync(versionFile)) {
6692266922
throw new Error(`The specified python version file at: ${versionFile} doesn't exist.`);
6692366923
}
66924-
const version = fs_1.default.readFileSync(versionFile, 'utf8');
66924+
const version = utils_1.parsePythonVersionFile(fs_1.default.readFileSync(versionFile, 'utf8'));
6692566925
core.info(`Resolved ${versionFile} as ${version}`);
6692666926
return [version];
6692766927
}
@@ -67024,7 +67024,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6702467024
return (mod && mod.__esModule) ? mod : { "default": mod };
6702567025
};
6702667026
Object.defineProperty(exports, "__esModule", ({ value: true }));
67027-
exports.getOSInfo = exports.getLinuxInfo = exports.logWarning = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0;
67027+
exports.getOSInfo = exports.getLinuxInfo = exports.logWarning = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.parsePythonVersionFile = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0;
6702867028
const cache = __importStar(__nccwpck_require__(7799));
6702967029
const core = __importStar(__nccwpck_require__(2186));
6703067030
const fs_1 = __importDefault(__nccwpck_require__(7147));
@@ -67037,6 +67037,20 @@ exports.IS_MAC = process.platform === 'darwin';
6703767037
exports.WINDOWS_ARCHS = ['x86', 'x64'];
6703867038
exports.WINDOWS_PLATFORMS = ['win32', 'win64'];
6703967039
const PYPY_VERSION_FILE = 'PYPY_VERSION';
67040+
function parsePythonVersionFile(contents) {
67041+
var _a;
67042+
let pythonVersion;
67043+
// Try to find the version in tool-version file
67044+
const found = contents.match(/^(?:python\s+)?v?(?<version>[^\s]+)$/m);
67045+
pythonVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version;
67046+
// In the case of an unknown format,
67047+
// return as is and evaluate the version separately.
67048+
if (!pythonVersion) {
67049+
pythonVersion = contents.trim();
67050+
}
67051+
return pythonVersion;
67052+
}
67053+
exports.parsePythonVersionFile = parsePythonVersionFile;
6704067054
/** create Symlinks for downloaded PyPy
6704167055
* It should be executed only for downloaded versions in runtime, because
6704267056
* toolcache versions have this setup.

docs/advanced-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ jobs:
241241
The python-version-file input accepts a path to a file containing the version of Python to be used by a project, for example .python-version, or .tool-versions.
242242
If both the python-version and the python-version-file inputs are provided then the python-version input is used.
243243

244-
> In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority.
244+
>In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority.
245245

246246
```yaml
247247
steps:

src/setup-python.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import * as path from 'path';
55
import * as os from 'os';
66
import fs from 'fs';
77
import {getCacheDistributor} from './cache-distributions/cache-factory';
8-
import {parsePythonVersionFile, isCacheFeatureAvailable, logWarning, IS_MAC} from './utils';
8+
import {
9+
parsePythonVersionFile,
10+
isCacheFeatureAvailable,
11+
logWarning,
12+
IS_MAC
13+
} from './utils';
914

1015
function isPyPyVersion(versionSpec: string) {
1116
return versionSpec.startsWith('pypy');
@@ -43,7 +48,9 @@ function resolveVersionInput() {
4348
);
4449
}
4550

46-
const version = parsePythonVersionFile(fs.readFileSync(versionFile, 'utf8'));
51+
const version = parsePythonVersionFile(
52+
fs.readFileSync(versionFile, 'utf8')
53+
);
4754
core.info(`Resolved ${versionFile} as ${version}`);
4855

4956
return [version];

0 commit comments

Comments
 (0)