Skip to content

Commit

Permalink
Merge pull request #12 from dman926/proper-logging
Browse files Browse the repository at this point in the history
Migrate to latest. Fix logging issues. Fix tests. Fix plugin name.
  • Loading branch information
dman926 authored Oct 27, 2023
2 parents f0c6426 + dd90101 commit 7d36c96
Show file tree
Hide file tree
Showing 29 changed files with 1,434 additions and 1,266 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
},
"rules": {}
},
{
"files": ["*.json", ".pyre_configuration"],
"parser": "jsonc-eslint-parser"
},
{
"files": ["*.mjs"],
"parserOptions": {
Expand Down
11 changes: 8 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@
"rules": {}
},
{
"files": ["*.json", ".pyre_configuration"],
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
// Not really sure why these are triggering
{ "ignoredDependencies": ["@nx/jest", "@nx/linter", "chalk"] }
{ "ignoredDependencies": ["@nx/jest", "chalk"] }
]
}
},
{
"files": ["./package.json", "./executors.json", "./generators.json"],
"files": [
"./package.json",
"./executors.json",
"./generators.json",
"./migrations.json"
],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/nx-plugin-checks": "error"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ Thumbs.db

# Environment
nx-cloud.env

.nx/cache
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Add files here to ignore them from prettier formatting
/dist
/coverage
/coverage
/.nx/cache
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# nx-python-pdm
# @dman926/nx-python-pdm

[![LICENSE](https://img.shields.io/badge/license-MIT-green)](https://github.com/dman926/nx-python-pdm/blob/main/LICENSE)
[![CI](https://github.com/dman926/nx-python-pdm/actions/workflows/ci.yml/badge.svg)](https://github.com/dman926/nx-python-pdm/actions/workflows/ci.yml)
Expand All @@ -22,15 +22,18 @@ yarn add -D @dman926/nx-python-pdm
## Prerequisites

- An [NX workspace](https://nx.dev/)
- [PDM](https://pdm.fming.dev/) must be available to run from the NX workspace.
- [PDM](https://pdm.fming.dev/) must be available to run from a terminal in the NX workspace.

## Usage

### Executors

- pdm - Run a command with PDM on the project
- command\*: The command to run. 'pdm ' is prepended to this command.
- cwd: Override where the command runs. By default, the command runs in the project root. If provided, it should be relative to the workspace root.
- The default input is used for command as well. It is important to note that the remainder of the PDM command must still be wrapped in quotes.
- Ex: `nx run my-project:pdm --command="add -d wheel"`
- Ex: `nx run my-project:pdm "add -d wheel"`
- cwd: Override where the command runs. By default, the command runs in the project root. If provided, it should be relative to the workspace root or an absolute path.
- raw: Do not prepend `'pdm '` to the given command.
- quiet: Suppress output to stdout. stderr will still be printed on process error.

Expand All @@ -41,7 +44,7 @@ yarn add -D @dman926/nx-python-pdm
- projectType\*: Application or Library.
- application (default)
- library
- buildBackend: Override the default build backend.
- buildBackend: Override the PDM default build backend.
- pdm-backend
- setuptools
- flot
Expand Down Expand Up @@ -77,6 +80,7 @@ yarn add -D @dman926/nx-python-pdm
- e2e: Run end-to-end tests with the selected test runner.
- _In progress. It technically works, but it is missing tests. It's also not created automatically by the python generator except for cypress_
- pdm: Allows running arbitrary PDM commands in the project through NX.
- See [Executors](#Executors) for examples.

### TODOs

Expand Down
6 changes: 3 additions & 3 deletions e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"coverageDirectory": "coverage/e2e",
"runInBand": true
},
"dependsOn": ["nx-python-pdm:build"]
"dependsOn": ["@dman926/nx-python-pdm:build"]
},
"lint": {
"executor": "@nx/linter:eslint",
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["e2e/**/*.ts"]
}
}
},
"tags": [],
"implicitDependencies": ["nx-python-pdm"]
"implicitDependencies": ["@dman926/nx-python-pdm"]
}
18 changes: 10 additions & 8 deletions e2e/tests/executor/pdm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('pdm executor', () => {
const names: string[] = [];

beforeAll(() => {
ensureNxProject('nx-python-pdm', 'dist/nx-python-pdm');
ensureNxProject('@dman926/nx-python-pdm', 'dist/@dman926/nx-python-pdm');
});

afterAll(async () => {
Expand All @@ -30,17 +30,18 @@ describe('pdm executor', () => {
const name = uniq('pdm-executor-test');
names.push(name);
await runNxCommandAsync(
`generate nx-python-pdm:python --name ${name} --no-interactive`
`generate @dman926/nx-python-pdm:python --name ${name} --no-interactive`
);

// pdm info
let projectInfo: string[] = [];
expect(() => {
projectInfo = runNxCommand(`run ${name}:pdm info`).split('\n');
}).not.toThrow();
expect(projectInfo.length).toBeGreaterThanOrEqual(4);
const firstLineOfInfo = projectInfo[3];
expect(firstLineOfInfo).toBe('PDM version:');
const expectedLine = projectInfo.find((line) =>
line.startsWith('PDM version:')
);
expect(expectedLine).toBeDefined();

// pdm run
let runOutput: string[] = [];
Expand All @@ -49,8 +50,9 @@ describe('pdm executor', () => {
`run ${name}:pdm "run python -c \\"print('Hello World')\\""`
).split('\n');
}).not.toThrow();
expect(runOutput.length).toBeGreaterThanOrEqual(4);
const firstLineOfPython = runOutput[3];
expect(firstLineOfPython).toBe('Hello World');
const expectedLineOfPython = runOutput.find(
(line) => line === 'Hello World'
);
expect(expectedLineOfPython).toBeDefined();
});
});
34 changes: 14 additions & 20 deletions e2e/tests/generator/python.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ projectTypes.forEach((projectType) => {
const options = () => getOptionString(baseOptions);

beforeAll(() => {
ensureNxProject('nx-python-pdm', 'dist/nx-python-pdm');
ensureNxProject('@dman926/nx-python-pdm', 'dist/@dman926/nx-python-pdm');
});

afterEach(() => {
Expand All @@ -51,7 +51,7 @@ projectTypes.forEach((projectType) => {
const name = uniq('generate-proj');
baseOptions.name = name;
await runNxCommandAsync(
`generate nx-python-pdm:python ${options()} --no-interactive`
`generate @dman926/nx-python-pdm:python ${options()} --no-interactive`
);
names.push(name);
const baseDir = await getProjectRoot(name);
Expand All @@ -73,7 +73,7 @@ projectTypes.forEach((projectType) => {
const name = uniq('build-target-test');
baseOptions.name = name;
await runNxCommandAsync(
`generate nx-python-pdm:python ${options()} --no-interactive`
`generate @dman926/nx-python-pdm:python ${options()} --no-interactive`
);
names.push(name);

Expand Down Expand Up @@ -111,25 +111,19 @@ projectTypes.forEach((projectType) => {
const name = uniq('serve-target-test');
baseOptions.name = name;
await runNxCommandAsync(
`generate nx-python-pdm:python ${options()} --no-interactive`
`generate @dman926/nx-python-pdm:python ${options()} --no-interactive`
);
names.push(name);
let serveOutput = '';
const expectedOutput =
'\n' +
`> nx run ${name}:serve\n` +
'\n' +
'Hello World\n' +
'\n' +
' \n' +
'\n' +
` > NX Successfully ran target serve for project ${name}\n` +
'\n' +
'\n';
const expectedOutput = 'Hello World';
expect(() => {
serveOutput = runNxCommand(`serve ${name}`);
}).not.toThrow();
expect(serveOutput).toBe(expectedOutput);
expect(
serveOutput
.split('\n')
.find((line) => line.startsWith(expectedOutput))
).toBeDefined();
});
});

Expand All @@ -141,7 +135,7 @@ projectTypes.forEach((projectType) => {
const name = uniq(`${testRunner}-test-target-test`);
baseOptions.name = name;
await runNxCommandAsync(
`generate nx-python-pdm:python ${options()} --unitTestRunner ${testRunner} --no-interactive`
`generate @dman926/nx-python-pdm:python ${options()} --unitTestRunner ${testRunner} --no-interactive`
);
names.push(name);

Expand Down Expand Up @@ -181,7 +175,7 @@ projectTypes.forEach((projectType) => {
const name = uniq(`${projectName}-lint-target-test`);
baseOptions.name = name;
await runNxCommandAsync(
`generate nx-python-pdm:python ${options()}${command} --no-interactive`
`generate @dman926/nx-python-pdm:python ${options()}${command} --no-interactive`
);
names.push(name);

Expand All @@ -205,7 +199,7 @@ projectTypes.forEach((projectType) => {
const name = uniq(`${linter}-lint-target-test`);
baseOptions.name = name;
await runNxCommandAsync(
`generate nx-python-pdm:python ${options()} --linter ${linter} --no-interactive`
`generate @dman926/nx-python-pdm:python ${options()} --linter ${linter} --no-interactive`
);
names.push(name);

Expand All @@ -228,7 +222,7 @@ projectTypes.forEach((projectType) => {
const name = uniq(`${typeChecker}-type-check-target-test`);
baseOptions.name = name;
await runNxCommandAsync(
`generate nx-python-pdm:python ${options()} --typeChecker ${typeChecker} --no-interactive`
`generate @dman926/nx-python-pdm:python ${options()} --typeChecker ${typeChecker} --no-interactive`
);
names.push(name);

Expand Down
2 changes: 1 addition & 1 deletion jest.config.app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
export default {
displayName: 'nx-python-pdm',
displayName: '@dman926/nx-python-pdm',
preset: './jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
Expand Down
24 changes: 24 additions & 0 deletions migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"generators": {
"update-plugin-name": {
"version": "1.1.0",
"description": "Change references to package from 'nx-python-pdm' to '@dman926/nx-python-pdm'",
"implementation": "./src/migrations/update-1-1-0/update-plugin-name"
}
},
"packageJsonUpdates": {
"1.1.0": {
"version": "1.1.0",
"packages": {
"@nx/cypress": {
"version": "17.0.2",
"alwaysAddToPackageJson": false
},
"@nx/eslint": {
"version": "17.0.2",
"alwaysAddToPackageJson": false
}
}
}
}
}
24 changes: 11 additions & 13 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
{
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"tasksRunnerOptions": {
"default": {
"runner": "nx-cloud",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"],
"accessToken": "OGJhOTMzNjAtNGQzYy00OTI5LThjODktZGJkZjdlN2FkMTZjfHJlYWQtb25seQ=="
}
}
},
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"inputs": ["production", "^production"]
"inputs": ["production", "^production"],
"cache": true
},
"lint": {
"inputs": [
"default",
"{workspaceRoot}/.eslintrc.json",
"{workspaceRoot}/.eslintignore"
]
],
"cache": true
},
"test": {
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"]
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
"cache": true
},
"e2e": {
"cache": true
}
},
"namedInputs": {
Expand All @@ -37,5 +34,6 @@
"!{projectRoot}/**/jest.d.ts"
],
"sharedGlobals": []
}
},
"nxCloudAccessToken": "OGJhOTMzNjAtNGQzYy00OTI5LThjODktZGJkZjdlN2FkMTZjfHJlYWQtb25seQ=="
}
Loading

0 comments on commit 7d36c96

Please sign in to comment.