Created
September 23, 2024 20:30
-
-
Save gkspranger/ddfcc529d0eec310cb6f595d38ed7c05 to your computer and use it in GitHub Desktop.
gist to install deps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var process = require("bldz/process") | |
var child_process = require("bldz/child_process") | |
var fs = require("bldz/fs") | |
var CWD = process.cwd() | |
var BUILD_DIR = `${CWD}/build-out` | |
child_process.spawn(`rm -fr ${BUILD_DIR}/* ${BUILD_DIR}/.*`) | |
child_process.spawn(`cp -r python/. ${BUILD_DIR}/`) | |
function readRequirements() { | |
var reqs = fs.read(`${BUILD_DIR}/requirements.txt`) | |
var deps = reqs.split(/\r?\n/) | |
return deps | |
} | |
function readManifest() { | |
var mft = fs.read(`${CWD}/python/manifest.json`) | |
var cfg = JSON.parse(mft) | |
return cfg | |
} | |
function pypiPaths() { | |
var cfg = readManifest() | |
var links = "" | |
cfg.pypiPaths.forEach(function(path) { | |
links = links.concat(` --find-links ${path}/ `) | |
}) | |
return links | |
} | |
function installDep(pkg) { | |
var i = child_process.spawn(`python3 -m pip install \ | |
${pkg} \ | |
-t ${BUILD_DIR}/ \ | |
--no-deps --no-index \ | |
${pypiPaths()}`) | |
if (i.exitCode > 0) { | |
console.log(`rc=${i.exitCode} | |
stdout=${i.stdout} | |
stderr=${i.stderr}`) | |
throw Error(`error installing dependency: ${pkg}`) | |
} | |
} | |
readRequirements().forEach(function(pkg) { | |
if (!pkg) { | |
return | |
} | |
installDep(pkg) | |
}) | |
child_process.spawn(`cd ${BUILD_DIR}/ && \ | |
tar zcvf artifact.tgz *`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment