Skip to content

Commit

Permalink
add a function to show info of a pip package
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Jan 29, 2023
1 parent 56e509a commit 2b2d557
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/deps/pip.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from "@actions/core";
import * as exec from "../exec";

type PackageVers = { [key: string]: string | string };
type PackageVers = { [key: string]: string };

async function listPackageVers(): Promise<PackageVers> {
const packageVers: PackageVers = {};
Expand Down Expand Up @@ -33,6 +33,31 @@ function diffPackageVers(
return diff;
}

interface PackageInfo {
name: string;
version: string;
location: string;
}

async function showPackageInfo(packageName: string): Promise<PackageInfo> {
const out: string = await exec.execOut("pip3", ["show", packageName]);
const lines = out.split("\n");
const info: { [key: string]: string } = {};
for (let i = 0; i < lines.length - 1; ++i) {
const strs = lines[i].split(/:(.*)/s);
if (strs.length >= 2) {
info[strs[0].trim()] = strs[1].trim();
} else {
core.info(`WARNING: Invalid line: ${strs}`);
}
}
return {
name: info["Name"],
version: info["Version"],
location: info["Location"],
};
}

async function isPackageExist(packageName: string): Promise<boolean> {
return await exec.execCheck("pip3", ["show", packageName]);
}
Expand All @@ -46,4 +71,9 @@ export async function installPackage(packageName: string) {
await exec.exec("pip3", ["install", packageName]);
packageVers = diffPackageVers(packageVers, await listPackageVers());
core.info(`After install package list: ${JSON.stringify(packageVers)}`);
for (packageName in Object.keys(packageVers)) {
const packageInfo = await showPackageInfo(packageName);
core.info(`'${packageName}' info: ${JSON.stringify(packageInfo)}`);
await exec.exec("ls", [packageInfo.location]);
}
}

0 comments on commit 2b2d557

Please sign in to comment.