diff --git a/packages/nx-python/src/dependency/update-dependency.ts b/packages/nx-python/src/dependency/update-dependency.ts index 831afb7..bc5da6b 100644 --- a/packages/nx-python/src/dependency/update-dependency.ts +++ b/packages/nx-python/src/dependency/update-dependency.ts @@ -65,8 +65,7 @@ export function updateDependents( console.log(chalk`\nUpdating project {bold ${dep}}`); const depConfig = workspace.projects[dep]; - const pkgName = getProjectPackageName(context, projectName); - updateProject(pkgName, depConfig.root, updateLockOnly); + updateProject(depConfig.root, updateLockOnly); updateDependents( context, diff --git a/packages/nx-python/src/executors/add/executor.spec.ts b/packages/nx-python/src/executors/add/executor.spec.ts index ebfe3da..ca58299 100644 --- a/packages/nx-python/src/executors/add/executor.spec.ts +++ b/packages/nx-python/src/executors/add/executor.spec.ts @@ -422,7 +422,7 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(4); + expect(spawn.sync).toHaveBeenCalledTimes(7); expect(spawn.sync).toHaveBeenNthCalledWith(1, 'poetry', ['add', 'numpy'], { cwd: 'libs/shared1', shell: false, @@ -431,33 +431,48 @@ version = "1.0.0" expect(spawn.sync).toHaveBeenNthCalledWith( 2, 'poetry', - ['update', 'shared1'], + ['lock', '--no-update'], { cwd: 'libs/lib1', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(3, 'poetry', ['install'], { + cwd: 'libs/lib1', + shell: false, + stdio: 'inherit', + }); expect(spawn.sync).toHaveBeenNthCalledWith( - 3, + 4, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(5, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(spawn.sync).toHaveBeenNthCalledWith( - 4, + 6, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app1', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(7, 'poetry', ['install'], { + cwd: 'apps/app1', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); @@ -554,7 +569,7 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(4); + expect(spawn.sync).toHaveBeenCalledTimes(7); expect(spawn.sync).toHaveBeenNthCalledWith(1, 'poetry', ['add', 'numpy'], { cwd: 'libs/shared1', shell: false, @@ -563,33 +578,48 @@ version = "1.0.0" expect(spawn.sync).toHaveBeenNthCalledWith( 2, 'poetry', - ['update', 'shared1'], + ['lock', '--no-update'], { cwd: 'libs/lib1', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(3, 'poetry', ['install'], { + cwd: 'libs/lib1', + shell: false, + stdio: 'inherit', + }); expect(spawn.sync).toHaveBeenNthCalledWith( - 3, + 4, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(5, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(spawn.sync).toHaveBeenNthCalledWith( - 4, + 6, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app1', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(7, 'poetry', ['install'], { + cwd: 'apps/app1', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); @@ -644,17 +674,22 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(1); + expect(spawn.sync).toHaveBeenCalledTimes(2); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(2, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); @@ -710,17 +745,22 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(1); + expect(spawn.sync).toHaveBeenCalledTimes(2); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(2, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); @@ -780,17 +820,22 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(1); + expect(spawn.sync).toHaveBeenCalledTimes(2); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(2, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); @@ -851,17 +896,22 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(1); + expect(spawn.sync).toHaveBeenCalledTimes(2); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(2, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); @@ -917,17 +967,22 @@ version = "1.0.0" expect(output.success).toBe(true); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(1); + expect(spawn.sync).toHaveBeenCalledTimes(2); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', - ['update', 'dgx-devops-lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(2, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); const { tool: { diff --git a/packages/nx-python/src/executors/add/executor.ts b/packages/nx-python/src/executors/add/executor.ts index 4686b9f..bbf182d 100644 --- a/packages/nx-python/src/executors/add/executor.ts +++ b/packages/nx-python/src/executors/add/executor.ts @@ -84,12 +84,12 @@ function updateLocalProject( dependencyConfig.root, ); - const dependencyPkgName = addLocalProjectToPoetryProject( + addLocalProjectToPoetryProject( projectConfig, dependencyConfig, dependencyPath, group, extras, ); - updateProject(dependencyPkgName, projectConfig.root, updateLockOnly); + updateProject(projectConfig.root, updateLockOnly); } diff --git a/packages/nx-python/src/executors/remove/executor.spec.ts b/packages/nx-python/src/executors/remove/executor.spec.ts index f838c7a..74e6aa4 100644 --- a/packages/nx-python/src/executors/remove/executor.spec.ts +++ b/packages/nx-python/src/executors/remove/executor.spec.ts @@ -162,7 +162,7 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(3); + expect(spawn.sync).toHaveBeenCalledTimes(5); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', @@ -176,23 +176,33 @@ version = "1.0.0" expect(spawn.sync).toHaveBeenNthCalledWith( 2, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(3, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(spawn.sync).toHaveBeenNthCalledWith( - 3, + 4, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app1', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(5, 'poetry', ['install'], { + cwd: 'apps/app1', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); @@ -285,7 +295,7 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(4); + expect(spawn.sync).toHaveBeenCalledTimes(7); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', @@ -299,33 +309,48 @@ version = "1.0.0" expect(spawn.sync).toHaveBeenNthCalledWith( 2, 'poetry', - ['update', 'shared1'], + ['lock', '--no-update'], { cwd: 'libs/lib1', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(3, 'poetry', ['install'], { + cwd: 'libs/lib1', + shell: false, + stdio: 'inherit', + }); expect(spawn.sync).toHaveBeenNthCalledWith( - 3, + 4, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(5, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(spawn.sync).toHaveBeenNthCalledWith( - 4, + 6, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app1', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(7, 'poetry', ['install'], { + cwd: 'apps/app1', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); diff --git a/packages/nx-python/src/executors/update/executor.spec.ts b/packages/nx-python/src/executors/update/executor.spec.ts index 02cf264..fa563ba 100644 --- a/packages/nx-python/src/executors/update/executor.spec.ts +++ b/packages/nx-python/src/executors/update/executor.spec.ts @@ -303,7 +303,7 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(4); + expect(spawn.sync).toHaveBeenCalledTimes(7); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', @@ -317,33 +317,48 @@ version = "1.0.0" expect(spawn.sync).toHaveBeenNthCalledWith( 2, 'poetry', - ['update', 'shared1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(3, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(spawn.sync).toHaveBeenNthCalledWith( - 3, + 4, 'poetry', - ['update', 'shared1'], + ['lock', '--no-update'], { cwd: 'libs/lib1', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(5, 'poetry', ['install'], { + cwd: 'libs/lib1', + shell: false, + stdio: 'inherit', + }); expect(spawn.sync).toHaveBeenNthCalledWith( - 4, + 6, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app1', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(7, 'poetry', ['install'], { + cwd: 'apps/app1', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); @@ -398,17 +413,22 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(1); + expect(spawn.sync).toHaveBeenCalledTimes(2); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', - ['update', 'lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(2, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); }); @@ -467,17 +487,22 @@ version = "1.0.0" const output = await executor(options, context); expect(checkPoetryExecutableMock).toHaveBeenCalled(); expect(activateVenvMock).toHaveBeenCalledWith('.'); - expect(spawn.sync).toHaveBeenCalledTimes(1); + expect(spawn.sync).toHaveBeenCalledTimes(2); expect(spawn.sync).toHaveBeenNthCalledWith( 1, 'poetry', - ['update', 'dgx-devops-lib1'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, stdio: 'inherit', }, ); + expect(spawn.sync).toHaveBeenNthCalledWith(2, 'poetry', ['install'], { + cwd: 'apps/app', + shell: false, + stdio: 'inherit', + }); expect(output.success).toBe(true); const { @@ -786,7 +811,7 @@ version = "1.0.0" expect(spawn.sync).toHaveBeenNthCalledWith( 2, 'poetry', - ['update', 'shared1', '--lock'], + ['lock', '--no-update'], { cwd: 'libs/lib1', shell: false, @@ -796,7 +821,7 @@ version = "1.0.0" expect(spawn.sync).toHaveBeenNthCalledWith( 3, 'poetry', - ['update', 'lib1', '--lock'], + ['lock', '--no-update'], { cwd: 'apps/app', shell: false, @@ -806,7 +831,7 @@ version = "1.0.0" expect(spawn.sync).toHaveBeenNthCalledWith( 4, 'poetry', - ['update', 'lib1', '--lock'], + ['lock', '--no-update'], { cwd: 'apps/app1', shell: false, diff --git a/packages/nx-python/src/executors/update/executor.ts b/packages/nx-python/src/executors/update/executor.ts index 6bb6ca8..5f199f6 100644 --- a/packages/nx-python/src/executors/update/executor.ts +++ b/packages/nx-python/src/executors/update/executor.ts @@ -1,12 +1,9 @@ -import { ExecutorContext, ProjectConfiguration } from '@nx/devkit'; +import { ExecutorContext } from '@nx/devkit'; import chalk from 'chalk'; import { UpdateExecutorSchema } from './schema'; import { activateVenv, checkPoetryExecutable, - getLocalDependencyConfig, - getProjectTomlPath, - parseToml, runPoetry, updateProject, } from '../utils/poetry'; @@ -30,12 +27,18 @@ export default async function executor( console.log( chalk`\n {bold Updating {bgBlue ${options.name} } workspace dependency...}\n`, ); - updateLocalProject( - context, - options.name, - projectConfig, - rootPyprojectToml, - ); + + if ( + !Object.keys(context.workspace.projects).some( + (projectName) => options.name === projectName, + ) + ) { + throw new Error( + chalk`\n {red.bold ${options.name}} workspace project does not exist\n`, + ); + } + + updateProject(projectConfig.root, rootPyprojectToml); } else { if (options.name) { console.log( @@ -68,19 +71,3 @@ export default async function executor( }; } } - -function updateLocalProject( - context: ExecutorContext, - dependencyName: string, - projectConfig: ProjectConfiguration, - updateLockOnly: boolean, -) { - const dependencyConfig = getLocalDependencyConfig(context, dependencyName); - const dependencyProjectToml = parseToml(getProjectTomlPath(dependencyConfig)); - - updateProject( - dependencyProjectToml.tool.poetry.name, - projectConfig.root, - updateLockOnly, - ); -} diff --git a/packages/nx-python/src/executors/utils/poetry.ts b/packages/nx-python/src/executors/utils/poetry.ts index 506559b..bdc9ea9 100644 --- a/packages/nx-python/src/executors/utils/poetry.ts +++ b/packages/nx-python/src/executors/utils/poetry.ts @@ -69,15 +69,11 @@ export function addLocalProjectToPoetryProject( return dependencyName; } -export function updateProject( - projectName: string, - cwd: string, - updateLockOnly: boolean, -) { - const updateLockArgs = ['update', projectName].concat( - updateLockOnly ? ['--lock'] : [], - ); - runPoetry(updateLockArgs, { cwd }); +export function updateProject(cwd: string, updateLockOnly: boolean) { + runPoetry(['lock', '--no-update'], { cwd }); + if (!updateLockOnly) { + runPoetry(['install'], { cwd }); + } } export function getProjectTomlPath(targetConfig: ProjectConfiguration) {