8000 Use correct Poetry config when collecting Poetry projects · actions/setup-python@0e3a2ac · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e3a2ac

Browse files
committed
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.
1 parent 2818fdc commit 0e3a2ac

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

dist/setup/index.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63871,6 +63871,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
6387163871
step((generator = generator.apply(thisArg, _arguments || [])).next());
6387263872
});
6387363873
};
63874+
var __asyncValues = (this && this.__asyncValues) || function (o) {
63875+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
63876+
var m = o[Symbol.asyncIterator], i;
63877+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
63878+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
63879+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
63880+
};
6387463881
var __importDefault = (this && this.__importDefault) || function (mod) {
6387563882
return (mod && mod.__esModule) ? mod : { "default": mod };
6387663883
};
@@ -63886,13 +63893,29 @@ class PoetryCache extends cache_distributor_1.default {
6388663893
this.patterns = patterns;
6388763894
}
6388863895
getCacheGlobalDirectories() {
63896+
var e_1, _a;
6388963897
return __awaiter(this, void 0, void 0, function* () {
63890-
const poetryConfig = yield this.getPoetryConfiguration();
63891-
const cacheDir = poetryConfig['cache-dir'];
63892-
const virtualenvsPath = poetryConfig['virtualenvs.path'].replace('{cache-dir}', cacheDir);
63893-
const paths = [virtualenvsPath];
63894-
if (poetryConfig['virtualenvs.in-project'] === true) {
63895-
paths.push(path.join(process.cwd(), '.venv'));
63898+
const paths = [];
63899+
const globber = yield glob.create(this.patterns);
63900+
try {
63901+
for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) {
63902+
const file = _c.value;
63903+
const basedir = path.dirname(file);
63904+
const poetryConfig = yield this.getPoetryConfiguration(basedir);
63905+
const cacheDir = poetryConfig['cache-dir'];
63906+
const virtualenvsPath = poetryConfig['virtualenvs.path'].replace('{cache-dir}', cacheDir);
63907+
paths.push(virtualenvsPath);
63908+
if (poetryConfig['virtualenvs.in-project'] === true) {
63909+
paths.push(path.join(basedir, '.venv'));
63910+
}
63911+
}
63912+
}
63913+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
63914+
finally {
63915+
try {
63916+
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
63917+
}
63918+
finally { if (e_1) throw e_1.error; }
6389663919
}
6389763920
return paths;
6389863921
});
@@ -63908,12 +63931,9 @@ class PoetryCache extends cache_distributor_1.default {
6390863931
};
6390963932
});
6391063933
}
63911-
getPoetryConfiguration() {
63934+
getPoetryConfiguration(basedir) {
6391263935
return __awaiter(this, void 0, void 0, function* () {
63913-
const { stdout, stderr, exitCode } = yield exec.getExecOutput('poetry', [
63914-
'config',
63915-
'--list'
63916-
]);
63936+
const { stdout, stderr, exitCode } = yield exec.getExecOutput('poetry', ['config', '--list'], { cwd: basedir });
6391763937
if (exitCode && stderr) {
6391863938
throw new Error('Could not get cache folder path for poetry package manager');
6391963939
}

src/cache-distributions/poetry-cache.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ class PoetryCache extends CacheDistributor {
1313
}
1414

1515
protected async getCacheGlobalDirectories() {
16-
const poetryConfig = await this.getPoetryConfiguration();
16+
const paths = [];
17+
const globber = await glob.create(this.patterns);
1718

18-
const cacheDir = poetryConfig['cache-dir'];
19-
const virtualenvsPath = poetryConfig['virtualenvs.path'].replace(
20-
'{cache-dir}',
21-
cacheDir
22-
);
19+
for await (const file of globber.globGenerator()) {
20+
const basedir = path.dirname(file);
21+
const poetryConfig = await this.getPoetryConfiguration(basedir);
22+
23+
const cacheDir = poetryConfig['cache-dir'];
24+
const virtualenvsPath = poetryConfig['virtualenvs.path'].replace(
25+
'{cache-dir}',
26+
cacheDir
27+
);
2328

24-
const paths = [virtualenvsPath];
29+
paths.push(virtualenvsPath);
2530

26-
if (poetryConfig['virtualenvs.in-project'] === true) {
27-
paths.push(path.join(process.cwd(), '.venv'));
31+
if (poetryConfig['virtualenvs.in-project'] === true) {
32+
paths.push(path.join(basedir, '.venv'));
33+
}
2834
}
2935

3036
return paths;
@@ -40,11 +46,12 @@ class PoetryCache extends CacheDistributor {
4046
};
4147
}
4248

43-
private async getPoetryConfiguration() {
44-
const {stdout, stderr, exitCode} = await exec.getExecOutput('poetry', [
45-
'config',
46-
'--list'
47-
]);
49+
private async getPoetryConfiguration(basedir: string) {
50+
const {stdout, stderr, exitCode} = await exec.getExecOutput(
51+
'poetry',
52+
['config', '--list'],
53+
{cwd: basedir}
54+
);
4855

4956
if (exitCode && stderr) {
5057
throw new Error(

0 commit comments

Comments
 (0)
0