Skip to content

Commit

Permalink
poetry: Set up environment for each project individually
Browse files Browse the repository at this point in the history
  • Loading branch information
oranav committed Oct 10, 2022
1 parent f6e0835 commit 37385ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
34 changes: 19 additions & 15 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66081,18 +66081,33 @@ class PoetryCache extends cache_distributor_1.default {
getCacheGlobalDirectories() {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const paths = [];
// Same virtualenvs path may appear for different projects, hence we use a Set
const paths = new Set();
const globber = yield glob.create(this.patterns);
const pythonLocation = yield io.which('python');
if (pythonLocation) {
core.debug(`pythonLocation is ${pythonLocation}`);
}
else {
utils_1.logWarning('python binaries were not found in PATH');
}
try {
for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) {
const file = _c.value;
const basedir = path.dirname(file);
core.debug(`Processing Poetry project at ${basedir}`);
const poetryConfig = yield this.getPoetryConfiguration(basedir);
const cacheDir = poetryConfig['cache-dir'];
const virtualenvsPath = poetryConfig['virtualenvs.path'].replace('{cache-dir}', cacheDir);
paths.push(virtualenvsPath);
paths.add(virtualenvsPath);
if (poetryConfig['virtualenvs.in-project'] === true) {
paths.push(path.join(basedir, '.venv'));
paths.add(path.join(basedir, '.venv'));
}
if (pythonLocation) {
const { exitCode, stderr } = yield exec.getExecOutput('poetry', ['env', 'use', pythonLocation], { ignoreReturnCode: true, cwd: basedir });
if (exitCode) {
utils_1.logWarning(stderr);
}
}
}
}
Expand All @@ -66103,18 +66118,7 @@ class PoetryCache extends cache_distributor_1.default {
}
finally { if (e_1) throw e_1.error; }
}
const pythonLocation = yield io.which('python');
if (pythonLocation) {
core.debug(`pythonLocation is ${pythonLocation}`);
const { exitCode, stderr } = yield exec.getExecOutput(`poetry env use ${pythonLocation}`, undefined, { ignoreReturnCode: true });
if (exitCode) {
utils_1.logWarning(stderr);
}
}
else {
utils_1.logWarning('python binaries were not found in PATH');
}
return paths;
return Array.from(paths);
});
}
computeKeys() {
Expand Down
35 changes: 18 additions & 17 deletions src/cache-distributions/poetry-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ class PoetryCache extends CacheDistributor {
const paths = new Set<string>();
const globber = await glob.create(this.patterns);

const pythonLocation = await io.which('python');
if (pythonLocation) {
core.debug(`pythonLocation is ${pythonLocation}`);
} else {
logWarning('python binaries were not found in PATH');
}

for await (const file of globber.globGenerator()) {
const basedir = path.dirname(file);
core.debug(`Processing Poetry project at ${basedir}`);

const poetryConfig = await this.getPoetryConfiguration(basedir);

const cacheDir = poetryConfig['cache-dir'];
Expand All @@ -35,26 +44,18 @@ class PoetryCache extends CacheDistributor {
if (poetryConfig['virtualenvs.in-project'] === true) {
paths.add(path.join(basedir, '.venv'));
}
}

const pythonLocation = await io.which('python');

if (pythonLocation) {
core.debug(`pythonLocation is ${pythonLocation}`);
const {
exitCode,
stderr
} = await exec.getExecOutput(
`poetry env use ${pythonLocation}`,
undefined,
{ignoreReturnCode: true}
);
if (pythonLocation) {
const {exitCode, stderr} = await exec.getExecOutput(
'poetry',
['env', 'use', pythonLocation],
{ignoreReturnCode: true, cwd: basedir}
);

if (exitCode) {
logWarning(stderr);
if (exitCode) {
logWarning(stderr);
}
}
} else {
logWarning('python binaries were not found in PATH');
}

return Array.from(paths);
Expand Down

0 comments on commit 37385ae

Please sign in to comment.