Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 59cb3f4

Browse filesBrowse files
committed
Add untest poetry cache implementation
1 parent 18c67b4 commit 59cb3f4
Copy full SHA for 59cb3f4

File tree

Expand file treeCollapse file tree

1 file changed

+75
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+75
-0
lines changed
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import * as glob from '@actions/glob';
2+
import * as os from 'os';
3+
import * as path from 'path';
4+
import * as exec from '@actions/exec';
5+
6+
import CacheDistributor from './cache-distributor';
7+
8+
class PoetryCache extends CacheDistributor {
9+
constructor(
10+
private pythonVersion: string,
11+
protected patterns: string = '**/poetry.lock'
12+
) {
13+
super('poetry', patterns);
14+
}
15+
16+
protected async getCacheGlobalDirectories() {
17+
const poetryConfig = await this.getPoetryConfiguration();
18+
19+
const cacheDir = poetryConfig['cache-dir'];
20+
const virtualenvsPath = poetryConfig['virtualenvs.path'].replace(
21+
'{cache-dir}',
22+
cacheDir
23+
);
24+
25+
const paths = [virtualenvsPath];
26+
27+
if (poetryConfig['virtualenvs.in-project'] === 'true') {
28+
paths.push(path.join(process.cwd(), '.venv'));
29+
}
30+
31+
return paths;
32+
}
33+
34+
protected async computeKeys() {
35+
const hash = await glob.hashFiles(this.patterns);
36+
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
37+
const restoreKey = undefined;
38+
return {
39+
primaryKey,
40+
restoreKey
41+
};
42+
}
43+
44+
private async getPoetryConfiguration() {
45+
const {stdout, stderr, exitCode} = await exec.getExecOutput(
46+
'poetry config --list'
47+
);
48+
49+
if (exitCode && stderr) {
50+
throw new Error(
51+
`Could not get cache folder path for poetry package manager`
52+
);
53+
}
54+
55+
const lines = stdout.split(os.EOL);
56+
57+
const config = {} as {
58+
'cache-dir': string;
59+
'virtualenvs.in-project': string;
60+
'virtualenvs.path': string;
61+
};
62+
63+
for (let line of lines) {
64+
line = line.replace(/#.*$/, '');
65+
66+
const [key, value] = line.split('=').map(part => part.trim());
67+
68+
config[key as keyof typeof config] = value;
69+
}
70+
71+
return config;
72+
}
73+
}
74+
75+
export default PoetryCache;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.