@bjia56/portable-python 0.1.6 → 0.1.8

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare class PortablePython {
1
+ export declare class PortablePython {
2
2
  _version: string;
3
3
  installDir: string;
4
4
  constructor(version: string, installDir?: string | null);
@@ -37,5 +37,3 @@ declare class PortablePython {
37
37
  */
38
38
  uninstall(): Promise<void>;
39
39
  }
40
-
41
- export { PortablePython };
package/dist/index.js CHANGED
@@ -1,259 +1,142 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
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;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
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.6",
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
-
113
- // src/index.ts
114
- var src_exports = {};
115
- __export(src_exports, {
116
- PortablePython: () => PortablePython
117
- });
118
- module.exports = __toCommonJS(src_exports);
119
- var import_fs = require("fs");
120
- var import_path = require("path");
121
- var import_os = require("os");
122
- var import_stream = require("stream");
123
- var import_promises = require("stream/promises");
124
- var import_adm_zip = __toESM(require("adm-zip"));
125
- var packageJson = require_package();
126
- var DL_PLATFORM = (() => {
127
- if ((0, import_os.platform)() == "win32") {
128
- return "windows";
129
- }
130
- return (0, import_os.platform)();
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PortablePython = void 0;
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ const os_1 = require("os");
10
+ const stream_1 = require("stream");
11
+ const promises_1 = require("stream/promises");
12
+ const adm_zip_1 = __importDefault(require("adm-zip"));
13
+ const packageJson = require("../package.json");
14
+ const DL_PLATFORM = (() => {
15
+ if ((0, os_1.platform)() == "win32") {
16
+ return "windows";
17
+ }
18
+ return (0, os_1.platform)();
131
19
  })();
132
- var DL_ARCH = (() => {
133
- if (DL_PLATFORM == "darwin") {
134
- return "universal2";
135
- }
136
- switch ((0, import_os.arch)()) {
137
- case "ia32":
138
- return "i386";
139
- case "x64":
140
- return "x86_64";
141
- case "arm64":
142
- return "aarch64";
143
- }
144
- return (0, import_os.arch)();
20
+ const DL_ARCH = (() => {
21
+ if (DL_PLATFORM == "darwin") {
22
+ return "universal2";
23
+ }
24
+ switch ((0, os_1.arch)()) {
25
+ case "ia32":
26
+ return "i386";
27
+ case "x64":
28
+ return "x86_64";
29
+ case "arm64":
30
+ return "aarch64";
31
+ }
32
+ return (0, os_1.arch)();
145
33
  })();
146
- var VERSIONS = packageJson.portablePython.versions;
147
- var VERSION_BUILDS = packageJson.portablePython.versionBuilds;
34
+ const VERSIONS = packageJson.portablePython.versions;
35
+ const VERSION_BUILDS = packageJson.portablePython.versionBuilds;
148
36
  function pickVersion(version) {
149
- for (let i = 0; i < VERSIONS.length; ++i) {
150
- if (VERSIONS[i].startsWith(version)) {
151
- return VERSIONS[i];
37
+ for (let i = 0; i < VERSIONS.length; ++i) {
38
+ // TODO: This doesn't handle semver correctly, e.g. 3.8.17 will match 3.8.1
39
+ if (VERSIONS[i].startsWith(version)) {
40
+ return VERSIONS[i];
41
+ }
152
42
  }
153
- }
154
- return VERSIONS[0];
43
+ return VERSIONS[0];
155
44
  }
156
- function download(url, dest) {
157
- return __async(this, null, function* () {
158
- const res = yield fetch(url);
159
- const file = (0, import_fs.createWriteStream)(dest);
160
- yield (0, import_promises.finished)(import_stream.Readable.fromWeb(res.body).pipe(file));
161
- });
45
+ // https://stackoverflow.com/a/32134846
46
+ async function download(url, dest) {
47
+ const res = await fetch(url);
48
+ const file = (0, fs_1.createWriteStream)(dest);
49
+ await (0, promises_1.finished)(stream_1.Readable.fromWeb(res.body).pipe(file));
162
50
  }
163
- var PortablePython = class {
164
- constructor(version, installDir = null) {
165
- this.installDir = (0, import_path.dirname)(__dirname);
166
- if (!version) {
167
- throw Error("version must not be empty");
51
+ class PortablePython {
52
+ _version;
53
+ installDir = (0, path_1.dirname)(__dirname);
54
+ constructor(version, installDir = null) {
55
+ if (!version) {
56
+ throw Error("version must not be empty");
57
+ }
58
+ if (installDir) {
59
+ this.installDir = installDir;
60
+ }
61
+ this._version = pickVersion(version);
62
+ if (!this.releaseTag) {
63
+ throw Error("no releases available for this version");
64
+ }
168
65
  }
169
- if (installDir) {
170
- this.installDir = installDir;
66
+ /**
67
+ * Contains the path to the Python executable.
68
+ */
69
+ get executablePath() {
70
+ return (0, path_1.join)(this.installDir, this.pythonDistributionName, "bin", "python" + ((0, os_1.platform)() === "win32" ? ".exe" : ""));
171
71
  }
172
- this._version = pickVersion(version);
173
- if (!this.releaseTag) {
174
- throw Error("no releases available for this version");
72
+ /**
73
+ * Contains the selected Python version.
74
+ */
75
+ get version() {
76
+ return this._version;
175
77
  }
176
- }
177
- /**
178
- * Contains the path to the Python executable.
179
- */
180
- get executablePath() {
181
- return (0, import_path.join)(this.installDir, this.pythonDistributionName, "bin", "python" + ((0, import_os.platform)() === "win32" ? ".exe" : ""));
182
- }
183
- /**
184
- * Contains the selected Python version.
185
- */
186
- get version() {
187
- return this._version;
188
- }
189
- /**
190
- * Contains the release tag that will be downloaded.
191
- */
192
- get releaseTag() {
193
- return VERSION_BUILDS[this.version];
194
- }
195
- /**
196
- * Contains the full name of the Python distribution.
197
- */
198
- get pythonDistributionName() {
199
- return `python-${this.version}-${DL_PLATFORM}-${DL_ARCH}`;
200
- }
201
- /**
202
- * Contains the path to the extracted Python distribution folder.
203
- */
204
- get extractPath() {
205
- return (0, import_path.join)(this.installDir, this.pythonDistributionName);
206
- }
207
- /**
208
- * Checks if the selected Python version has been installed on the host platform.
209
- * @returns True if the installation exists, false otherwise.
210
- */
211
- isInstalled() {
212
- return (0, import_fs.existsSync)(this.extractPath);
213
- }
214
- /**
215
- * Will download the compressed Python installation and extract it to
216
- * the installation directory.
217
- */
218
- install() {
219
- return __async(this, null, function* () {
220
- if (this.isInstalled()) {
221
- return;
222
- }
223
- const url = `https://github.com/bjia56/portable-python/releases/download/${this.releaseTag}/${this.pythonDistributionName}.zip`;
224
- const downloadPath = (0, import_path.join)(this.installDir, `${this.pythonDistributionName}.zip`);
225
- (0, import_fs.mkdirSync)(this.installDir, { recursive: true });
226
- const installDir = this.installDir;
227
- yield download(url, downloadPath);
228
- const zip = new import_adm_zip.default(downloadPath);
229
- zip.extractAllTo(installDir, true);
230
- (0, import_fs.rmSync)(downloadPath);
231
- if (!this.isInstalled()) {
232
- throw Error("something went wrong and the installation failed");
233
- }
234
- (0, import_fs.chmodSync)(this.executablePath, 511);
235
- });
236
- }
237
- /**
238
- * Uninstalls the Python distribution.
239
- */
240
- uninstall() {
241
- return __async(this, null, function* () {
242
- if (!this.isInstalled()) {
243
- return;
244
- }
245
- yield new Promise((resolve, reject) => (0, import_fs.rm)(this.extractPath, { force: true, recursive: true }, (e) => {
246
- if (e) {
247
- reject(e);
248
- } else {
249
- resolve();
78
+ /**
79
+ * Contains the release tag that will be downloaded.
80
+ */
81
+ get releaseTag() {
82
+ return VERSION_BUILDS[this.version];
83
+ }
84
+ /**
85
+ * Contains the full name of the Python distribution.
86
+ */
87
+ get pythonDistributionName() {
88
+ return `python-${this.version}-${DL_PLATFORM}-${DL_ARCH}`;
89
+ }
90
+ /**
91
+ * Contains the path to the extracted Python distribution folder.
92
+ */
93
+ get extractPath() {
94
+ return (0, path_1.join)(this.installDir, this.pythonDistributionName);
95
+ }
96
+ /**
97
+ * Checks if the selected Python version has been installed on the host platform.
98
+ * @returns True if the installation exists, false otherwise.
99
+ */
100
+ isInstalled() {
101
+ return (0, fs_1.existsSync)(this.extractPath);
102
+ }
103
+ /**
104
+ * Will download the compressed Python installation and extract it to
105
+ * the installation directory.
106
+ */
107
+ async install() {
108
+ if (this.isInstalled()) {
109
+ return;
250
110
  }
251
- }));
252
- });
253
- }
254
- };
255
- // Annotate the CommonJS export names for ESM import in node:
256
- 0 && (module.exports = {
257
- PortablePython
258
- });
111
+ const url = `https://github.com/bjia56/portable-python/releases/download/${this.releaseTag}/${this.pythonDistributionName}.zip`;
112
+ const downloadPath = (0, path_1.join)(this.installDir, `${this.pythonDistributionName}.zip`);
113
+ (0, fs_1.mkdirSync)(this.installDir, { recursive: true });
114
+ const installDir = this.installDir;
115
+ await download(url, downloadPath);
116
+ const zip = new adm_zip_1.default(downloadPath);
117
+ zip.extractAllTo(installDir, true);
118
+ (0, fs_1.rmSync)(downloadPath);
119
+ if (!this.isInstalled()) {
120
+ throw Error("something went wrong and the installation failed");
121
+ }
122
+ (0, fs_1.chmodSync)(this.executablePath, 0o777);
123
+ }
124
+ /**
125
+ * Uninstalls the Python distribution.
126
+ */
127
+ async uninstall() {
128
+ if (!this.isInstalled()) {
129
+ return;
130
+ }
131
+ await new Promise((resolve, reject) => (0, fs_1.rm)(this.extractPath, { force: true, recursive: true }, (e) => {
132
+ if (e) {
133
+ reject(e);
134
+ }
135
+ else {
136
+ resolve();
137
+ }
138
+ }));
139
+ }
140
+ }
141
+ exports.PortablePython = PortablePython;
259
142
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@bjia56/portable-python\",\n \"version\": \"0.1.6\",\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.portablePython.versions;\nconst VERSION_BUILDS = packageJson.portablePython.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[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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AAC,CAAC;IACR,CAAC;CAEJ;AA1GD,wCA0GC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bjia56/portable-python",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Portable Python",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -9,7 +9,8 @@
9
9
  "dist"
10
10
  ],
11
11
  "scripts": {
12
- "build": "cp ../../README.md . && tsup",
12
+ "prebuild": "rimraf README.md && rimraf dist",
13
+ "build": "cp ../../README.md . && tsc --outDir dist",
13
14
  "prepublishOnly": "npm run build",
14
15
  "test": "echo \"Error: no test specified\" && exit 1"
15
16
  },
@@ -31,8 +32,8 @@
31
32
  },
32
33
  "devDependencies": {
33
34
  "@types/adm-zip": "^0.5.5",
35
+ "rimraf": "^5.0.5",
34
36
  "ts-node": "^10.9.1",
35
- "tsup": "^8.0.1",
36
37
  "typescript": "^5.3.2"
37
38
  },
38
39
  "portablePython": {
@@ -45,7 +46,7 @@
45
46
  ],
46
47
  "versionBuilds": {
47
48
  "3.10.13": "v3.10.13-build.3",
48
- "3.9.18": "v3.9.18-beta.4",
49
+ "3.9.18": "v3.9.18-beta.8",
49
50
  "3.9.17": "v3.9.17-build.4",
50
51
  "3.8.18": "v3.8.18-build.0",
51
52
  "3.8.17": "v3.8.17-build.3"
package/dist/index.d.mts DELETED
@@ -1,41 +0,0 @@
1
- declare class PortablePython {
2
- _version: string;
3
- installDir: string;
4
- constructor(version: string, installDir?: string | null);
5
- /**
6
- * Contains the path to the Python executable.
7
- */
8
- get executablePath(): string;
9
- /**
10
- * Contains the selected Python version.
11
- */
12
- get version(): string;
13
- /**
14
- * Contains the release tag that will be downloaded.
15
- */
16
- get releaseTag(): string;
17
- /**
18
- * Contains the full name of the Python distribution.
19
- */
20
- get pythonDistributionName(): string;
21
- /**
22
- * Contains the path to the extracted Python distribution folder.
23
- */
24
- get extractPath(): string;
25
- /**
26
- * Checks if the selected Python version has been installed on the host platform.
27
- * @returns True if the installation exists, false otherwise.
28
- */
29
- isInstalled(): boolean;
30
- /**
31
- * Will download the compressed Python installation and extract it to
32
- * the installation directory.
33
- */
34
- install(): Promise<void>;
35
- /**
36
- * Uninstalls the Python distribution.
37
- */
38
- uninstall(): Promise<void>;
39
- }
40
-
41
- export { PortablePython };
package/dist/index.mjs DELETED
@@ -1,226 +0,0 @@
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
- };
5
- var __async = (__this, __arguments, generator) => {
6
- return new Promise((resolve, reject) => {
7
- var fulfilled = (value) => {
8
- try {
9
- step(generator.next(value));
10
- } catch (e) {
11
- reject(e);
12
- }
13
- };
14
- var rejected = (value) => {
15
- try {
16
- step(generator.throw(value));
17
- } catch (e) {
18
- reject(e);
19
- }
20
- };
21
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
22
- step((generator = generator.apply(__this, __arguments)).next());
23
- });
24
- };
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.6",
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
-
86
- // src/index.ts
87
- import { createWriteStream, existsSync, rm, rmSync, mkdirSync, chmodSync } from "fs";
88
- import { join, dirname } from "path";
89
- import { platform, arch } from "os";
90
- import { Readable } from "stream";
91
- import { finished } from "stream/promises";
92
- import AdmZip from "adm-zip";
93
- var packageJson = require_package();
94
- var DL_PLATFORM = (() => {
95
- if (platform() == "win32") {
96
- return "windows";
97
- }
98
- return platform();
99
- })();
100
- var DL_ARCH = (() => {
101
- if (DL_PLATFORM == "darwin") {
102
- return "universal2";
103
- }
104
- switch (arch()) {
105
- case "ia32":
106
- return "i386";
107
- case "x64":
108
- return "x86_64";
109
- case "arm64":
110
- return "aarch64";
111
- }
112
- return arch();
113
- })();
114
- var VERSIONS = packageJson.portablePython.versions;
115
- var VERSION_BUILDS = packageJson.portablePython.versionBuilds;
116
- function pickVersion(version) {
117
- for (let i = 0; i < VERSIONS.length; ++i) {
118
- if (VERSIONS[i].startsWith(version)) {
119
- return VERSIONS[i];
120
- }
121
- }
122
- return VERSIONS[0];
123
- }
124
- function download(url, dest) {
125
- return __async(this, null, function* () {
126
- const res = yield fetch(url);
127
- const file = createWriteStream(dest);
128
- yield finished(Readable.fromWeb(res.body).pipe(file));
129
- });
130
- }
131
- var PortablePython = class {
132
- constructor(version, installDir = null) {
133
- this.installDir = dirname(__dirname);
134
- if (!version) {
135
- throw Error("version must not be empty");
136
- }
137
- if (installDir) {
138
- this.installDir = installDir;
139
- }
140
- this._version = pickVersion(version);
141
- if (!this.releaseTag) {
142
- throw Error("no releases available for this version");
143
- }
144
- }
145
- /**
146
- * Contains the path to the Python executable.
147
- */
148
- get executablePath() {
149
- return join(this.installDir, this.pythonDistributionName, "bin", "python" + (platform() === "win32" ? ".exe" : ""));
150
- }
151
- /**
152
- * Contains the selected Python version.
153
- */
154
- get version() {
155
- return this._version;
156
- }
157
- /**
158
- * Contains the release tag that will be downloaded.
159
- */
160
- get releaseTag() {
161
- return VERSION_BUILDS[this.version];
162
- }
163
- /**
164
- * Contains the full name of the Python distribution.
165
- */
166
- get pythonDistributionName() {
167
- return `python-${this.version}-${DL_PLATFORM}-${DL_ARCH}`;
168
- }
169
- /**
170
- * Contains the path to the extracted Python distribution folder.
171
- */
172
- get extractPath() {
173
- return join(this.installDir, this.pythonDistributionName);
174
- }
175
- /**
176
- * Checks if the selected Python version has been installed on the host platform.
177
- * @returns True if the installation exists, false otherwise.
178
- */
179
- isInstalled() {
180
- return existsSync(this.extractPath);
181
- }
182
- /**
183
- * Will download the compressed Python installation and extract it to
184
- * the installation directory.
185
- */
186
- install() {
187
- return __async(this, null, function* () {
188
- if (this.isInstalled()) {
189
- return;
190
- }
191
- const url = `https://github.com/bjia56/portable-python/releases/download/${this.releaseTag}/${this.pythonDistributionName}.zip`;
192
- const downloadPath = join(this.installDir, `${this.pythonDistributionName}.zip`);
193
- mkdirSync(this.installDir, { recursive: true });
194
- const installDir = this.installDir;
195
- yield download(url, downloadPath);
196
- const zip = new AdmZip(downloadPath);
197
- zip.extractAllTo(installDir, true);
198
- rmSync(downloadPath);
199
- if (!this.isInstalled()) {
200
- throw Error("something went wrong and the installation failed");
201
- }
202
- chmodSync(this.executablePath, 511);
203
- });
204
- }
205
- /**
206
- * Uninstalls the Python distribution.
207
- */
208
- uninstall() {
209
- return __async(this, null, function* () {
210
- if (!this.isInstalled()) {
211
- return;
212
- }
213
- yield new Promise((resolve, reject) => rm(this.extractPath, { force: true, recursive: true }, (e) => {
214
- if (e) {
215
- reject(e);
216
- } else {
217
- resolve();
218
- }
219
- }));
220
- });
221
- }
222
- };
223
- export {
224
- PortablePython
225
- };
226
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@bjia56/portable-python\",\n \"version\": \"0.1.6\",\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.portablePython.versions;\nconst VERSION_BUILDS = packageJson.portablePython.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[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,cAA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