Install a package into an isolated venv and run pyright against its source. Args: package: The package to install and check. python_version: The interpreter version for the venv. venv: Directory in which to create the virtualenv. config: Path to the pyright optio
(
package: Package,
python_version: str,
venv: Path,
config: Path,
lowest: bool,
)
| 366 | |
| 367 | |
| 368 | def _resolve_and_check( |
| 369 | package: Package, |
| 370 | python_version: str, |
| 371 | venv: Path, |
| 372 | config: Path, |
| 373 | lowest: bool, |
| 374 | ) -> tuple[dict[tuple[str, int, int, str], str] | None, str]: |
| 375 | """Install a package into an isolated venv and run pyright against its source. |
| 376 | |
| 377 | Args: |
| 378 | package: The package to install and check. |
| 379 | python_version: The interpreter version for the venv. |
| 380 | venv: Directory in which to create the virtualenv. |
| 381 | config: Path to the pyright options config. |
| 382 | lowest: Whether to pin direct dependencies to their declared minimums. |
| 383 | |
| 384 | Returns: |
| 385 | A ``(errors, detail)`` tuple. ``errors`` is the pyright error map, or ``None`` if |
| 386 | the environment could not be built or pyright produced no parseable output, in |
| 387 | which case ``detail`` carries the captured output. |
| 388 | """ |
| 389 | venv_proc = _run(["uv", "venv", "--python", python_version, str(venv)]) |
| 390 | if venv_proc.returncode != 0: |
| 391 | return None, venv_proc.stdout |
| 392 | venv_python = str(_venv_python(venv)) |
| 393 | |
| 394 | install_cmd = [ |
| 395 | "uv", |
| 396 | "pip", |
| 397 | "install", |
| 398 | "--python", |
| 399 | venv_python, |
| 400 | "--no-sources", |
| 401 | ] |
| 402 | if lowest: |
| 403 | install_cmd += ["--resolution", "lowest-direct"] |
| 404 | install_cmd += ["-e", package.install_target()] |
| 405 | # ``--no-sources`` forces every dependency to resolve from PyPI; the lone exception is a |
| 406 | # sibling pinned to an unpublished ``*.dev`` release, which is provided here as an explicit |
| 407 | # editable from its local checkout so resolution can succeed without reaching PyPI for it. |
| 408 | for source in package.local_dev_sources: |
| 409 | install_cmd += ["-e", str(source)] |
| 410 | install = _run(install_cmd, cwd=REPO_ROOT) |
| 411 | if install.returncode != 0: |
| 412 | return None, install.stdout |
| 413 | |
| 414 | pyright = _run( |
| 415 | [ |
| 416 | "pyright", |
| 417 | "--outputjson", |
| 418 | "--pythonpath", |
| 419 | venv_python, |
| 420 | "--project", |
| 421 | str(config), |
| 422 | str(package.source_dir), |
| 423 | ], |
| 424 | cwd=REPO_ROOT, |
| 425 | ) |
no test coverage detected