Skip to content

Commit

Permalink
costa: use ~/.pipcook/plugins/.pip as the default cache dir (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkie committed Jul 14, 2020
1 parent e209b14 commit 36bb8dc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/costa/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function emitStart(message: PluginMessage): Promise<void> {
recv(PluginOperator.WRITE);
}
} catch (err) {
recv(PluginOperator.WRITE, 'error', err?.message);
recv(PluginOperator.WRITE, 'error', err?.stack);
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/costa/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ export class CostaRuntime {
if (pyIndex) {
args = args.concat([ '-i', pyIndex ]);
}
args = args.concat([ '--default-timeout=1000' ]);
args = args.concat([
'--default-timeout=1000',
`--cache-dir=${this.options.installDir}/.pip`
]);
await spawnAsync(`${envDir}/bin/pip3`, args);
}
} else {
Expand Down
26 changes: 20 additions & 6 deletions packages/costa/src/runtime_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { CostaRuntime } from './runtime';
import { PluginPackage } from '.';
import { stat } from 'fs-extra';

console.log(process.env.NODE_ENV);
const INSTALL_SPECS_TIMEOUT = 180 * 1000;

describe('create a costa runtime', () => {
const costa = new CostaRuntime({
installDir: path.join(__dirname, '../.tests/plugins'),
Expand All @@ -24,7 +25,20 @@ describe('create a costa runtime', () => {
'node_modules',
collectCsv.name
));
}, 180 * 1000);
}, INSTALL_SPECS_TIMEOUT);

it('should fetch a python plugin and install fron local', async () => {
const bayesClassifier = await costa.fetch('../plugins/model-define/bayesian-model-define');
expect(bayesClassifier.name).toBe('@pipcook/plugins-bayesian-model-define');
expect(bayesClassifier.pipcook.category).toBe('modelDefine');
await costa.install(bayesClassifier);
// make sure js packages are installed.
await stat(path.join(costa.options.installDir, 'node_modules', bayesClassifier.name));
// make sure python packages are installed.
await stat(path.join(costa.options.installDir, 'conda_envs', `${bayesClassifier.name}@${bayesClassifier.version}`));
// make sure python caches are used.
await stat(path.join(costa.options.installDir, '.pip/selfcheck.json'));
}, INSTALL_SPECS_TIMEOUT);

it('should fetch a plugin and install from tarball', async () => {
const collectCsvWithSpecificVer = await costa.fetch('https://registry.npmjs.org/@pipcook/plugins-csv-data-collect/-/plugins-csv-data-collect-0.5.8.tgz');
Expand All @@ -36,7 +50,7 @@ describe('create a costa runtime', () => {
'node_modules',
collectCsvWithSpecificVer.name
));
}, 180 * 1000);
}, INSTALL_SPECS_TIMEOUT);

it('should fetch a plugin from npm', async () => {
const collectCsvWithSpecificVer = await costa.fetch('@pipcook/plugins-csv-data-collect@0.5.8');
Expand All @@ -62,7 +76,7 @@ describe('create a costa runtime', () => {
'node_modules',
collectCsv.name
));
}, 180 * 1000);
}, INSTALL_SPECS_TIMEOUT);

it('should install the package with conda packages', async () => {
const bayesClassifier = await costa.fetch('../plugins/model-define/bayesian-model-define');
Expand All @@ -77,7 +91,7 @@ describe('create a costa runtime', () => {
'conda_envs',
`${bayesClassifier.name}@${bayesClassifier.version}`
));
}, 180 * 1000);
}, INSTALL_SPECS_TIMEOUT);

it('should start the package', async () => {
const runnable = await costa.createRunnable({ id: 'foobar' });
Expand All @@ -86,5 +100,5 @@ describe('create a costa runtime', () => {
url: 'http://ai-sample.oss-cn-hangzhou.aliyuncs.com/image_classification/datasets/textClassification.zip'
});
await runnable.destroy();
}, 180 * 1000);
}, INSTALL_SPECS_TIMEOUT);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"compile": "tsc -b tsconfig.json && cp -r ./src/assets ./dist/"
},
"author": "",
"license": "ISC",
"license": "Apache 2.0",
"dependencies": {
"@pipcook/boa": "^1.0.3",
"@pipcook/pipcook-core": "^1.0.3",
Expand All @@ -39,7 +39,7 @@
"python": "3.7",
"dependencies": {
"jieba": "*",
"sklearn": "*"
"scikit-learn": "*"
}
}
}

0 comments on commit 36bb8dc

Please sign in to comment.