This repository has been archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathpython.js
88 lines (74 loc) · 2.14 KB
/
python.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
class PythonRuntime {
constructor(parent, runtime, runtimeDir) {
this.parent = parent;
this.plugin = parent.plugin;
this.default = {
runtime,
runtimeDir,
libraryFolder: 'site-packages',
packageManager: 'pip',
packageManagerExtraArgs: '',
dependenciesPath: 'requirements.txt',
compatibleRuntimes: [runtime],
compatibleArchitectures: parent.compatibleArchitectures,
copyBeforeInstall: [],
packagePatterns: [
'!package.json',
'!package-lock.json',
'!node_modules/**',
],
layerOptimization: {
cleanupPatterns: [
"node_modules/**/*.pyc",
"node_modules/**/*.md",
]
}
};
this.commands = {
pip: `pip install -r ${this.default.dependenciesPath} -t .`,
};
}
init() {
const { dependenciesPath } = this.plugin.settings;
const localpackageJson = path.join(
process.cwd(),
dependenciesPath
);
try {
this.localPackage = fs.readFileSync(localpackageJson).toString();
} catch (e) {
this.plugin.log(`Error: Can not find ${localpackageJson}!`);
process.exit(1);
}
}
async isCompatibleVersion(runtime) {
const osVersion = await this.parent.run('python --version');
const [runtimeVersion] = runtime.match(/[0-9].[0-9]/);
return {
version: osVersion,
isCompatible: osVersion.startsWith(`Python ${runtimeVersion}`)
};
}
isDiff(depsA, depsB) {
if (!depsA) {
return true;
}
return depsA !== depsB;
}
async hasDependenciesChanges() {
const remotePackage = await this.plugin.bucketService.downloadDependencesFile();
let isDifferent = true;
if (remotePackage) {
this.plugin.log(`Comparing ${this.default.dependenciesPath} dependencies...`);
isDifferent = await this.isDiff(remotePackage, this.localPackage);
}
return isDifferent;
}
getDependenciesChecksum() {
return crypto.createHash('md5').update(JSON.stringify(this.localPackage)).digest('hex');
}
}
module.exports = PythonRuntime;