Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Esser <[email protected]>
  • Loading branch information
florianesser-tng committed Nov 26, 2024
1 parent f9c7cfa commit 7325383
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 76 deletions.
4 changes: 2 additions & 2 deletions WebUI/build/build-config-offline.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"to": "7zr.exe"
},
{
"from": "external/env-offline-${env.PLATFORM}.7z",
"to": "env-offline.7z"
"from": "external/env.7z",
"to": "env.7z"
},
{
"from": "external/model_config.json",
Expand Down
8 changes: 8 additions & 0 deletions WebUI/build/scripts/install-full-python-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,17 @@ function copyToTargetDir(sourceDir, targetDir) {
console.log(`copied resources to ${targetDir}`)
}

function prepareTargetDir(targetDir) {
if (fs.existsSync(targetDir)) {
console.log("clearing previous env dir ${targetDir}")
fs.rmSync(targetDir, { recursive: true });
}
}


function main() {
const targetDir = path.join(envDir, '..', `env-full-${platform}`);
prepareTargetDir(targetDir)
copyToTargetDir(envDir, targetDir)

const pythonExe = existingFileOrExit(path.join(targetDir, 'python.exe'));
Expand Down
Empty file.
Empty file removed WebUI/build/scripts/prebuild.js
Empty file.
70 changes: 15 additions & 55 deletions WebUI/build/scripts/prepare-python-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,12 @@ if (!buildResourcesDirArg || !targetDirArg) {

const envResourcesDir = path.resolve(buildResourcesDirArg);
const targetDir = path.resolve(targetDirArg);
const webUIBuildDir = path.join(__dirname, '..', '..');
const pythonEmbedDir = path.join(webUIBuildDir, '..', 'env');

const envResourcesFiles = fs.readdirSync(envResourcesDir);
const pythonEmbedZipFile = path.join(envResourcesDir, envResourcesFiles.find((fileName) => { return fileName.startsWith('python') && fileName.endsWith('.zip') }));
const condaDir = path.join(envResourcesDir, envResourcesFiles.find((fileName) => { return fileName.includes('conda') }));
const condaBinDir = path.join(condaDir, 'Library', 'bin');
const getPipFile = path.join(envResourcesDir, 'get-pip.py');
const sevenZipExe = path.join(envResourcesDir, '7zr.exe')
const sevenZipBinary = () => {
if (childProcess.execSync('which 7z').toString().includes('7z')) {
return "7z";
} else if (fs.existsSync(sevenZipExe)) {
return sevenZipExe;
} else {
console.error('No 7z executable found');
process.exit(1);
}
}

function verifyFilesExist() {
console.log('verifying all required files exist.')
Expand All @@ -49,11 +36,6 @@ function verifyFilesExist() {
process.exit(1);
}

if (!fs.existsSync(sevenZipExe)) {
console.error('File not found:', sevenZipExe);
process.exit(1);
}

// check whether libuv has been installed in the conda env
const uvDll = path.join(condaBinDir, 'uv.dll');
if (!fs.existsSync(uvDll)) {
Expand All @@ -75,17 +57,16 @@ function preparePythonEnvDir(pyEnvTargetPath) {
}
}

function createPythonEnvFromEmbedabblePythonZip() {
const pyEnvTargetPath = pythonEmbedDir
preparePythonEnvDir(pyEnvTargetPath);
function createPythonEnvFromEmbedabblePythonZip(targetDir, pythonEmbedZipFile) {
preparePythonEnvDir(targetDir);
console.log('Creating python env.')
const pythonEmbed = new AdmZip(pythonEmbedZipFile);
pythonEmbed.extractAllTo(pyEnvTargetPath, true);
console.log('Extracted embeddable python to:', pyEnvTargetPath);
pythonEmbed.extractAllTo(targetDir, true);
console.log('Extracted embeddable python to:', targetDir);

// configure path of python env:
console.log('Patching path of python environment');
const pthFile = path.join(pyEnvTargetPath, 'python311._pth');
const pthFile = path.join(targetDir, 'python311._pth');
const pthContent = `
python311.zip
.
Expand All @@ -98,13 +79,13 @@ import site
console.log('patched python paths');

console.log('Copying get-pip.py');
const getPipDest = path.join(pyEnvTargetPath, 'get-pip.py');
const getPipDest = path.join(targetDir, 'get-pip.py');
fs.copyFileSync(getPipFile, getPipDest);
console.log('Copied get-pip.py to:', getPipDest);
return pyEnvTargetPath;
return targetDir;
}

function patchCondaDllsIntoPythonEnv(pyEnvDirPath) {
function patchCondaDllsIntoPythonEnv(pyEnvDirPath, condaBinDir) {
console.log('Copying conda dlls to python env');

for (const condaDll of fs.readdirSync(condaBinDir)) {
Expand All @@ -115,40 +96,19 @@ function patchCondaDllsIntoPythonEnv(pyEnvDirPath) {
console.log('Copied conda dlls into:', pyEnvDirPath);
}

function compressPythonEnvDirectory(pyEnvDirPath) {
const outputFile = path.join(pythonEmbedDir, 'env.7z');
console.log(`7zipping env directory into ${outputFile}`)
if (fs.existsSync(outputFile)) {
console.warn("Removing existing 7z file:", outputFile);
fs.rmSync(outputFile);
function prepareTargetDir(targetDir) {
if (fs.existsSync(targetDir)) {
console.log(`clearing previous env dir ${targetDir}`)
fs.rmSync(targetDir, { recursive: true });
}

const zip = childProcess.spawnSync(sevenZipBinary(), ['a', outputFile, pyEnvDirPath]);
console.log(zip.stdout.toString());
console.error(zip.stderr.toString());
if (zip.status !== 0) {
console.error('Failed to compress env directory');
process.exit(1);
}

console.log('Compressed env directory to:', outputFile);
return outputFile
}

function copyToTargetDir(filePaths) {
for (const sourceFilePath of filePaths) {
const destinationPath = path.join(targetDir, path.basename(sourceFilePath));
fs.copyFileSync(sourceFilePath, destinationPath);
console.log(`copied ${path.basename(sourceFilePath)} into ${targetDir}`)
}
}

function main() {
verifyFilesExist();
const pyEnvPath = createPythonEnvFromEmbedabblePythonZip();
patchCondaDllsIntoPythonEnv(pyEnvPath);
//const sevenZippedPyenv = compressPythonEnvDirectory(pyEnvPath);
//copyToTargetDir([sevenZippedPyenv, sevenZipExe]);
prepareTargetDir(targetDir)
createPythonEnvFromEmbedabblePythonZip(targetDir, pythonEmbedZipFile);
patchCondaDllsIntoPythonEnv(targetDir, condaBinDir);
}

main();
22 changes: 15 additions & 7 deletions WebUI/build/scripts/provide-electron-build-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,40 @@ function symlinkBackendDir(backendDir, serviceLink) {
}


function zipPythonEnv(sevenZipExe, pythonEnvDir, targetDir) {
const envArchiveTargetPath = path.join(targetDir, `env.7z`);
console.log(`zipping offline env to ${envArchiveTargetPath}`);
function zipPythonEnv(sevenZipExe, pythonEnvDir, targetPath) {
console.log(`zipping ${pythonEnvDir} to ${targetPath}`);

const zip = childProcess.spawnSync(sevenZipExe, ['a', envArchiveTargetPath, pythenEnvDir]);
const zip = childProcess.spawnSync(sevenZipExe, ['a', targetPath, , "env"]);
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:', envArchiveTargetPath);
console.log('Offline env has been compressed to:', targetPath);
const renameRootFolder = childProcess.spawnSync(sevenZipExe, ['rn', targetPath, fie.basename(pythenEnvDir), "env"]);
console.log(zip.stdout.toString());
console.error(zip.stderr.toString());
if (zip.status !== 0) {
console.error('Failed to rename root folder to expected name');
process.exit(1);
}
}

function copyResources(targetDir, ...files) {
for (const file of files) {
fs.copyFileSync(src, path.join(targetDir, path.basename(filePath)));
console.log('Copied:', src, 'to:', dest);
console.log(file)
fs.copyFileSync(file, path.join(targetDir, path.basename(file)));
console.log('Copied:', file, 'to:', path.join(targetDir, path.basename(file)));
}
}

function main() {
const sevenZipExe = path.join(buildResourcesDir, '7zr.exe');

zipPythonEnv(sevenZipExe, pythenEnvDir, path.join(targetDir, `env.7z`));

symlinkBackendDir(backendDir, path.join(targetDir, 'service'))
copyResources(targetDir,
sevenZipExe
Expand Down
12 changes: 5 additions & 7 deletions WebUI/build/scripts/render-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ if (!platform) {
process.exit(1);
}

console.log(onlineInstallerFlag)

// Function to render the template with environment variables
function renderTemplate(templatePath, outputPath, variables) {
// Read the template content
Expand Down Expand Up @@ -40,16 +38,16 @@ function renderTemplate(templatePath, outputPath, variables) {
});
}

function installerTemplate() {
function installerFileName() {
if (onlineInstallerFlag) {
return 'installer.nsh.template'
return 'installer.nsh'
} else {
return 'installer-offline.nsh.template'
return 'installer-offline.nsh'
}
}

const templatePath = path.join(buildDir, installerTemplate());
const outputPath = path.join(buildDir, 'installer.nsh');
const templatePath = path.join(buildDir, installerFileName() + '.template');
const outputPath = path.join(buildDir, installerFileName());
const variables = {
PLATFORM: platform
};
Expand Down
16 changes: 11 additions & 5 deletions WebUI/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
"preview": "vite preview",

"fetch-build-resources": "cross-env node ./build/scripts/fetch-python-package-resources.js --target_dir=../build_resources",
"prepare-python-env": "cross-env node ./build/scripts/prepare-python-env.js --build_resources_dir=../build_resources --target_dir=../env",
"install-full-python-env": "cross-env node ./build/scripts/install-full-python-env.js --env_dir=../env",

"prepare-python-env": "cross-env node ./build/scripts/prepare-python-env.js --build_resources_dir=../build_resources --target_dir=../env-slim",
"install-full-python-env": "cross-env node ./build/scripts/install-full-python-env.js --env_dir=../env-slim",
"provide-electron-build-resources": "cross-env node build/scripts/provide-electron-build-resources.js --build_resources_dir=../build_resources --backend_dir=../service --target_dir=./external",

"prepare-build:arc": "cross-env npm run prepare-python-env && npm run provide-electron-build-resources -- --python_env_dir=../env-slim && node ./build/scripts/render-template.js --online_installer --platform=arc",
"prepare-build:arc-offline": "cross-env && npm run prepare-python-env && npm run install-full-python-env -- --platform=arc && npm run provide-electron-build-resources -- --python_env_dir=../env-full-arc && node ./build/scripts/render-template.js --no-online_installer --platform=arc",
"prepare-build:ultra": "cross-env npm run prepare-python-env && npm run provide-electron-build-resources -- --python_env_dir=../env-slim && node ./build/scripts/render-template.js --online_installer --platform=ultra",
"prepare-build:ultra-offline": "cross-env npm run prepare-python-env && npm run install-full-python-env -- --platform=ultra && npm run provide-electron-build-resources -- --python_env_dir=../env-full-ultra && node ./build/scripts/render-template.js --no-online_installer --platform=ultra",
"prepare-build:ultra2": "cross-env npm run prepare-python-env && npm run provide-electron-build-resources -- --python_env_dir=../env-slim && node ./build/scripts/render-template.js --online_installer --platform=ultra2",
"prepare-build:ultra2-offline": "cross-env npm run prepare-python-env && npm run install-full-python-env -- --platform=ultra2 && npm run provide-electron-build-resources -- --python_env_dir=../env-full-ultra2 && node ./build/scripts/render-template.js --no-online_installer --platform=ultra2",

"build:arc": "cross-env-shell PLATFORM=\"arc\" VITE_PLATFORM_TITLE=\"for Intel® Arc™\" \"vue-tsc && vite build && electron-builder --config build/build-config.json --win --x64\"",
"build:arc-offline": "cross-env-shell PLATFORM=\"arc\" VITE_PLATFORM_TITLE=\"for Intel® Arc™\" \"vue-tsc && vite build && electron-builder --config build/build-config-offline.json --win --x64\"",

"build:ultra": "cross-env-shell PLATFORM=\"ultra\" VITE_PLATFORM_TITLE=\"for Intel® Core™ Ultra\" \"vue-tsc && vite build && electron-builder --config build/build-config.json --win --x64\"",
"build:ultra-offline": "cross-env-shell PLATFORM=\"ultra\" VITE_PLATFORM_TITLE=\"for Intel® Core™ Ultra\" \"vue-tsc && vite build && electron-builder --config build/build-config-offline.json --win --x64\"",

"build:ultra2": "cross-env-shell PLATFORM=\"ultra2\" VITE_PLATFORM_TITLE=\"for Intel® Core™ Ultra Series 2\" \"vue-tsc && vite build && electron-builder --config build/build-config.json --win --x64\"",
"build:ultra2-offline": "cross-env-shell PLATFORM=\"ultra2\" VITE_PLATFORM_TITLE=\"for Intel® Core™ Ultra Series 2\" \"npm run pack-offline ultra2 && npm run prebuild && vue-tsc && vite build && electron-builder --config build/build-config-offline.json --win --x64\"",
"build:ultra2-offline": "cross-env-shell PLATFORM=\"ultra2\" VITE_PLATFORM_TITLE=\"for Intel® Core™ Ultra Series 2\" \"npm run pack-offline ultra2 && npm run prebuild && vue-tsc && vite build && electron-builder --config build/build-config-offline.json --win --x64\""
},
"dependencies": {
"@radix-icons/vue": "^1.0.0",
Expand Down

0 comments on commit 7325383

Please sign in to comment.