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 0a5c926

Browse filesBrowse 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 0a5c926
Copy full SHA for 0a5c926

File tree

Expand file treeCollapse file tree

4 files changed

+56
-26
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+56
-26
lines changed

‎__tests__/cache-restore.test.ts

Copy file name to clipboardExpand all lines: __tests__/cache-restore.test.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ describe('restore-cache', () => {
1010
'd8110e0006d7fb5ee76365d565eef9d37df1d11598b912d3eb66d398d57a1121';
1111
const requirementsLinuxHash =
1212
'2d0ff7f46b0e120e3d3294db65768b474934242637b9899b873e6283dfd16d7c';
13+
// poetry.lock is hashed twice:
14+
// sha256(sha256(data/poetry.lock) || sha256(data/inner/poetry.lock))
1315
const poetryLockHash =
14-
'571bf984f8d210e6a97f854e479fdd4a2b5af67b5fdac109ec337a0ea16e7836';
16+
'f24ea1ad73968e6c8d80c16a093ade72d9332c433aeef979a0dd943e6a99b2ab';
1517
const poetryConfigOutput = `
1618
cache-dir = "/Users/patrick/Library/Caches/pypoetry"
1719
experimental.new-installer = false

‎__tests__/data/inner/poetry.lock

Copy file name to clipboardExpand all lines: __tests__/data/inner/poetry.lock
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/setup/index.js

Copy file name to clipboardExpand all lines: dist/setup/index.js
+31-11Lines 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

Copy file name to clipboardExpand all lines: src/cache-distributions/poetry-cache.ts
+21-14Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.