-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx-python): add support for nx releases (#246)
- Loading branch information
1 parent
4ae1502
commit 9614843
Showing
22 changed files
with
4,613 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/nx-python/src/generators/enable-releases/generator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { vi, MockInstance } from 'vitest'; | ||
import '../../utils/mocks/cross-spawn.mock'; | ||
import * as poetryUtils from '../../executors/utils/poetry'; | ||
import { readJson, Tree } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import generator from './generator'; | ||
import projectGenerator from '../poetry-project/generator'; | ||
import spawn from 'cross-spawn'; | ||
|
||
describe('nx-python enable-releases', () => { | ||
let checkPoetryExecutableMock: MockInstance; | ||
let appTree: Tree; | ||
|
||
beforeEach(() => { | ||
appTree = createTreeWithEmptyWorkspace({}); | ||
checkPoetryExecutableMock = vi.spyOn(poetryUtils, 'checkPoetryExecutable'); | ||
checkPoetryExecutableMock.mockResolvedValue(undefined); | ||
vi.mocked(spawn.sync).mockReturnValue({ | ||
status: 0, | ||
output: [''], | ||
pid: 0, | ||
signal: null, | ||
stderr: null, | ||
stdout: null, | ||
}); | ||
}); | ||
|
||
it('should add release version generator', async () => { | ||
await projectGenerator(appTree, { | ||
name: 'proj1', | ||
projectType: 'application', | ||
pyprojectPythonDependency: '', | ||
pyenvPythonVersion: '', | ||
publishable: false, | ||
buildLockedVersions: false, | ||
buildBundleLocalDependencies: false, | ||
linter: 'none', | ||
unitTestRunner: 'none', | ||
rootPyprojectDependencyGroup: 'main', | ||
unitTestHtmlReport: false, | ||
unitTestJUnitReport: false, | ||
codeCoverage: false, | ||
codeCoverageHtmlReport: false, | ||
codeCoverageXmlReport: false, | ||
projectNameAndRootFormat: 'derived', | ||
}); | ||
|
||
await generator(appTree); | ||
|
||
expect(readJson(appTree, 'proj1/project.json').release).toEqual({ | ||
version: { | ||
generator: '@nxlv/python:release-version', | ||
}, | ||
}); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/nx-python/src/generators/enable-releases/generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { getProjects, Tree, updateProjectConfiguration } from '@nx/devkit'; | ||
import path from 'path'; | ||
|
||
async function generator(host: Tree) { | ||
for (const project of getProjects(host)) { | ||
const [projectName, projectConfig] = project; | ||
const pyprojectTomlPath = path.join(projectConfig.root, 'pyproject.toml'); | ||
if (host.exists(pyprojectTomlPath)) { | ||
projectConfig.release = projectConfig.release || { | ||
version: { | ||
generator: '@nxlv/python:release-version', | ||
}, | ||
}; | ||
|
||
updateProjectConfiguration(host, projectName, projectConfig); | ||
} | ||
} | ||
} | ||
|
||
export default generator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Schema = object; |
8 changes: 8 additions & 0 deletions
8
packages/nx-python/src/generators/enable-releases/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "NxEnableReleases", | ||
"title": "Enable Releases for Python projects", | ||
"type": "object", | ||
"properties": {}, | ||
"required": [] | ||
} |
Oops, something went wrong.