-
Notifications
You must be signed in to change notification settings - Fork 692
Add poetry caching support #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
18c67b4
Initial preparation to add support for poetry
patrick91 59cb3f4
Add untest poetry cache implementation
patrick91 95824fd
Get poetry cache implementation when requested
patrick91 1259541
Add tests
patrick91 7c950eb
Add more tests
patrick91 c275cf4
Release
patrick91 42ed863
Parse values from poetry
patrick91 415c356
Reduce test matrix
patrick91 0ebf799
Remove unused file
patrick91 b0c8e3d
Remove console.log
patrick91 aac0ef9
Build and format
patrick91 e4be7a4
Initialise pyproject.toml
patrick91 7a37d78
Update dist
patrick91 6c31eb3
Use `\n` instead of `os.EOL`
patrick91 7aa3e95
Update dist
patrick91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add untest poetry cache implementation
- Loading branch information
commit 59cb3f4919eb64c8afad1545f67330fee453e839
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import * as glob from '@actions/glob'; | ||
| import * as os from 'os'; | ||
| import * as path from 'path'; | ||
| import * as exec from '@actions/exec'; | ||
|
|
||
| import CacheDistributor from './cache-distributor'; | ||
|
|
||
| class PoetryCache extends CacheDistributor { | ||
| constructor( | ||
| private pythonVersion: string, | ||
| protected patterns: string = '**/poetry.lock' | ||
| ) { | ||
| super('poetry', patterns); | ||
| } | ||
|
|
||
| protected async getCacheGlobalDirectories() { | ||
| const poetryConfig = await this.getPoetryConfiguration(); | ||
|
|
||
| const cacheDir = poetryConfig['cache-dir']; | ||
| const virtualenvsPath = poetryConfig['virtualenvs.path'].replace( | ||
| '{cache-dir}', | ||
| cacheDir | ||
| ); | ||
|
|
||
| const paths = [virtualenvsPath]; | ||
|
|
||
| if (poetryConfig['virtualenvs.in-project'] === 'true') { | ||
| paths.push(path.join(process.cwd(), '.venv')); | ||
| } | ||
|
|
||
| return paths; | ||
| } | ||
|
|
||
| protected async computeKeys() { | ||
| const hash = await glob.hashFiles(this.patterns); | ||
| const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; | ||
| const restoreKey = undefined; | ||
| return { | ||
| primaryKey, | ||
| restoreKey | ||
| }; | ||
| } | ||
|
|
||
| private async getPoetryConfiguration() { | ||
| const {stdout, stderr, exitCode} = await exec.getExecOutput( | ||
| 'poetry config --list' | ||
| ); | ||
|
|
||
| if (exitCode && stderr) { | ||
| throw new Error( | ||
| `Could not get cache folder path for poetry package manager` | ||
| ); | ||
| } | ||
|
|
||
| const lines = stdout.split(os.EOL); | ||
|
|
||
| const config = {} as { | ||
| 'cache-dir': string; | ||
| 'virtualenvs.in-project': string; | ||
| 'virtualenvs.path': string; | ||
| }; | ||
|
|
||
| for (let line of lines) { | ||
| line = line.replace(/#.*$/, ''); | ||
|
|
||
| const [key, value] = line.split('=').map(part => part.trim()); | ||
|
|
||
| config[key as keyof typeof config] = value; | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
| } | ||
|
|
||
| export default PoetryCache; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.