@bjia56/portable-python 0.1.2 → 0.1.4
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 +67 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -1
package/dist/index.js
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -47,6 +50,66 @@ var __async = (__this, __arguments, generator) => {
|
|
|
47
50
|
});
|
|
48
51
|
};
|
|
49
52
|
|
|
53
|
+
// package.json
|
|
54
|
+
var require_package = __commonJS({
|
|
55
|
+
"package.json"(exports, module2) {
|
|
56
|
+
module2.exports = {
|
|
57
|
+
name: "@bjia56/portable-python",
|
|
58
|
+
version: "0.1.4",
|
|
59
|
+
description: "Portable Python",
|
|
60
|
+
main: "./dist/index.js",
|
|
61
|
+
module: "./dist/index.mjs",
|
|
62
|
+
types: "./dist/index.d.ts",
|
|
63
|
+
files: [
|
|
64
|
+
"dist"
|
|
65
|
+
],
|
|
66
|
+
scripts: {
|
|
67
|
+
build: "cp ../../README.md . && tsup",
|
|
68
|
+
prepublishOnly: "npm run build",
|
|
69
|
+
test: 'echo "Error: no test specified" && exit 1'
|
|
70
|
+
},
|
|
71
|
+
repository: {
|
|
72
|
+
type: "git",
|
|
73
|
+
url: "git+https://github.com/bjia56/portable-python.git"
|
|
74
|
+
},
|
|
75
|
+
keywords: [
|
|
76
|
+
"python"
|
|
77
|
+
],
|
|
78
|
+
author: "Brett Jia",
|
|
79
|
+
license: "Apache-2.0",
|
|
80
|
+
bugs: {
|
|
81
|
+
url: "https://github.com/bjia56/portable-python/issues"
|
|
82
|
+
},
|
|
83
|
+
homepage: "https://github.com/bjia56/portable-python",
|
|
84
|
+
dependencies: {
|
|
85
|
+
"adm-zip": "^0.5.10"
|
|
86
|
+
},
|
|
87
|
+
devDependencies: {
|
|
88
|
+
"@types/adm-zip": "^0.5.5",
|
|
89
|
+
"ts-node": "^10.9.1",
|
|
90
|
+
tsup: "^8.0.1",
|
|
91
|
+
typescript: "^5.3.2"
|
|
92
|
+
},
|
|
93
|
+
portablePython: {
|
|
94
|
+
versions: [
|
|
95
|
+
"3.10.13",
|
|
96
|
+
"3.9.18",
|
|
97
|
+
"3.9.17",
|
|
98
|
+
"3.8.18",
|
|
99
|
+
"3.8.17"
|
|
100
|
+
],
|
|
101
|
+
versionBuilds: {
|
|
102
|
+
"3.10.13": "v3.10.13-build.3",
|
|
103
|
+
"3.9.18": "v3.9.18-beta.4",
|
|
104
|
+
"3.9.17": "v3.9.17-build.4",
|
|
105
|
+
"3.8.18": "v3.8.18-build.0",
|
|
106
|
+
"3.8.17": "v3.8.17-build.3"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
50
113
|
// src/index.ts
|
|
51
114
|
var src_exports = {};
|
|
52
115
|
__export(src_exports, {
|
|
@@ -59,6 +122,7 @@ var import_os = require("os");
|
|
|
59
122
|
var import_stream = require("stream");
|
|
60
123
|
var import_promises = require("stream/promises");
|
|
61
124
|
var import_adm_zip = __toESM(require("adm-zip"));
|
|
125
|
+
var packageJson = require_package();
|
|
62
126
|
var DL_PLATFORM = (() => {
|
|
63
127
|
if ((0, import_os.platform)() == "win32") {
|
|
64
128
|
return "windows";
|
|
@@ -79,20 +143,8 @@ var DL_ARCH = (() => {
|
|
|
79
143
|
}
|
|
80
144
|
return (0, import_os.arch)();
|
|
81
145
|
})();
|
|
82
|
-
var VERSIONS = [
|
|
83
|
-
|
|
84
|
-
"3.9.18",
|
|
85
|
-
"3.9.17",
|
|
86
|
-
"3.8.18",
|
|
87
|
-
"3.8.17"
|
|
88
|
-
];
|
|
89
|
-
var VERSION_BUILDS = /* @__PURE__ */ new Map([
|
|
90
|
-
["3.10.13", "v3.10.13-build.3"],
|
|
91
|
-
["3.9.18", "v3.9.18-beta.4"],
|
|
92
|
-
["3.9.17", "v3.9.17-build.4"],
|
|
93
|
-
["3.8.18", "v3.8.18-build.0"],
|
|
94
|
-
["3.8.17", "v3.8.17-build.3"]
|
|
95
|
-
]);
|
|
146
|
+
var VERSIONS = packageJson["versions"];
|
|
147
|
+
var VERSION_BUILDS = packageJson["versionBuilds"];
|
|
96
148
|
function pickVersion(version) {
|
|
97
149
|
for (let i = 0; i < VERSIONS.length; ++i) {
|
|
98
150
|
if (VERSIONS[i].startsWith(version)) {
|
|
@@ -110,7 +162,7 @@ function download(url, dest) {
|
|
|
110
162
|
}
|
|
111
163
|
var PortablePython = class {
|
|
112
164
|
constructor(version, installDir = null) {
|
|
113
|
-
this.installDir = (0, import_path.
|
|
165
|
+
this.installDir = (0, import_path.dirname)(__dirname);
|
|
114
166
|
if (!version) {
|
|
115
167
|
throw Error("version must not be empty");
|
|
116
168
|
}
|
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":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@bjia56/portable-python\",\n \"version\": \"0.1.4\",\n \"description\": \"Portable Python\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"build\": \"cp ../../README.md . && tsup\",\n \"prepublishOnly\": \"npm run build\",\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/bjia56/portable-python.git\"\n },\n \"keywords\": [\n \"python\"\n ],\n \"author\": \"Brett Jia\",\n \"license\": \"Apache-2.0\",\n \"bugs\": {\n \"url\": \"https://github.com/bjia56/portable-python/issues\"\n },\n \"homepage\": \"https://github.com/bjia56/portable-python\",\n \"dependencies\": {\n \"adm-zip\": \"^0.5.10\"\n },\n \"devDependencies\": {\n \"@types/adm-zip\": \"^0.5.5\",\n \"ts-node\": \"^10.9.1\",\n \"tsup\": \"^8.0.1\",\n \"typescript\": \"^5.3.2\"\n },\n \"portablePython\": {\n \"versions\": [\n \"3.10.13\",\n \"3.9.18\",\n \"3.9.17\",\n \"3.8.18\",\n \"3.8.17\"\n ],\n \"versionBuilds\": {\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 }\n}\n","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 packageJson = require(\"../package.json\");\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 = packageJson[\"versions\"];\nconst VERSION_BUILDS = packageJson[\"versionBuilds\"];\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,0BAAAA,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,aAAe;AAAA,MACf,MAAQ;AAAA,MACR,QAAU;AAAA,MACV,OAAS;AAAA,MACT,OAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA,SAAW;AAAA,QACT,OAAS;AAAA,QACT,gBAAkB;AAAA,QAClB,MAAQ;AAAA,MACV;AAAA,MACA,YAAc;AAAA,QACZ,MAAQ;AAAA,QACR,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,QACV;AAAA,MACF;AAAA,MACA,QAAU;AAAA,MACV,SAAW;AAAA,MACX,MAAQ;AAAA,QACN,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,MACZ,cAAgB;AAAA,QACd,WAAW;AAAA,MACb;AAAA,MACA,iBAAmB;AAAA,QACjB,kBAAkB;AAAA,QAClB,WAAW;AAAA,QACX,MAAQ;AAAA,QACR,YAAc;AAAA,MAChB;AAAA,MACA,gBAAkB;AAAA,QAChB,UAAY;AAAA,UACV;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QACA,eAAiB;AAAA,UACf,WAAW;AAAA,UACX,U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EA,+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":["module","AdmZip"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
+
};
|
|
1
5
|
var __async = (__this, __arguments, generator) => {
|
|
2
6
|
return new Promise((resolve, reject) => {
|
|
3
7
|
var fulfilled = (value) => {
|
|
@@ -19,13 +23,74 @@ var __async = (__this, __arguments, generator) => {
|
|
|
19
23
|
});
|
|
20
24
|
};
|
|
21
25
|
|
|
26
|
+
// package.json
|
|
27
|
+
var require_package = __commonJS({
|
|
28
|
+
"package.json"(exports, module) {
|
|
29
|
+
module.exports = {
|
|
30
|
+
name: "@bjia56/portable-python",
|
|
31
|
+
version: "0.1.4",
|
|
32
|
+
description: "Portable Python",
|
|
33
|
+
main: "./dist/index.js",
|
|
34
|
+
module: "./dist/index.mjs",
|
|
35
|
+
types: "./dist/index.d.ts",
|
|
36
|
+
files: [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
scripts: {
|
|
40
|
+
build: "cp ../../README.md . && tsup",
|
|
41
|
+
prepublishOnly: "npm run build",
|
|
42
|
+
test: 'echo "Error: no test specified" && exit 1'
|
|
43
|
+
},
|
|
44
|
+
repository: {
|
|
45
|
+
type: "git",
|
|
46
|
+
url: "git+https://github.com/bjia56/portable-python.git"
|
|
47
|
+
},
|
|
48
|
+
keywords: [
|
|
49
|
+
"python"
|
|
50
|
+
],
|
|
51
|
+
author: "Brett Jia",
|
|
52
|
+
license: "Apache-2.0",
|
|
53
|
+
bugs: {
|
|
54
|
+
url: "https://github.com/bjia56/portable-python/issues"
|
|
55
|
+
},
|
|
56
|
+
homepage: "https://github.com/bjia56/portable-python",
|
|
57
|
+
dependencies: {
|
|
58
|
+
"adm-zip": "^0.5.10"
|
|
59
|
+
},
|
|
60
|
+
devDependencies: {
|
|
61
|
+
"@types/adm-zip": "^0.5.5",
|
|
62
|
+
"ts-node": "^10.9.1",
|
|
63
|
+
tsup: "^8.0.1",
|
|
64
|
+
typescript: "^5.3.2"
|
|
65
|
+
},
|
|
66
|
+
portablePython: {
|
|
67
|
+
versions: [
|
|
68
|
+
"3.10.13",
|
|
69
|
+
"3.9.18",
|
|
70
|
+
"3.9.17",
|
|
71
|
+
"3.8.18",
|
|
72
|
+
"3.8.17"
|
|
73
|
+
],
|
|
74
|
+
versionBuilds: {
|
|
75
|
+
"3.10.13": "v3.10.13-build.3",
|
|
76
|
+
"3.9.18": "v3.9.18-beta.4",
|
|
77
|
+
"3.9.17": "v3.9.17-build.4",
|
|
78
|
+
"3.8.18": "v3.8.18-build.0",
|
|
79
|
+
"3.8.17": "v3.8.17-build.3"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
22
86
|
// src/index.ts
|
|
23
87
|
import { createWriteStream, existsSync, rm, rmSync, mkdirSync, chmodSync } from "fs";
|
|
24
|
-
import { join,
|
|
88
|
+
import { join, dirname } from "path";
|
|
25
89
|
import { platform, arch } from "os";
|
|
26
90
|
import { Readable } from "stream";
|
|
27
91
|
import { finished } from "stream/promises";
|
|
28
92
|
import AdmZip from "adm-zip";
|
|
93
|
+
var packageJson = require_package();
|
|
29
94
|
var DL_PLATFORM = (() => {
|
|
30
95
|
if (platform() == "win32") {
|
|
31
96
|
return "windows";
|
|
@@ -46,20 +111,8 @@ var DL_ARCH = (() => {
|
|
|
46
111
|
}
|
|
47
112
|
return arch();
|
|
48
113
|
})();
|
|
49
|
-
var VERSIONS = [
|
|
50
|
-
|
|
51
|
-
"3.9.18",
|
|
52
|
-
"3.9.17",
|
|
53
|
-
"3.8.18",
|
|
54
|
-
"3.8.17"
|
|
55
|
-
];
|
|
56
|
-
var VERSION_BUILDS = /* @__PURE__ */ new Map([
|
|
57
|
-
["3.10.13", "v3.10.13-build.3"],
|
|
58
|
-
["3.9.18", "v3.9.18-beta.4"],
|
|
59
|
-
["3.9.17", "v3.9.17-build.4"],
|
|
60
|
-
["3.8.18", "v3.8.18-build.0"],
|
|
61
|
-
["3.8.17", "v3.8.17-build.3"]
|
|
62
|
-
]);
|
|
114
|
+
var VERSIONS = packageJson["versions"];
|
|
115
|
+
var VERSION_BUILDS = packageJson["versionBuilds"];
|
|
63
116
|
function pickVersion(version) {
|
|
64
117
|
for (let i = 0; i < VERSIONS.length; ++i) {
|
|
65
118
|
if (VERSIONS[i].startsWith(version)) {
|
|
@@ -77,7 +130,7 @@ function download(url, dest) {
|
|
|
77
130
|
}
|
|
78
131
|
var PortablePython = class {
|
|
79
132
|
constructor(version, installDir = null) {
|
|
80
|
-
this.installDir =
|
|
133
|
+
this.installDir = dirname(__dirname);
|
|
81
134
|
if (!version) {
|
|
82
135
|
throw Error("version must not be empty");
|
|
83
136
|
}
|
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":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@bjia56/portable-python\",\n \"version\": \"0.1.4\",\n \"description\": \"Portable Python\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"build\": \"cp ../../README.md . && tsup\",\n \"prepublishOnly\": \"npm run build\",\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/bjia56/portable-python.git\"\n },\n \"keywords\": [\n \"python\"\n ],\n \"author\": \"Brett Jia\",\n \"license\": \"Apache-2.0\",\n \"bugs\": {\n \"url\": \"https://github.com/bjia56/portable-python/issues\"\n },\n \"homepage\": \"https://github.com/bjia56/portable-python\",\n \"dependencies\": {\n \"adm-zip\": \"^0.5.10\"\n },\n \"devDependencies\": {\n \"@types/adm-zip\": \"^0.5.5\",\n \"ts-node\": \"^10.9.1\",\n \"tsup\": \"^8.0.1\",\n \"typescript\": \"^5.3.2\"\n },\n \"portablePython\": {\n \"versions\": [\n \"3.10.13\",\n \"3.9.18\",\n \"3.9.17\",\n \"3.8.18\",\n \"3.8.17\"\n ],\n \"versionBuilds\": {\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 }\n}\n","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 packageJson = require(\"../package.json\");\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 = packageJson[\"versions\"];\nconst VERSION_BUILDS = packageJson[\"versionBuilds\"];\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,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,aAAe;AAAA,MACf,MAAQ;AAAA,MACR,QAAU;AAAA,MACV,OAAS;AAAA,MACT,OAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA,SAAW;AAAA,QACT,OAAS;AAAA,QACT,gBAAkB;AAAA,QAClB,MAAQ;AAAA,MACV;AAAA,MACA,YAAc;AAAA,QACZ,MAAQ;AAAA,QACR,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,QACV;AAAA,MACF;AAAA,MACA,QAAU;AAAA,MACV,SAAW;AAAA,MACX,MAAQ;AAAA,QACN,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,MACZ,cAAgB;AAAA,QACd,WAAW;AAAA,MACb;AAAA,MACA,iBAAmB;AAAA,QACjB,kBAAkB;AAAA,QAClB,WAAW;AAAA,QACX,MAAQ;AAAA,QACR,YAAc;AAAA,MAChB;AAAA,MACA,gBAAkB;AAAA,QAChB,UAAY;AAAA,UACV;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QACA,eAAiB;AAAA,UACf,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B,cAAM,MAAM,kDAAkD;AAAA,MAClE;AAEA,gBAAU,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,WAAW,GAAG,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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjia56/portable-python",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Portable Python",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -34,5 +34,21 @@
|
|
|
34
34
|
"ts-node": "^10.9.1",
|
|
35
35
|
"tsup": "^8.0.1",
|
|
36
36
|
"typescript": "^5.3.2"
|
|
37
|
+
},
|
|
38
|
+
"portablePython": {
|
|
39
|
+
"versions": [
|
|
40
|
+
"3.10.13",
|
|
41
|
+
"3.9.18",
|
|
42
|
+
"3.9.17",
|
|
43
|
+
"3.8.18",
|
|
44
|
+
"3.8.17"
|
|
45
|
+
],
|
|
46
|
+
"versionBuilds": {
|
|
47
|
+
"3.10.13": "v3.10.13-build.3",
|
|
48
|
+
"3.9.18": "v3.9.18-beta.4",
|
|
49
|
+
"3.9.17": "v3.9.17-build.4",
|
|
50
|
+
"3.8.18": "v3.8.18-build.0",
|
|
51
|
+
"3.8.17": "v3.8.17-build.3"
|
|
52
|
+
}
|
|
37
53
|
}
|
|
38
54
|
}
|