Skip to content

Commit 397c132

Browse files
authored
Merge pull request #22 from Geode-solutions/feat/pyinstaller
feat(PyInstaller): add pyinstaller script
2 parents 269bdcd + f3c0eae commit 397c132

2 files changed

Lines changed: 112 additions & 23 deletions

File tree

generate_pyinstaller.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env node
2+
3+
import fs from "node:fs";
4+
import path from "node:path";
5+
import { execSync } from "node:child_process";
6+
7+
const projectPath = process.argv[2];
8+
console.log("projectPath", projectPath);
9+
10+
function pythonCommand() {
11+
const candidates = ["python3", "python"];
12+
for (const cmd of candidates) {
13+
try {
14+
execSync(`${cmd} --version`, { stdio: "ignore" });
15+
return cmd;
16+
} catch {
17+
// silent fail
18+
}
19+
}
20+
throw new Error("Python not found");
21+
}
22+
23+
function createVenv() {
24+
console.log("🔧 Setting up Python virtual environment...");
25+
const python = pythonCommand();
26+
console.log(`→ Using Python: ${python}`);
27+
const venvPath = path.join(projectPath, "venv");
28+
if (fs.existsSync(venvPath)) {
29+
console.log(`→ Found existing venv → ${venvPath}`);
30+
} else {
31+
console.log(`→ Creating virtual environment → ${venvPath}`);
32+
try {
33+
execSync(`${python} -m venv ${venvPath}`, { stdio: "inherit" });
34+
} catch (err) {
35+
console.error("Failed to create virtual environment");
36+
console.error(err.message);
37+
process.exit(1);
38+
}
39+
}
40+
if (process.platform === "win32") {
41+
return path.join(venvPath, "Scripts", "python.exe");
42+
} else {
43+
return path.join(venvPath, "bin", "python");
44+
}
45+
}
46+
47+
function installDependecies(pythonExe) {
48+
console.log(`→ Installing dependencies ...`);
49+
const pipCommand = `pip install ${projectPath} pyinstaller`;
50+
try {
51+
console.log(`→ Running: ${pythonExe} -m ${pipCommand}`);
52+
execSync(`${pythonExe} -m ${pipCommand}`, { stdio: "inherit" });
53+
} catch (err) {
54+
console.error("Failed to install requirements");
55+
console.error(err.message);
56+
process.exit(1);
57+
}
58+
console.log("✅ Python virtual environment setup complete");
59+
}
60+
61+
function runPyInstaller(pythonExe) {
62+
console.log(`→ Running PyInstaller ...`);
63+
const specFiles = fs.readdirSync(projectPath, { withFileTypes: true })
64+
.filter(file => file.isFile() && file.name.endsWith(".spec"))
65+
.map(file => path.join(projectPath, file.name));
66+
if (specFiles.length !== 1) {
67+
console.error("Expected 1 spec file, found " + specFiles.length);
68+
process.exit(1);
69+
}
70+
const pyinstallerCommand = `PyInstaller ${specFiles[0]} --distpath ${process.cwd()} --clean`;
71+
try {
72+
console.log(`→ Running: ${pythonExe} -m ${pyinstallerCommand}`);
73+
execSync(`${pythonExe} -m ${pyinstallerCommand}`, { stdio: "inherit" });
74+
} catch (err) {
75+
console.error("Failed to run pyinstaller");
76+
console.error(err.message);
77+
process.exit(1);
78+
}
79+
console.log("✅ PyInstaller complete");
80+
}
81+
82+
function main() {
83+
const pythonExe = createVenv();
84+
installDependecies(pythonExe);
85+
runPyInstaller(pythonExe);
86+
}
87+
88+
main();

package.json

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,39 @@
22
"name": "@geode/opengeodeweb-microservice",
33
"version": "0.0.0",
44
"description": "Shared utilities and schema generator for OpenGeodeWeb ecosystem",
5-
"bin": {
6-
"opengeodeweb-microservice-generate": "./generate_schemas.js"
7-
},
8-
"main": "generate_schemas.js",
9-
"scripts": {
10-
"json": "echo \"Error: no test specified\" && exit 0",
11-
"test": "echo \"Error: no test specified\" && exit 0",
12-
"build": "echo \"Error: no test specified\" && exit 0"
13-
},
14-
"dependencies": {
15-
"glob": "^11.0.3",
16-
"quicktype-core": "^23.2.6"
17-
},
18-
"repository": {
19-
"type": "git",
20-
"url": "git+https://github.com/Geode-solutions/OpenGeodeWeb-Microservice.git"
5+
"homepage": "https://github.com/Geode-solutions/OpenGeodeWeb-Microservice",
6+
"bugs": {
7+
"url": "https://github.com/Geode-solutions/OpenGeodeWeb-Microservice/issues"
218
},
9+
"license": "MIT",
2210
"author": {
2311
"name": "Geode-solutions",
2412
"email": "contact@geode-solutions.com",
2513
"url": "https://geode-solutions.com/"
2614
},
27-
"license": "MIT",
28-
"bugs": {
29-
"url": "https://github.com/Geode-solutions/OpenGeodeWeb-Microservice/issues"
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/Geode-solutions/OpenGeodeWeb-Microservice.git"
3018
},
31-
"homepage": "https://github.com/Geode-solutions/OpenGeodeWeb-Microservice",
32-
"publishConfig": {
33-
"access": "public"
19+
"bin": {
20+
"opengeodeweb-microservice-generate": "./generate_schemas.js",
21+
"opengeodeweb-microservice-pyinstaller": "./generate_pyinstaller.js"
3422
},
3523
"files": [
3624
"generate_schemas.js"
3725
],
38-
"type": "module"
26+
"type": "module",
27+
"main": "generate_schemas.js",
28+
"publishConfig": {
29+
"access": "public"
30+
},
31+
"scripts": {
32+
"json": "echo \"Error: no test specified\" && exit 0",
33+
"test": "echo \"Error: no test specified\" && exit 0",
34+
"build": "echo \"Error: no test specified\" && exit 0"
35+
},
36+
"dependencies": {
37+
"glob": "11.0.3",
38+
"quicktype-core": "23.2.6"
39+
}
3940
}

0 commit comments

Comments
 (0)