From 1ffc145596d36f9053411b6e40eb05e67ec92ec5 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 14 Sep 2021 12:40:42 -0500 Subject: [PATCH] fix: use pip3 if available --- package.json | 6 ++++-- pnpm-lock.yaml | 10 ++++++++-- src/utils/setup/setupPip.ts | 6 ++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index a4126aab..d891f42c 100644 --- a/package.json +++ b/package.json @@ -32,17 +32,19 @@ }, "prettier": "prettier-config-atomic", "dependencies": { - "@actions/exec": "^1.1.0", "@actions/core": "^1.5.0", + "@actions/exec": "^1.1.0", "@actions/io": "^1.1.1", "@actions/tool-cache": "^1.7.1", "hasha": "^5.2.2", - "semver": "^7.3.5" + "semver": "^7.3.5", + "which": "^2.0.2" }, "devDependencies": { "@types/jest": "^27.0.1", "@types/node": "^16.9.1", "@types/semver": "^7.3.8", + "@types/which": "^2.0.1", "cross-env": "7.0.3", "eslint-config-atomic": "^1.16.2", "jest": "^27.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 016a850b..d9cf2e5e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,7 @@ importers: '@types/jest': ^27.0.1 '@types/node': ^16.9.1 '@types/semver': ^7.3.8 + '@types/which': ^2.0.1 cross-env: 7.0.3 eslint-config-atomic: ^1.16.2 hasha: ^5.2.2 @@ -23,6 +24,7 @@ importers: terser-config-atomic: ^0.1.1 ts-jest: ^27.0.5 typescript: ^4.4.3 + which: ^2.0.2 dependencies: '@actions/core': 1.5.0 '@actions/exec': 1.1.0 @@ -30,10 +32,12 @@ importers: '@actions/tool-cache': 1.7.1 hasha: 5.2.2 semver: 7.3.5 + which: 2.0.2 devDependencies: '@types/jest': 27.0.1 '@types/node': 16.9.1 '@types/semver': 7.3.8 + '@types/which': 2.0.1 cross-env: 7.0.3 eslint-config-atomic: 1.16.2 jest: 27.2.0 @@ -1546,6 +1550,10 @@ packages: resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==} dev: true + /@types/which/2.0.1: + resolution: {integrity: sha512-Jjakcv8Roqtio6w1gr0D7y6twbhx6gGgFGF5BLwajPpnOIOxFkakFhCq+LmyyeAz7BX6ULrjBOxdKaCDy+4+dQ==} + dev: true + /@types/yargs-parser/20.2.1: resolution: {integrity: sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==} dev: true @@ -4799,7 +4807,6 @@ packages: /isexe/2.0.0: resolution: {integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=} - dev: true /isobject/2.1.0: resolution: {integrity: sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk=} @@ -8425,7 +8432,6 @@ packages: hasBin: true dependencies: isexe: 2.0.0 - dev: true /word-wrap/1.2.3: resolution: {integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==} diff --git a/src/utils/setup/setupPip.ts b/src/utils/setup/setupPip.ts index daf9eeef..19197baf 100644 --- a/src/utils/setup/setupPip.ts +++ b/src/utils/setup/setupPip.ts @@ -1,10 +1,12 @@ import { exec } from "@actions/exec" +import which from "which" /** A function that installs a package using pip */ export async function setupPip(name: string, version?: string) { - // pip3 install conan --upgrade + // check if it exists + const pip = which.sync("pip3", { nothrow: true }) !== null ? "pip3" : "pip" - const exit = await exec("pip", ["install", "--user", version !== undefined ? `${name}==${version}` : name]) + const exit = await exec(pip, ["install", version !== undefined ? `${name}==${version}` : name]) if (exit !== 0) { throw new Error(`Failed to install ${name} ${version}`) }