Skip to content
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
2 changes: 1 addition & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,4 @@ forge languages
forge languages . --json
~~~

Python and Rust are first-class verification adapters. A Python project receives bounded AST syntax validation and detected pytest/unittest checks; standard and release profiles enable Ruff when `ruff.toml`, `.ruff.toml` or `[tool.ruff]` configuration is present, and standard/release profiles enable mypy when `[tool.mypy]`, `mypy.ini`, `.mypy.ini` or `[mypy]` in `setup.cfg` is configured. A Rust project receives `cargo test --all-targets`, `cargo fmt --all -- --check`, and (for release profiles) strict Clippy checks. The language report shows the actual adapter check set next to the percentage, and keeps Python/Rust rows visible even in a workspace that currently contains zero files for one of them.
Python and Rust are first-class verification adapters. A Python project receives bounded AST syntax validation and detected pytest/unittest checks; standard and release profiles enable Ruff when `ruff.toml`, `.ruff.toml` or `[tool.ruff]` configuration is present, and standard/release profiles enable mypy when `[tool.mypy]`, `mypy.ini`, `.mypy.ini` or `[mypy]` in `setup.cfg` is configured. Standard/release profiles also enable Pyright when `pyrightconfig.json` or `[tool.pyright]` is present; the project manages the Pyright executable. Standard/release profiles also run Pylint when `.pylintrc`, `pylintrc`, `[tool.pylint]` or `[pylint]` in `setup.cfg` is present. A Rust project receives `cargo test --all-targets`, `cargo fmt --all -- --check`, and (for release profiles) strict Clippy checks. The language report shows the actual adapter check set next to the percentage, and keeps Python/Rust rows visible even in a workspace that currently contains zero files for one of them.
4 changes: 2 additions & 2 deletions src/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const ADAPTERS = Object.freeze([
Object.freeze({
id: 'python',
name: 'Python',
manifests: Object.freeze(['pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'ruff.toml', '.ruff.toml']),
checks: Object.freeze(['syntax', 'tests', 'unittest', 'ruff', 'mypy']),
manifests: Object.freeze(['pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'ruff.toml', '.ruff.toml', 'mypy.ini', '.mypy.ini', 'pyrightconfig.json', '.pylintrc', 'pylintrc']),
checks: Object.freeze(['syntax', 'tests', 'unittest', 'ruff', 'mypy', 'pyright', 'pylint']),
createChecks: createPythonChecks,
}),
Object.freeze({
Expand Down
32 changes: 31 additions & 1 deletion src/adapters/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';
import { spawnSync } from 'node:child_process';
import { makeVerificationStep } from './step.js';

const PYTHON_PROJECT_FILES = ['pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'ruff.toml', '.ruff.toml', 'mypy.ini', '.mypy.ini'];
const PYTHON_PROJECT_FILES = ['pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'ruff.toml', '.ruff.toml', 'mypy.ini', '.mypy.ini', 'pyrightconfig.json', '.pylintrc', 'pylintrc'];
const IGNORED_DIRECTORIES = new Set([
'.git', '.forge', '.venv', 'venv', 'node_modules', '__pycache__', 'site-packages',
]);
Expand Down Expand Up @@ -35,6 +35,27 @@ export function hasRuffConfiguration(projectRoot) {
return /^\s*\[tool\.ruff(?:\.[^\]]+)?\]\s*(?:#.*)?$/m.test(content);
}

export function hasPylintConfiguration(projectRoot) {
if (isRegularConfigFile(projectRoot, '.pylintrc')
|| isRegularConfigFile(projectRoot, 'pylintrc')) return true;
for (const [filename, section] of [
['pyproject.toml', /^\s*\[tool\.pylint(?:\.[^\]]+)?\]\s*(?:#.*)?$/m],
['setup.cfg', /^\s*\[pylint(?:\.[^\]]+)?\]\s*(?:[#;].*)?$/m],
]) {
if (!isRegularConfigFile(projectRoot, filename)) continue;
if (section.test(readFileSync(path.join(projectRoot, filename), 'utf8'))) return true;
}
return false;
}

export function hasPyrightConfiguration(projectRoot) {
if (isRegularConfigFile(projectRoot, 'pyrightconfig.json')) return true;
const pyprojectPath = path.join(projectRoot, 'pyproject.toml');
if (!isRegularConfigFile(projectRoot, 'pyproject.toml')) return false;
const content = readFileSync(pyprojectPath, 'utf8');
return /^\s*\[tool\.pyright(?:\.[^\]]+)?\]\s*(?:#.*)?$/m.test(content);
}

export function hasMypyConfiguration(projectRoot) {
for (const filename of ['mypy.ini', '.mypy.ini']) {
if (isRegularConfigFile(projectRoot, filename)) {
Expand Down Expand Up @@ -142,5 +163,14 @@ export function createPythonChecks(projectRoot, {
if (profile !== 'quick' && hasMypyConfiguration(projectRoot)) {
steps.push(makeVerificationStep('python', 'mypy', python, ['-m', 'mypy', '.']));
}
if (profile !== 'quick' && hasPyrightConfiguration(projectRoot)) {
const command = platform === 'win32' ? 'pyright.cmd' : 'pyright';
steps.push(makeVerificationStep('python', 'pyright', command, ['--project', projectRoot], {
shell: platform === 'win32',
}));
}
if (profile !== 'quick' && hasPylintConfiguration(projectRoot)) {
steps.push(makeVerificationStep('python', 'pylint', python, ['-m', 'pylint', '.']));
}
return steps;
}
124 changes: 124 additions & 0 deletions test/language-adapters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,130 @@ test('Python Mypy configuration symlinks are ignored', () => {
}
});

test('Python Pyright configuration enables standard-profile project type checking', () => {
const f = fixture();
try {
writeFileSync(path.join(f.root, 'pyproject.toml'), [
'[project]',
'name = "forge-pyright-project"',
'',
'[tool.pyright]',
'typeCheckingMode = "strict"',
'',
].join('\n'));
const standard = createLanguageVerificationChecks(f.root, {
profile: 'standard',
pythonCommand: process.execPath,
});
assert.deepEqual(standard.map((step) => step.name), ['python:syntax', 'python:pyright']);
assert.equal(standard[1].command, 'pyright');
assert.deepEqual(standard[1].args, ['--project', f.root]);
assert.equal(standard[1].shell, false);
const quick = createLanguageVerificationChecks(f.root, {
profile: 'quick', pythonCommand: process.execPath,
});
assert.deepEqual(quick.map((step) => step.name), ['python:syntax']);
} finally { f.cleanup(); }
});

test('Python Pyright adapter supports pyrightconfig.json and Windows command shims', () => {
const f = fixture();
try {
writeFileSync(path.join(f.root, 'pyrightconfig.json'), JSON.stringify({
typeCheckingMode: 'strict', include: ['src'],
}));
const standard = createLanguageVerificationChecks(f.root, {
profile: 'standard', pythonCommand: process.execPath,
});
assert.deepEqual(standard.map((step) => step.name), ['python:syntax', 'python:pyright']);
assert.equal(standard[1].command, 'pyright');
assert.deepEqual(standard[1].args, ['--project', f.root]);
const windows = createLanguageVerificationChecks(f.root, {
profile: 'standard', platform: 'win32', pythonCommand: process.execPath,
});
assert.deepEqual(windows.map((step) => step.name), ['python:syntax', 'python:pyright']);
assert.equal(windows[1].command, 'pyright.cmd');
assert.equal(windows[1].shell, true);
} finally { f.cleanup(); }
});

test('Python Pyright configuration ignores symlinked config files', () => {
const f = fixture();
try {
const target = path.join(f.root, 'outside.json');
writeFileSync(target, JSON.stringify({ typeCheckingMode: 'strict' }));
symlinkSync(target, path.join(f.root, 'pyrightconfig.json'));
assert.deepEqual(createLanguageVerificationChecks(f.root, {
profile: 'standard', pythonCommand: process.execPath,
}), []);
} finally { f.cleanup(); }
});

test('Python Pylint configuration enables standard-profile lint checks', () => {
const f = fixture();
try {
writeFileSync(path.join(f.root, 'pyproject.toml'), [
'[project]',
'name = "forge-pylint-project"',
'',
'[tool.pylint.main]',
'jobs = 1',
'',
].join('\n'));
const standard = createLanguageVerificationChecks(f.root, {
profile: 'standard',
pythonCommand: process.execPath,
});
assert.deepEqual(standard.map((step) => step.name), ['python:syntax', 'python:pylint']);
assert.equal(standard[1].command, process.execPath);
assert.deepEqual(standard[1].args, ['-m', 'pylint', '.']);
const quick = createLanguageVerificationChecks(f.root, {
profile: 'quick',
pythonCommand: process.execPath,
});
assert.deepEqual(quick.map((step) => step.name), ['python:syntax']);
} finally { f.cleanup(); }
});

test('Python Pylint adapter recognises standalone and setup.cfg configurations', () => {
const standalone = fixture(), setup = fixture();
try {
writeFileSync(path.join(standalone.root, '.pylintrc'), '[MAIN]\njobs=1\n');
const standaloneChecks = createLanguageVerificationChecks(standalone.root, {
profile: 'standard', pythonCommand: process.execPath,
});
assert.deepEqual(standaloneChecks.map((step) => step.name), ['python:syntax', 'python:pylint']);

writeFileSync(path.join(setup.root, 'setup.cfg'), [
'[metadata]',
'name = forge-pylint-setup',
'',
'[pylint.messages_control]',
'disable = missing-docstring',
'',
].join('\n'));
const setupChecks = createLanguageVerificationChecks(setup.root, {
profile: 'standard', pythonCommand: process.execPath,
});
assert.deepEqual(setupChecks.map((step) => step.name), ['python:syntax', 'python:pylint']);
} finally {
standalone.cleanup();
setup.cleanup();
}
});

test('Python Pylint configuration ignores symlinked config files', () => {
const f = fixture();
try {
const target = path.join(f.root, 'outside.pylintrc');
writeFileSync(target, '[MAIN]\njobs=1\n');
symlinkSync(target, path.join(f.root, '.pylintrc'));
assert.deepEqual(createLanguageVerificationChecks(f.root, {
profile: 'standard', pythonCommand: process.execPath,
}), []);
} finally { f.cleanup(); }
});

test('Python backend detects unittest.TestCase suites separately from pytest tests', () => {
const f = fixture();
try {
Expand Down
2 changes: 2 additions & 0 deletions test/language-report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ test('language report calculates percentages from recognised source bytes and ke
assert.equal(byId.get('python').verificationAdapter.available, true);
assert.ok(byId.get('python').verificationAdapter.checks.includes('syntax'));
assert.ok(byId.get('python').verificationAdapter.checks.includes('mypy'));
assert.ok(byId.get('python').verificationAdapter.checks.includes('pyright'));
assert.ok(byId.get('python').verificationAdapter.checks.includes('pylint'));
assert.ok(byId.get('python').verificationAdapter.checks.includes('ruff'));
assert.ok(byId.get('rust').verificationAdapter.checks.includes('clippy'));
assert.equal(result.adapters.find((adapter) => adapter.id === 'node').detected, true);
Expand Down
Loading