forked from intel/AI-Playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide scripts, that simply setup a python env This env may be used for developers (on windows machines) Overall flow remains equal, but try to make things a little more obvious my adding named parameters of scripts. Signed-off-by: Florian Esser <florian.esser@tngtech.com>
- Loading branch information
1 parent
384eb2e
commit f9c7cfa
Showing
15 changed files
with
260 additions
and
342 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Usage: node pack-offline.js <npm_package_res_dir> <platform> | ||
// | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const AdmZip = require('adm-zip'); | ||
const childProcess = require('child_process'); | ||
|
||
const argv = require('minimist')(process.argv.slice(2)); | ||
const envDirArg = argv.env_dir | ||
const platformArg = argv.platform | ||
|
||
if (!envDirArg || !platformArg) { | ||
console.error('Usage: node install-full-python-env.js --env_dir=$DIR ---platform=arc|ultra|ultra2\n'); | ||
process.exit(1); | ||
} | ||
|
||
const envDir = existingFileOrExit(path.resolve(envDirArg)); | ||
const platform = platformArg; | ||
|
||
function existingFileOrExit(filePath) { | ||
if (!fs.existsSync(filePath)) { | ||
console.error('Resource not found:', filePath); | ||
process.exit(1); | ||
} | ||
return filePath | ||
} | ||
|
||
|
||
function installPip(pythonExe, getPipFilePath) { | ||
const runGetPip = childProcess.spawnSync(pythonExe, [getPipFilePath]); | ||
console.log(runGetPip.stdout.toString()); | ||
//console.error(runGetPip.stderr.toString()); | ||
if (runGetPip.status!== 0) { | ||
console.error('Failed to install requirements'); | ||
process.exit(1); | ||
} | ||
console.log('Successfully installed pip'); | ||
} | ||
|
||
function runPipInstall(pythonExe, requirementsFilePath) { | ||
console.log(`installing python dependencies from ${requirementsFilePath}`); | ||
const pipInstall = childProcess.spawnSync(pythonExe, ['-m', 'pip', 'install', '-r', requirementsFilePath]); | ||
console.log(pipInstall.stdout.toString()); | ||
console.error(pipInstall.stderr.toString()); | ||
if (pipInstall.status!== 0) { | ||
console.error('Failed to install requirements'); | ||
process.exit(1); | ||
} | ||
console.log(`Installed dependencies from ${requirementsFilePath} successfully`); | ||
} | ||
|
||
function copyToTargetDir(sourceDir, targetDir) { | ||
fs.cpSync(sourceDir, targetDir, { recursive: true }); | ||
console.log(`copied resources to ${targetDir}`) | ||
} | ||
|
||
|
||
function main() { | ||
const targetDir = path.join(envDir, '..', `env-full-${platform}`); | ||
copyToTargetDir(envDir, targetDir) | ||
|
||
const pythonExe = existingFileOrExit(path.join(targetDir, 'python.exe')); | ||
const getPipFile = existingFileOrExit(path.join(targetDir, 'get-pip.py')); | ||
|
||
const platformSpecificRequirementsTxt = existingFileOrExit(path.join(__dirname, '..', '..','..', 'service', `requirements-${platform}.txt`)); | ||
const requirementsTxt = existingFileOrExit(path.join(__dirname, '..', '..', '..', 'service', `requirements.txt`)); | ||
|
||
installPip(pythonExe, getPipFile) | ||
runPipInstall(pythonExe, platformSpecificRequirementsTxt) | ||
runPipInstall(pythonExe, requirementsTxt) | ||
} | ||
|
||
main(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +0,0 @@ | ||
// Usage: node pack-offline.js <npm_package_res_dir> <platform> | ||
// | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const AdmZip = require('adm-zip'); | ||
const childProcess = require('child_process'); | ||
|
||
if (process.argv.length < 4) { | ||
console.error('Usage: node pack-offline.js <npm_package_res_dir> <platform>'); | ||
process.exit(1); | ||
} | ||
|
||
const packageResDir = existingFileOrExit(path.resolve(process.argv[2])); | ||
const platform = process.argv[3]; | ||
|
||
const sevenZipExe = existingFileOrExit(path.join(packageResDir, '7zr.exe')); | ||
const zippedPyenv = existingFileOrExit(path.join(packageResDir, 'env.7z')); | ||
|
||
function existingFileOrExit(filePath) { | ||
if (!fs.existsSync(filePath)) { | ||
console.error('Resource not found:', filePath); | ||
process.exit(1); | ||
} | ||
return filePath | ||
} | ||
|
||
|
||
function unzippedPackagedPyenv(pyenvArchive) { | ||
existingFileOrExit(pyenvArchive) | ||
const pyenvTargetDir = workDir | ||
|
||
if (fs.existsSync(pyenvTargetDir)) { | ||
console.warn("Removing existing offline env directory:", pyenvTargetDir); | ||
fs.rmSync(workDir, { recursive: true }); | ||
} | ||
|
||
const unzip = childProcess.spawnSync(sevenZipExe, ['x', pyenvArchive, `-o${workDir}`]); | ||
console.log(unzip.stdout.toString()); | ||
console.error(unzip.stderr.toString()); | ||
if (unzip.status !== 0) { | ||
console.error('Failed to extract env.7z'); | ||
process.exit(1); | ||
} | ||
|
||
const offlineEnvDir = existingFileOrExit(path.join(workDir, 'env')); | ||
return offlineEnvDir | ||
} | ||
|
||
function installPip(getPipFilePath, workingDir) { | ||
const runGetPip = spawn(pythonExe, [getPipFilePath], { cwd: workingDir }); | ||
runGetPip.stdout.on('data', (data) => { | ||
console.log(data.toString()); | ||
}); | ||
runGetPip.stderr.on('data', (data) => { | ||
console.error(data.toString()); | ||
}); | ||
pipInstall.on('close', (code) => { | ||
if (code !== 0) { | ||
console.error('Failed to install pip'); | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
|
||
function runPipInstall(requirementsFilePath, workingDir) { | ||
const pipInstall = spawn(pythonExe, ['-m', 'pip', 'install', '-r', requirementsFilePath], { cwd: workingDir }); | ||
pipInstall.stdout.on('data', (data) => { | ||
console.log(data.toString()); | ||
}); | ||
pipInstall.stderr.on('data', (data) => { | ||
console.error(data.toString()); | ||
}); | ||
pipInstall.on('close', (code) => { | ||
if (code !== 0) { | ||
console.error('Failed to install requirements'); | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
|
||
function zipPyenv(pyEnvDir) { | ||
const offlineEnvArchiveTargetPath = path.join(packageResDir, `env-offline-${platform}.7z`); | ||
const zip = childProcess.spawnSync((sevenZipExe, ['a', offlineEnvArchiveTargetPath, existingFileOrExit(pyEnvDir)]); | ||
console.log(zip.stdout.toString()); | ||
console.error(zip.stderr.toString()); | ||
if (zip.status !== 0) { | ||
console.error('Failed to compress offline env directory'); | ||
process.exit(1); | ||
} | ||
|
||
console.log('Offline env has been created successfully:', offlineEnvArchiveTargetPath); | ||
} | ||
|
||
function main() { | ||
const workDir = path.join(__dirname, `env-${platform}`); | ||
|
||
const offlineEnvDir = unzippedPackagedPyenv(zippedPyenv) | ||
const pythonExe = existingFileOrExit(path.join(offlineEnvDir, 'python.exe')); | ||
|
||
const getPipFile = existingFileOrExit(path.join(offlineEnvDir, 'get-pip.py')); | ||
const platformSpecificRequirementsTxt = existingFileOrExit(path.join(__dirname, '..', '..', 'service', `requirements-${platform}.txt`)); | ||
const requirementsTxt = existingFileOrExit(path.join(__dirname, '..', '..', 'service', `requirements.txt`)); | ||
|
||
installPip(getPipFile, offlineEnvDir) | ||
runPipInstall(platformSpecificRequirementsTxt, offlineEnvDir) | ||
runPipInstall(requirementsTxt, offlineEnvDir) | ||
|
||
zipPyenv(offlineEnvDir) | ||
} | ||
Oops, something went wrong.