@bjia56/portable-python 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -110,7 +110,7 @@ function download(url, dest) {
|
|
|
110
110
|
}
|
|
111
111
|
var PortablePython = class {
|
|
112
112
|
constructor(version, installDir = null) {
|
|
113
|
-
this.installDir = (0, import_path.
|
|
113
|
+
this.installDir = (0, import_path.dirname)(__dirname);
|
|
114
114
|
if (!version) {
|
|
115
115
|
throw Error("version must not be empty");
|
|
116
116
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createWriteStream, existsSync, rm, rmSync, mkdirSync, chmodSync } from \"fs\";\nimport { join,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createWriteStream, existsSync, rm, rmSync, mkdirSync, chmodSync } from \"fs\";\nimport { join, dirname } from \"path\";\nimport { platform, arch } from \"os\";\nimport { Readable } from 'stream';\nimport { finished } from 'stream/promises';\nimport { ReadableStream } from 'stream/web';\nimport AdmZip from \"adm-zip\";\n\nconst DL_PLATFORM = (() => {\n if (platform() == \"win32\") {\n return \"windows\";\n }\n return platform();\n})();\n\nconst DL_ARCH = (() => {\n if (DL_PLATFORM == \"darwin\") {\n return \"universal2\";\n }\n\n switch (arch()) {\n case \"ia32\":\n return \"i386\";\n case \"x64\":\n return \"x86_64\";\n case \"arm64\":\n return \"aarch64\";\n }\n\n return arch();\n})();\n\nconst VERSIONS = [\n \"3.10.13\",\n \"3.9.18\",\n \"3.9.17\",\n \"3.8.18\",\n \"3.8.17\",\n];\n\nconst VERSION_BUILDS = new Map<string, string>([\n [\"3.10.13\", \"v3.10.13-build.3\"],\n [\"3.9.18\", \"v3.9.18-beta.4\"],\n [\"3.9.17\", \"v3.9.17-build.4\"],\n [\"3.8.18\", \"v3.8.18-build.0\"],\n [\"3.8.17\", \"v3.8.17-build.3\"],\n]);\n\nfunction pickVersion(version: string) {\n for (let i = 0; i < VERSIONS.length; ++i) {\n // TODO: This doesn't handle semver correctly, e.g. 3.8.17 will match 3.8.1\n if (VERSIONS[i].startsWith(version)) {\n return VERSIONS[i];\n }\n }\n return VERSIONS[0]\n}\n\n// https://stackoverflow.com/a/32134846\nasync function download(url: string, dest: string) {\n const res = await fetch(url);\n const file = createWriteStream(dest);\n await finished(Readable.fromWeb(res.body as ReadableStream).pipe(file));\n}\n\nexport class PortablePython {\n _version: string\n installDir = dirname(__dirname);\n\n constructor(version: string, installDir: string | null = null) {\n if (!version) {\n throw Error(\"version must not be empty\");\n }\n\n if (installDir) {\n this.installDir = installDir;\n }\n\n this._version = pickVersion(version);\n if (!this.releaseTag) {\n throw Error(\"no releases available for this version\");\n }\n }\n\n /**\n * Contains the path to the Python executable.\n */\n get executablePath() {\n return join(this.installDir, this.pythonDistributionName, \"bin\", \"python\" + (platform() === \"win32\" ? \".exe\" : \"\"));\n }\n\n /**\n * Contains the selected Python version.\n */\n get version() {\n return this._version;\n }\n\n /**\n * Contains the release tag that will be downloaded.\n */\n get releaseTag() {\n return VERSION_BUILDS.get(this.version) as string;\n }\n\n /**\n * Contains the full name of the Python distribution.\n */\n get pythonDistributionName() {\n return `python-${this.version}-${DL_PLATFORM}-${DL_ARCH}`;\n }\n\n /**\n * Contains the path to the extracted Python distribution folder.\n */\n get extractPath() {\n return join(this.installDir, this.pythonDistributionName);\n }\n\n /**\n * Checks if the selected Python version has been installed on the host platform.\n * @returns True if the installation exists, false otherwise.\n */\n isInstalled() {\n return existsSync(this.extractPath);\n }\n\n /**\n * Will download the compressed Python installation and extract it to\n * the installation directory.\n */\n async install() {\n if (this.isInstalled()) {\n return;\n }\n\n const url = `https://github.com/bjia56/portable-python/releases/download/${this.releaseTag}/${this.pythonDistributionName}.zip`\n const downloadPath = join(this.installDir, `${this.pythonDistributionName}.zip`);\n\n mkdirSync(this.installDir, { recursive: true });\n\n const installDir = this.installDir;\n await download(url, downloadPath);\n\n const zip = new AdmZip(downloadPath);\n zip.extractAllTo(installDir, true)\n\n rmSync(downloadPath);\n if (!this.isInstalled()) {\n throw Error(\"something went wrong and the installation failed\");\n }\n\n chmodSync(this.executablePath, 0o777);\n }\n\n /**\n * Uninstalls the Python distribution.\n */\n async uninstall() {\n if (!this.isInstalled()) {\n return;\n }\n await new Promise<void>((resolve, reject) => rm(this.extractPath, { force: true, recursive: true }, (e) => {\n if (e) {\n reject(e);\n } else {\n resolve();\n }\n }));\n }\n\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAgF;AAChF,kBAA8B;AAC9B,gBAA+B;AAC/B,oBAAyB;AACzB,sBAAyB;AAEzB,qBAAmB;AAEnB,IAAM,eAAe,MAAM;AACvB,UAAI,oBAAS,KAAK,SAAS;AACvB,WAAO;AAAA,EACX;AACA,aAAO,oBAAS;AACpB,GAAG;AAEH,IAAM,WAAW,MAAM;AACnB,MAAI,eAAe,UAAU;AACzB,WAAO;AAAA,EACX;AAEA,cAAQ,gBAAK,GAAG;AAAA,IAChB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,EACX;AAEA,aAAO,gBAAK;AAChB,GAAG;AAEH,IAAM,WAAW;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAEA,IAAM,iBAAiB,oBAAI,IAAoB;AAAA,EAC3C,CAAC,WAAW,kBAAkB;AAAA,EAC9B,CAAC,UAAU,gBAAgB;AAAA,EAC3B,CAAC,UAAU,iBAAiB;AAAA,EAC5B,CAAC,UAAU,iBAAiB;AAAA,EAC5B,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,KAAK,YAAY,KAAK,sBAAsB;AAAA,EAC5D;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc;AACV,eAAO,sBAAW,KAAK,WAAW;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMM,UAAU;AAAA;AACZ,UAAI,KAAK,YAAY,GAAG;AACpB;AAAA,MACJ;AAEA,YAAM,MAAM,+DAA+D,KAAK,UAAU,IAAI,KAAK,sBAAsB;AACzH,YAAM,mBAAe,kBAAK,KAAK,YAAY,GAAG,KAAK,sBAAsB,MAAM;AAE/E,+BAAU,KAAK,YAAY,EAAE,WAAW,KAAK,CAAC;AAE9C,YAAM,aAAa,KAAK;AACxB,YAAM,SAAS,KAAK,YAAY;AAEhC,YAAM,MAAM,IAAI,eAAAA,QAAO,YAAY;AACnC,UAAI,aAAa,YAAY,IAAI;AAEjC,4BAAO,YAAY;AACnB,UAAI,CAAC,KAAK,YAAY,GAAG;AACrB,cAAM,MAAM,kDAAkD;AAAA,MAClE;AAEA,+BAAU,KAAK,gBAAgB,GAAK;AAAA,IACxC;AAAA;AAAA;AAAA;AAAA;AAAA,EAKM,YAAY;AAAA;AACd,UAAI,CAAC,KAAK,YAAY,GAAG;AACrB;AAAA,MACJ;AACA,YAAM,IAAI,QAAc,CAAC,SAAS,eAAW,cAAG,KAAK,aAAa,EAAE,OAAO,MAAM,WAAW,KAAK,GAAG,CAAC,MAAM;AACvG,YAAI,GAAG;AACH,iBAAO,CAAC;AAAA,QACZ,OAAO;AACH,kBAAQ;AAAA,QACZ;AAAA,MACJ,CAAC,CAAC;AAAA,IACN;AAAA;AAEJ;","names":["AdmZip"]}
|
package/dist/index.mjs
CHANGED
|
@@ -21,7 +21,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
21
21
|
|
|
22
22
|
// src/index.ts
|
|
23
23
|
import { createWriteStream, existsSync, rm, rmSync, mkdirSync, chmodSync } from "fs";
|
|
24
|
-
import { join,
|
|
24
|
+
import { join, dirname } from "path";
|
|
25
25
|
import { platform, arch } from "os";
|
|
26
26
|
import { Readable } from "stream";
|
|
27
27
|
import { finished } from "stream/promises";
|
|
@@ -77,7 +77,7 @@ function download(url, dest) {
|
|
|
77
77
|
}
|
|
78
78
|
var PortablePython = class {
|
|
79
79
|
constructor(version, installDir = null) {
|
|
80
|
-
this.installDir =
|
|
80
|
+
this.installDir = dirname(__dirname);
|
|
81
81
|
if (!version) {
|
|
82
82
|
throw Error("version must not be empty");
|
|
83
83
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createWriteStream, existsSync, rm, rmSync, mkdirSync, chmodSync } from \"fs\";\nimport { join,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createWriteStream, existsSync, rm, rmSync, mkdirSync, chmodSync } from \"fs\";\nimport { join, dirname } from \"path\";\nimport { platform, arch } from \"os\";\nimport { Readable } from 'stream';\nimport { finished } from 'stream/promises';\nimport { ReadableStream } from 'stream/web';\nimport AdmZip from \"adm-zip\";\n\nconst DL_PLATFORM = (() => {\n if (platform() == \"win32\") {\n return \"windows\";\n }\n return platform();\n})();\n\nconst DL_ARCH = (() => {\n if (DL_PLATFORM == \"darwin\") {\n return \"universal2\";\n }\n\n switch (arch()) {\n case \"ia32\":\n return \"i386\";\n case \"x64\":\n return \"x86_64\";\n case \"arm64\":\n return \"aarch64\";\n }\n\n return arch();\n})();\n\nconst VERSIONS = [\n \"3.10.13\",\n \"3.9.18\",\n \"3.9.17\",\n \"3.8.18\",\n \"3.8.17\",\n];\n\nconst VERSION_BUILDS = new Map<string, string>([\n [\"3.10.13\", \"v3.10.13-build.3\"],\n [\"3.9.18\", \"v3.9.18-beta.4\"],\n [\"3.9.17\", \"v3.9.17-build.4\"],\n [\"3.8.18\", \"v3.8.18-build.0\"],\n [\"3.8.17\", \"v3.8.17-build.3\"],\n]);\n\nfunction pickVersion(version: string) {\n for (let i = 0; i < VERSIONS.length; ++i) {\n // TODO: This doesn't handle semver correctly, e.g. 3.8.17 will match 3.8.1\n if (VERSIONS[i].startsWith(version)) {\n return VERSIONS[i];\n }\n }\n return VERSIONS[0]\n}\n\n// https://stackoverflow.com/a/32134846\nasync function download(url: string, dest: string) {\n const res = await fetch(url);\n const file = createWriteStream(dest);\n await finished(Readable.fromWeb(res.body as ReadableStream).pipe(file));\n}\n\nexport class PortablePython {\n _version: string\n installDir = dirname(__dirname);\n\n constructor(version: string, installDir: string | null = null) {\n if (!version) {\n throw Error(\"version must not be empty\");\n }\n\n if (installDir) {\n this.installDir = installDir;\n }\n\n this._version = pickVersion(version);\n if (!this.releaseTag) {\n throw Error(\"no releases available for this version\");\n }\n }\n\n /**\n * Contains the path to the Python executable.\n */\n get executablePath() {\n return join(this.installDir, this.pythonDistributionName, \"bin\", \"python\" + (platform() === \"win32\" ? \".exe\" : \"\"));\n }\n\n /**\n * Contains the selected Python version.\n */\n get version() {\n return this._version;\n }\n\n /**\n * Contains the release tag that will be downloaded.\n */\n get releaseTag() {\n return VERSION_BUILDS.get(this.version) as string;\n }\n\n /**\n * Contains the full name of the Python distribution.\n */\n get pythonDistributionName() {\n return `python-${this.version}-${DL_PLATFORM}-${DL_ARCH}`;\n }\n\n /**\n * Contains the path to the extracted Python distribution folder.\n */\n get extractPath() {\n return join(this.installDir, this.pythonDistributionName);\n }\n\n /**\n * Checks if the selected Python version has been installed on the host platform.\n * @returns True if the installation exists, false otherwise.\n */\n isInstalled() {\n return existsSync(this.extractPath);\n }\n\n /**\n * Will download the compressed Python installation and extract it to\n * the installation directory.\n */\n async install() {\n if (this.isInstalled()) {\n return;\n }\n\n const url = `https://github.com/bjia56/portable-python/releases/download/${this.releaseTag}/${this.pythonDistributionName}.zip`\n const downloadPath = join(this.installDir, `${this.pythonDistributionName}.zip`);\n\n mkdirSync(this.installDir, { recursive: true });\n\n const installDir = this.installDir;\n await download(url, downloadPath);\n\n const zip = new AdmZip(downloadPath);\n zip.extractAllTo(installDir, true)\n\n rmSync(downloadPath);\n if (!this.isInstalled()) {\n throw Error(\"something went wrong and the installation failed\");\n }\n\n chmodSync(this.executablePath, 0o777);\n }\n\n /**\n * Uninstalls the Python distribution.\n */\n async uninstall() {\n if (!this.isInstalled()) {\n return;\n }\n await new Promise<void>((resolve, reject) => rm(this.extractPath, { force: true, recursive: true }, (e) => {\n if (e) {\n reject(e);\n } else {\n resolve();\n }\n }));\n }\n\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,mBAAmB,YAAY,IAAI,QAAQ,WAAW,iBAAiB;AAChF,SAAS,MAAM,eAAe;AAC9B,SAAS,UAAU,YAAY;AAC/B,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AAEzB,OAAO,YAAY;AAEnB,IAAM,eAAe,MAAM;AACvB,MAAI,SAAS,KAAK,SAAS;AACvB,WAAO;AAAA,EACX;AACA,SAAO,SAAS;AACpB,GAAG;AAEH,IAAM,WAAW,MAAM;AACnB,MAAI,eAAe,UAAU;AACzB,WAAO;AAAA,EACX;AAEA,UAAQ,KAAK,GAAG;AAAA,IAChB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,EACX;AAEA,SAAO,KAAK;AAChB,GAAG;AAEH,IAAM,WAAW;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAEA,IAAM,iBAAiB,oBAAI,IAAoB;AAAA,EAC3C,CAAC,WAAW,kBAAkB;AAAA,EAC9B,CAAC,UAAU,gBAAgB;AAAA,EAC3B,CAAC,UAAU,iBAAiB;AAAA,EAC5B,CAAC,UAAU,iBAAiB;AAAA,EAC5B,CAAC,UAAU,iBAAiB;AAChC,CAAC;AAED,SAAS,YAAY,SAAiB;AAClC,WAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,EAAE,GAAG;AAEtC,QAAI,SAAS,CAAC,EAAE,WAAW,OAAO,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