mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-05-06 14:03:15 +08:00
* fix(core): invoke linters via `python -m` so PATH state can't silently skip them
`Linters.run()` used `shutil.which(linter)` which resolves the binary against
the process `PATH`. When users run `.venv/bin/python` directly — as
`dev_install.py` itself does, and as common IDE configurations do — the venv's
`bin/` directory is not on `PATH`, so `which("ruff")` returned `None` and the
linter step silently no-op'd.
That mattered because `ImportDefinition.build` emits speculative type imports
(e.g. `OBBject_EquityInfo`) by design and relies on `ruff --fix` to strip the
unused ones. Without the cleanup, those imports remained in generated files
and produced `ImportError` on first import — the symptom many users have hit.
This change resolves the linter through `sys.executable -m <linter>` so it
always resolves against the running Python's environment, independent of
`PATH`. A pre-check via `importlib.util.find_spec` preserves the
"linter not found" path for environments where the package genuinely isn't
installed. A second guard skips invocation when the target directory has no
`*.py` files, which prevents the linter from falling back to its default
working-directory scan.
Adds two regression tests:
- `test_ruff_strips_unused_imports_via_module_invocation` simulates the
failing scenario by clearing `PATH` and asserts ruff still removes an
unused import.
- `test_run_logs_not_found_when_module_missing` exercises the missing-module
branch with a known-bogus linter name.
* style(linters): collapse subprocess.run call to satisfy black
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(linters): keep command list[str] to satisfy mypy
Glob produces Path objects; concatenating with the str command list
tripped mypy's "list[str] + list[Path]" check. Stringify the file
paths up-front so the assembled command is uniformly list[str].
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>