diff --git a/packages/monorepo/src/components/nx-configurator.ts b/packages/monorepo/src/components/nx-configurator.ts index 6c24c8ccf..71a4c376d 100644 --- a/packages/monorepo/src/components/nx-configurator.ts +++ b/packages/monorepo/src/components/nx-configurator.ts @@ -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"; @@ -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); }); diff --git a/packages/monorepo/test/__snapshots__/monorepo.test.ts.snap b/packages/monorepo/test/__snapshots__/monorepo.test.ts.snap index bd2fea703..6a6546162 100644 --- a/packages/monorepo/test/__snapshots__/monorepo.test.ts.snap +++ b/packages/monorepo/test/__snapshots__/monorepo.test.ts.snap @@ -9006,8 +9006,8 @@ cython_debug/ "packages/consumer/.projen/tasks.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -9041,14 +9041,8 @@ cython_debug/ }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "poetry update", }, @@ -9365,8 +9359,8 @@ cython_debug/ "packages/library/.projen/tasks.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -9400,14 +9394,8 @@ cython_debug/ }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "poetry update", }, @@ -11818,14 +11806,8 @@ cython_debug/ }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "pip install --upgrade pip", }, diff --git a/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap b/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap index f0a4b6955..06c4830ed 100644 --- a/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap +++ b/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap @@ -5956,8 +5956,8 @@ pyproject.toml "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { "AWS_PDK_VERSION": "0.0.0", - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -6002,14 +6002,8 @@ pyproject.toml }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "mkdir -p openapi_java_python_runtime && touch openapi_java_python_runtime/__init__.py", }, @@ -12033,8 +12027,8 @@ mocks "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { "AWS_PDK_VERSION": "0.0.0", - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -12082,14 +12076,8 @@ mocks }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "mkdir -p openapi_python_python_infra && touch openapi_python_python_infra/__init__.py", }, @@ -13075,8 +13063,8 @@ pyproject.toml "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { "AWS_PDK_VERSION": "0.0.0", - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -13121,14 +13109,8 @@ pyproject.toml }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "mkdir -p openapi_python_python_runtime && touch openapi_python_python_runtime/__init__.py", }, @@ -20783,8 +20765,8 @@ pyproject.toml "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { "AWS_PDK_VERSION": "0.0.0", - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -20829,14 +20811,8 @@ pyproject.toml }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "mkdir -p openapi_typescript_python_runtime && touch openapi_typescript_python_runtime/__init__.py", }, @@ -35370,8 +35346,8 @@ pyproject.toml "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { "AWS_PDK_VERSION": "0.0.0", - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -35416,14 +35392,8 @@ pyproject.toml }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "mkdir -p smithy_java_python_runtime && touch smithy_java_python_runtime/__init__.py", }, @@ -53590,8 +53560,8 @@ mocks "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { "AWS_PDK_VERSION": "0.0.0", - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -53639,14 +53609,8 @@ mocks }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "mkdir -p smithy_python_python_infra && touch smithy_python_python_infra/__init__.py", }, @@ -54632,8 +54596,8 @@ pyproject.toml "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { "AWS_PDK_VERSION": "0.0.0", - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -54678,14 +54642,8 @@ pyproject.toml }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "mkdir -p smithy_python_python_runtime && touch smithy_python_python_runtime/__init__.py", }, @@ -62526,8 +62484,8 @@ pyproject.toml "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "env": { "AWS_PDK_VERSION": "0.0.0", - "PATH": "$(echo $(poetry env info -p)/bin:$PATH)", - "VIRTUAL_ENV": "$(poetry env info -p)", + "PATH": "$(echo $(env -u VIRTUAL_ENV poetry env info -p || echo '')/bin:$PATH)", + "VIRTUAL_ENV": "$(env -u VIRTUAL_ENV poetry env info -p || echo '')", }, "tasks": { "build": { @@ -62572,14 +62530,8 @@ pyproject.toml }, "install": { "description": "Install and upgrade dependencies", - "env": { - "VIRTUAL_ENV": "", - }, "name": "install", "steps": [ - { - "exec": "unset VIRTUAL_ENV", - }, { "exec": "mkdir -p smithy_typescript_python_runtime && touch smithy_typescript_python_runtime/__init__.py", },