Skip to content

Commit

Permalink
Fix style issues and build
Browse files Browse the repository at this point in the history
Build the project using `npm run build` and run prettier using `npm run
format`
  • Loading branch information
elpic committed Jan 18, 2023
1 parent ce7a9c1 commit 730345f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
6 changes: 3 additions & 3 deletions __tests__/utils.test.ts
Expand Up @@ -12,15 +12,15 @@ jest.mock('@actions/core');

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

it('trims extra spaces at the end of the content', () => {
expect(parsePythonVersionFile('3.7 ')).toEqual('3.7')
expect(parsePythonVersionFile('3.7 ')).toEqual('3.7');
});

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

Expand Down
18 changes: 16 additions & 2 deletions dist/setup/index.js
Expand Up @@ -66921,7 +66921,7 @@ function resolveVersionInput() {
if (!fs_1.default.existsSync(versionFile)) {
throw new Error(`The specified python version file at: ${versionFile} doesn't exist.`);
}
const version = fs_1.default.readFileSync(versionFile, 'utf8');
const version = utils_1.parsePythonVersionFile(fs_1.default.readFileSync(versionFile, 'utf8'));
core.info(`Resolved ${versionFile} as ${version}`);
return [version];
}
Expand Down Expand Up @@ -67024,7 +67024,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
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;
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;
const cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186));
const fs_1 = __importDefault(__nccwpck_require__(7147));
Expand All @@ -67037,6 +67037,20 @@ exports.IS_MAC = process.platform === 'darwin';
exports.WINDOWS_ARCHS = ['x86', 'x64'];
exports.WINDOWS_PLATFORMS = ['win32', 'win64'];
const PYPY_VERSION_FILE = 'PYPY_VERSION';
function parsePythonVersionFile(contents) {
var _a;
let pythonVersion;
// Try to find the version in tool-version file
const found = contents.match(/^(?:python\s+)?v?(?<version>[^\s]+)$/m);
pythonVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version;
// In the case of an unknown format,
// return as is and evaluate the version separately.
if (!pythonVersion) {
pythonVersion = contents.trim();
}
return pythonVersion;
}
exports.parsePythonVersionFile = parsePythonVersionFile;
/** create Symlinks for downloaded PyPy
* It should be executed only for downloaded versions in runtime, because
* toolcache versions have this setup.
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-usage.md
Expand Up @@ -241,7 +241,7 @@ jobs:
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.
If both the python-version and the python-version-file inputs are provided then the python-version input is used.

> 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.
>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.
```yaml
steps:
Expand Down
11 changes: 9 additions & 2 deletions src/setup-python.ts
Expand Up @@ -5,7 +5,12 @@ import * as path from 'path';
import * as os from 'os';
import fs from 'fs';
import {getCacheDistributor} from './cache-distributions/cache-factory';
import {parsePythonVersionFile, isCacheFeatureAvailable, logWarning, IS_MAC} from './utils';
import {
parsePythonVersionFile,
isCacheFeatureAvailable,
logWarning,
IS_MAC
} from './utils';

function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith('pypy');
Expand Down Expand Up @@ -43,7 +48,9 @@ function resolveVersionInput() {
);
}

const version = parsePythonVersionFile(fs.readFileSync(versionFile, 'utf8'));
const version = parsePythonVersionFile(
fs.readFileSync(versionFile, 'utf8')
);
core.info(`Resolved ${versionFile} as ${version}`);

return [version];
Expand Down

0 comments on commit 730345f

Please sign in to comment.