Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(monorepo): ensure local venv is used for all subproject tasks #587

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions packages/monorepo/src/components/nx-configurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from "path";
import { Component, JsonFile, Project, Task } from "projen";
import { JavaProject } from "projen/lib/java";
import { NodePackageManager, NodeProject } from "projen/lib/javascript";
import { PythonProject } from "projen/lib/python";
import { Poetry, PythonProject } from "projen/lib/python";
import { NxProject } from "./nx-project";
import { NxWorkspace } from "./nx-workspace";
import { Nx } from "../nx-types";
Expand Down Expand Up @@ -136,19 +136,26 @@ export class NxConfigurator extends Component implements INxProjectCore {
this.nx.affected.defaultBase = options?.defaultReleaseBranch ?? "mainline";
}

public patchPoetryInstall(project: PythonProject): void {
const installTask = project.tasks.tryFind("install");

if (installTask?.steps[0]?.exec !== "unset VIRTUAL_ENV") {
installTask?.env("VIRTUAL_ENV", "");
installTask?.prependExec("unset VIRTUAL_ENV");
public patchPoetryEnv(project: PythonProject): void {
// Since the root monorepo is a poetry project and sets the VIRTUAL_ENV, and poetry env info -p will print
// the virtual env set in the VIRTUAL_ENV variable if set, we need to unset it to ensure the local project's
// env is used.
if (ProjectUtils.isNamedInstanceOf(project.depsManager as any, Poetry)) {
project.tasks.addEnvironment(
"VIRTUAL_ENV",
"$(env -u VIRTUAL_ENV poetry env info -p || echo '')"
);
project.tasks.addEnvironment(
"PATH",
"$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)"
);
}
}

public patchPythonProjects(projects: Project[]): void {
projects.forEach((p) => {
if (ProjectUtils.isNamedInstanceOf(p, PythonProject)) {
this.patchPoetryInstall(p);
this.patchPoetryEnv(p);
}
this.patchPythonProjects(p.subprojects);
});
Expand Down
26 changes: 4 additions & 22 deletions packages/monorepo/test/__snapshots__/monorepo.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading