Analyze a program. A single call to build performs parsing, semantic analysis and optionally type checking for the program *and* all imported modules, recursively. Return BuildResult if successful or only non-blocking errors were found; otherwise raise CompileError. If a flush
(
sources: list[BuildSource],
options: Options,
alt_lib_path: str | None = None,
flush_errors: Callable[[str | None, list[str], bool], None] | None = None,
fscache: FileSystemCache | None = None,
stdout: TextIO | None = None,
stderr: TextIO | None = None,
extra_plugins: Sequence[Plugin] | None = None,
worker_env: Mapping[str, str] | None = None,
)
| 328 | |
| 329 | |
| 330 | def build( |
| 331 | sources: list[BuildSource], |
| 332 | options: Options, |
| 333 | alt_lib_path: str | None = None, |
| 334 | flush_errors: Callable[[str | None, list[str], bool], None] | None = None, |
| 335 | fscache: FileSystemCache | None = None, |
| 336 | stdout: TextIO | None = None, |
| 337 | stderr: TextIO | None = None, |
| 338 | extra_plugins: Sequence[Plugin] | None = None, |
| 339 | worker_env: Mapping[str, str] | None = None, |
| 340 | ) -> BuildResult: |
| 341 | """Analyze a program. |
| 342 | |
| 343 | A single call to build performs parsing, semantic analysis and optionally |
| 344 | type checking for the program *and* all imported modules, recursively. |
| 345 | |
| 346 | Return BuildResult if successful or only non-blocking errors were found; |
| 347 | otherwise raise CompileError. |
| 348 | |
| 349 | If a flush_errors callback is provided, all error messages will be |
| 350 | passed to it and the errors and messages fields of BuildResult and |
| 351 | CompileError (respectively) will be empty. Otherwise, those fields will |
| 352 | report any error messages. |
| 353 | |
| 354 | Args: |
| 355 | sources: list of sources to build |
| 356 | options: build options |
| 357 | alt_lib_path: an additional directory for looking up library modules |
| 358 | (takes precedence over other directories) |
| 359 | flush_errors: optional function to flush errors after a file is processed |
| 360 | fscache: optionally a file-system cacher |
| 361 | stdout: Output stream to use instead of `sys.stdout` |
| 362 | stderr: Error stream to use instead of `sys.stderr` |
| 363 | extra_plugins: Plugins to use in addition to those loaded from config |
| 364 | worker_env: An environment to start parallel build workers (used for tests) |
| 365 | """ |
| 366 | # If we were not given a flush_errors, we use one that will populate those |
| 367 | # fields for callers that want the traditional API. |
| 368 | messages = [] |
| 369 | |
| 370 | # This is mostly for the benefit of tests that use builtins fixtures. |
| 371 | instance_cache.reset() |
| 372 | reset_known_modules_cache() |
| 373 | |
| 374 | def default_flush_errors( |
| 375 | filename: str | None, new_messages: list[str], is_serious: bool |
| 376 | ) -> None: |
| 377 | messages.extend(new_messages) |
| 378 | |
| 379 | flush_errors = flush_errors or default_flush_errors |
| 380 | stdout = stdout or sys.stdout |
| 381 | stderr = stderr or sys.stderr |
| 382 | extra_plugins = extra_plugins or [] |
| 383 | |
| 384 | # Create metastore before workers to avoid race conditions. |
| 385 | metastore = create_metastore(options, parallel_worker=False) |
| 386 | workers = [] |
| 387 | connect_threads = [] |
no test coverage detected
searching dependent graphs…