Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Support space in logDir #1694

Merged
merged 10 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nni_manager/common/experimentStartupInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ExperimentStartupInfo {
this.initialized = true;

if (logDir !== undefined && logDir.length > 0) {
this.logDir = path.join(logDir, getExperimentId());
this.logDir = path.join(path.normalize(logDir), getExperimentId());
} else {
this.logDir = path.join(os.homedir(), 'nni', 'experiments', getExperimentId());
}
Expand Down
28 changes: 14 additions & 14 deletions src/nni_manager/training_service/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export async function validateCodeDir(codeDir: string) : Promise<number> {
*/
export async function execMkdir(directory: string, share: boolean = false): Promise<void> {
if (process.platform === 'win32') {
await cpp.exec(`powershell.exe New-Item -Path ${directory} -ItemType "directory" -Force`);
await cpp.exec(`powershell.exe New-Item -Path "${directory}" -ItemType "directory" -Force`);
} else if (share) {
await cpp.exec(`(umask 0; mkdir -p ${directory})`);
await cpp.exec(`(umask 0; mkdir -p '${directory}')`);
} else {
await cpp.exec(`mkdir -p ${directory}`);
await cpp.exec(`mkdir -p '${directory}'`);
}

return Promise.resolve();
Expand All @@ -87,9 +87,9 @@ export async function execMkdir(directory: string, share: boolean = false): Prom
*/
export async function execCopydir(source: string, destination: string): Promise<void> {
if (process.platform === 'win32') {
await cpp.exec(`powershell.exe Copy-Item ${source} -Destination ${destination} -Recurse`);
await cpp.exec(`powershell.exe Copy-Item "${source}" -Destination "${destination}" -Recurse`);
} else {
await cpp.exec(`cp -r ${source} ${destination}`);
await cpp.exec(`cp -r '${source}' '${destination}'`);
}

return Promise.resolve();
Expand All @@ -101,9 +101,9 @@ export async function execCopydir(source: string, destination: string): Promise<
*/
export async function execNewFile(filename: string): Promise<void> {
if (process.platform === 'win32') {
await cpp.exec(`powershell.exe New-Item -Path ${filename} -ItemType "file" -Force`);
await cpp.exec(`powershell.exe New-Item -Path "${filename}" -ItemType "file" -Force`);
} else {
await cpp.exec(`touch ${filename}`);
await cpp.exec(`touch '${filename}'`);
}

return Promise.resolve();
Expand All @@ -115,9 +115,9 @@ export async function execNewFile(filename: string): Promise<void> {
*/
export function runScript(filePath: string): cp.ChildProcess {
if (process.platform === 'win32') {
return cp.exec(`powershell.exe -ExecutionPolicy Bypass -file ${filePath}`);
return cp.exec(`powershell.exe -ExecutionPolicy Bypass -file "${filePath}"`);
} else {
return cp.exec(`bash ${filePath}`);
return cp.exec(`bash '${filePath}'`);
}
}

Expand All @@ -128,9 +128,9 @@ export function runScript(filePath: string): cp.ChildProcess {
export async function execTail(filePath: string): Promise<cpp.childProcessPromise.Result> {
let cmdresult: cpp.childProcessPromise.Result;
if (process.platform === 'win32') {
cmdresult = await cpp.exec(`powershell.exe Get-Content ${filePath} -Tail 1`);
cmdresult = await cpp.exec(`powershell.exe Get-Content "${filePath}" -Tail 1`);
} else {
cmdresult = await cpp.exec(`tail -n 1 ${filePath}`);
cmdresult = await cpp.exec(`tail -n 1 '${filePath}'`);
}

return Promise.resolve(cmdresult);
Expand All @@ -142,9 +142,9 @@ export async function execTail(filePath: string): Promise<cpp.childProcessPromis
*/
export async function execRemove(directory: string): Promise<void> {
if (process.platform === 'win32') {
await cpp.exec(`powershell.exe Remove-Item ${directory} -Recurse -Force`);
await cpp.exec(`powershell.exe Remove-Item "${directory}" -Recurse -Force`);
} else {
await cpp.exec(`rm -rf ${directory}`);
await cpp.exec(`rm -rf '${directory}'`);
}

return Promise.resolve();
Expand Down Expand Up @@ -173,7 +173,7 @@ export function setEnvironmentVariable(variable: { key: string; value: string })
if (process.platform === 'win32') {
return `$env:${variable.key}="${variable.value}"`;
} else {
return `export ${variable.key}=${variable.value}`;
return `export ${variable.key}='${variable.value}'`;
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/nni_manager/training_service/local/localTrainingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,18 @@ class LocalTrainingService implements TrainingService {
const script: string[] = [];
if (process.platform === 'win32') {
script.push(
`cmd.exe /c ${localTrialConfig.command} 2>${path.join(workingDirectory, 'stderr')}`,
`cmd.exe /c ${localTrialConfig.command} 2>"${path.join(workingDirectory, 'stderr')}"`,
`$NOW_DATE = [int64](([datetime]::UtcNow)-(get-date "1/1/1970")).TotalSeconds`,
`$NOW_DATE = "$NOW_DATE" + (Get-Date -Format fff).ToString()`,
`Write $LASTEXITCODE " " $NOW_DATE | Out-File ${path.join(workingDirectory, '.nni', 'state')} -NoNewline -encoding utf8`);
`Write $LASTEXITCODE " " $NOW_DATE | Out-File "${path.join(workingDirectory, '.nni', 'state')}" -NoNewline -encoding utf8`);
} else {
script.push(`eval ${localTrialConfig.command} 2>${path.join(workingDirectory, 'stderr')}`);
script.push(`eval ${localTrialConfig.command} 2>"${path.join(workingDirectory, 'stderr')}"`);
if (process.platform === 'darwin') {
// https://superuser.com/questions/599072/how-to-get-bash-execution-time-in-milliseconds-under-mac-os-x
// Considering the worst case, write 999 to avoid negative duration
script.push(`echo $? \`date +%s999\` >${path.join(workingDirectory, '.nni', 'state')}`);
script.push(`echo $? \`date +%s999\` >'${path.join(workingDirectory, '.nni', 'state')}'`);
} else {
script.push(`echo $? \`date +%s%3N\` >${path.join(workingDirectory, '.nni', 'state')}`);
script.push(`echo $? \`date +%s%3N\` >'${path.join(workingDirectory, '.nni', 'state')}'`);
}
}

Expand All @@ -522,7 +522,7 @@ class LocalTrainingService implements TrainingService {
if (process.platform !== 'win32') {
runScriptContent.push('#!/bin/bash');
}
runScriptContent.push(`cd ${this.localTrialConfig.codeDir}`);
runScriptContent.push(`cd '${this.localTrialConfig.codeDir}'`);
for (const variable of variables) {
runScriptContent.push(setEnvironmentVariable(variable));
}
Expand Down