Skip to content

Commit 9f8e66a

Browse files
committed
poetry: Set up environment for each project individually
1 parent c5f4a54 commit 9f8e66a

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

dist/setup/index.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66081,18 +66081,33 @@ class PoetryCache extends cache_distributor_1.default {
6608166081
getCacheGlobalDirectories() {
6608266082
var e_1, _a;
6608366083
return __awaiter(this, void 0, void 0, function* () {
66084-
const paths = [];
66084+
// Same virtualenvs path may appear for different projects, hence we use a Set
66085+
const paths = new Set();
6608566086
const globber = yield glob.create(this.patterns);
66087+
const pythonLocation = yield io.which('python');
66088+
if (pythonLocation) {
66089+
core.debug(`pythonLocation is ${pythonLocation}`);
66090+
}
66091+
else {
66092+
utils_1.logWarning('python binaries were not found in PATH');
66093+
}
6608666094
try {
6608766095
for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) {
6608866096
const file = _c.value;
6608966097
const basedir = path.dirname(file);
66098+
core.debug(`Processing Poetry project at ${basedir}`);
6609066099
const poetryConfig = yield this.getPoetryConfiguration(basedir);
6609166100
const cacheDir = poetryConfig['cache-dir'];
6609266101
const virtualenvsPath = poetryConfig['virtualenvs.path'].replace('{cache-dir}', cacheDir);
66093-
paths.push(virtualenvsPath);
66102+
paths.add(virtualenvsPath);
6609466103
if (poetryConfig['virtualenvs.in-project'] === true) {
66095-
paths.push(path.join(basedir, '.venv'));
66104+
paths.add(path.join(basedir, '.venv'));
66105+
}
66106+
if (pythonLocation) {
66107+
const { exitCode, stderr } = yield exec.getExecOutput('poetry', ['env', 'use', pythonLocation], { ignoreReturnCode: true, cwd: basedir });
66108+
if (exitCode) {
66109+
utils_1.logWarning(stderr);
66110+
}
6609666111
}
6609766112
}
6609866113
}
@@ -66103,18 +66118,7 @@ class PoetryCache extends cache_distributor_1.default {
6610366118
}
6610466119
finally { if (e_1) throw e_1.error; }
6610566120
}
66106-
const pythonLocation = yield io.which('python');
66107-
if (pythonLocation) {
66108-
core.debug(`pythonLocation is ${pythonLocation}`);
66109-
const { exitCode, stderr } = yield exec.getExecOutput(`poetry env use ${pythonLocation}`, undefined, { ignoreReturnCode: true });
66110-
if (exitCode) {
66111-
utils_1.logWarning(stderr);
66112-
}
66113-
}
66114-
else {
66115-
utils_1.logWarning('python binaries were not found in PATH');
66116-
}
66117-
return paths;
66121+
return Array.from(paths);
6611866122
});
6611966123
}
6612066124
computeKeys() {

src/cache-distributions/poetry-cache.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@ class PoetryCache extends CacheDistributor {
2020
const paths = new Set<string>();
2121
const globber = await glob.create(this.patterns);
2222

23+
const pythonLocation = await io.which('python');
24+
if (pythonLocation) {
25+
core.debug(`pythonLocation is ${pythonLocation}`);
26+
} else {
27+
logWarning('python binaries were not found in PATH');
28+
}
29+
2330
for await (const file of globber.globGenerator()) {
2431
const basedir = path.dirname(file);
32+
core.debug(`Processing Poetry project at ${basedir}`);
33+
2534
const poetryConfig = await this.getPoetryConfiguration(basedir);
2635

2736
const cacheDir = poetryConfig['cache-dir'];
@@ -35,26 +44,18 @@ class PoetryCache extends CacheDistributor {
3544
if (poetryConfig['virtualenvs.in-project'] === true) {
3645
paths.add(path.join(basedir, '.venv'));
3746
}
38-
}
39-
40-
const pythonLocation = await io.which('python');
4147

42-
if (pythonLocation) {
43-
core.debug(`pythonLocation is ${pythonLocation}`);
44-
const {
45-
exitCode,
46-
stderr
47-
} = await exec.getExecOutput(
48-
`poetry env use ${pythonLocation}`,
49-
undefined,
50-
{ignoreReturnCode: true}
51-
);
48+
if (pythonLocation) {
49+
const {exitCode, stderr} = await exec.getExecOutput(
50+
'poetry',
51+
['env', 'use', pythonLocation],
52+
{ignoreReturnCode: true, cwd: basedir}
53+
);
5254

53-
if (exitCode) {
54-
logWarning(stderr);
55+
if (exitCode) {
56+
logWarning(stderr);
57+
}
5558
}
56-
} else {
57-
logWarning('python binaries were not found in PATH');
5859
}
5960

6061
return Array.from(paths);

0 commit comments

Comments
 (0)