forked from actions/setup-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresearcher-tools.ts
More file actions
73 lines (67 loc) · 1.69 KB
/
researcher-tools.ts
File metadata and controls
73 lines (67 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as core from '@actions/core';
import {exec} from '@actions/exec';
/**
* Common packages for research and data science workflows
*/
const RESEARCH_PACKAGES = [
'numpy',
'pandas',
'scipy',
'matplotlib',
'jupyter',
'jupyterlab',
'scikit-learn',
'seaborn'
];
/**
* Installs common research tools and packages
*/
export async function installResearcherTools(): Promise<void> {
core.info('Installing researcher tools and packages...');
try {
core.info(`Installing packages: ${RESEARCH_PACKAGES.join(', ')}`);
await exec('python', [
'-m',
'pip',
'install',
'--upgrade',
...RESEARCH_PACKAGES
]);
core.info('Successfully installed researcher tools');
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
core.warning(
`Failed to install some researcher tools: ${errorMessage}. Continuing...`
);
}
}
/**
* Verifies that research tools are properly installed
*/
export async function verifyResearcherTools(): Promise<boolean> {
core.info('Verifying researcher tools installation...');
try {
// Verify key packages can be imported
const verifyScript = `
import sys
packages = ['numpy', 'pandas', 'scipy', 'matplotlib', 'jupyter']
failed = []
for pkg in packages:
try:
__import__(pkg)
except ImportError:
failed.append(pkg)
if failed:
print(f"Failed to import: {', '.join(failed)}")
sys.exit(1)
else:
print("All researcher tools verified successfully")
sys.exit(0)
`;
await exec('python', ['-c', verifyScript]);
return true;
} catch (error) {
core.warning('Some researcher tools could not be verified');
return false;
}
}