mirror of
https://github.com/actions/setup-python.git
synced 2025-07-01 23:23:46 +00:00
Use correct Poetry config when collecting Poetry projects
When collecting Poetry projects for caching, a '**/poetry.lock' glob is used. However, in order to process the Poetry configuration, the "poetry" command is run from the repo's root directory; this causes Poetry to return an invalid configuration when there is a Poetry project inside an inner directory. Instead of running a single Poetry command, glob for the same pattern, and run a Poetry command for every discovered project.
This commit is contained in:
parent
2c3dd9e7e2
commit
748f3e6907
2 changed files with 52 additions and 25 deletions
|
@ -16,18 +16,24 @@ class PoetryCache extends CacheDistributor {
|
|||
}
|
||||
|
||||
protected async getCacheGlobalDirectories() {
|
||||
const poetryConfig = await this.getPoetryConfiguration();
|
||||
const paths = [];
|
||||
const globber = await glob.create(this.patterns);
|
||||
|
||||
const cacheDir = poetryConfig['cache-dir'];
|
||||
const virtualenvsPath = poetryConfig['virtualenvs.path'].replace(
|
||||
'{cache-dir}',
|
||||
cacheDir
|
||||
);
|
||||
for await (const file of globber.globGenerator()) {
|
||||
const basedir = path.dirname(file);
|
||||
const poetryConfig = await this.getPoetryConfiguration(basedir);
|
||||
|
||||
const paths = [virtualenvsPath];
|
||||
const cacheDir = poetryConfig['cache-dir'];
|
||||
const virtualenvsPath = poetryConfig['virtualenvs.path'].replace(
|
||||
'{cache-dir}',
|
||||
cacheDir
|
||||
);
|
||||
|
||||
if (poetryConfig['virtualenvs.in-project'] === true) {
|
||||
paths.push(path.join(process.cwd(), '.venv'));
|
||||
paths.push(virtualenvsPath);
|
||||
|
||||
if (poetryConfig['virtualenvs.in-project'] === true) {
|
||||
paths.push(path.join(basedir, '.venv'));
|
||||
}
|
||||
}
|
||||
|
||||
const pythonLocation = await io.which('python');
|
||||
|
@ -63,11 +69,12 @@ class PoetryCache extends CacheDistributor {
|
|||
};
|
||||
}
|
||||
|
||||
private async getPoetryConfiguration() {
|
||||
const {stdout, stderr, exitCode} = await exec.getExecOutput('poetry', [
|
||||
'config',
|
||||
'--list'
|
||||
]);
|
||||
private async getPoetryConfiguration(basedir: string) {
|
||||
const {stdout, stderr, exitCode} = await exec.getExecOutput(
|
||||
'poetry',
|
||||
['config', '--list'],
|
||||
{cwd: basedir}
|
||||
);
|
||||
|
||||
if (exitCode && stderr) {
|
||||
throw new Error(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue