|
38 | 38 | from mypy.indirection import TypeIndirectionVisitor |
39 | 39 | from mypy.errors import Errors, CompileError, report_internal_error |
40 | 40 | from mypy.util import DecodeError, decode_python_encoding, is_sub_path |
41 | | -from mypy.report import Reports |
| 41 | +if MYPY: |
| 42 | + from mypy.report import Reports # Avoid unconditional slow import |
42 | 43 | from mypy import moduleinfo |
43 | 44 | from mypy.fixup import fixup_module |
44 | 45 | from mypy.modulefinder import BuildSource, compute_search_paths, FindModuleCache, SearchPaths |
|
50 | 51 | from mypy.version import __version__ |
51 | 52 | from mypy.plugin import Plugin, ChainedPlugin, plugin_types |
52 | 53 | from mypy.plugins.default import DefaultPlugin |
53 | | -from mypy.server.deps import get_dependencies |
54 | 54 | from mypy.fscache import FileSystemCache |
55 | 55 | from mypy.metastore import MetadataStore, FilesystemMetadataStore, SqliteMetadataStore |
56 | 56 | from mypy.typestate import TypeState, reset_global_state |
@@ -182,7 +182,12 @@ def _build(sources: List[BuildSource], |
182 | 182 |
|
183 | 183 | search_paths = compute_search_paths(sources, options, data_dir, alt_lib_path) |
184 | 184 |
|
185 | | - reports = Reports(data_dir, options.report_dirs) |
| 185 | + reports = None |
| 186 | + if options.report_dirs: |
| 187 | + # Import lazily to avoid slowing down startup. |
| 188 | + from mypy.report import Reports # noqa |
| 189 | + reports = Reports(data_dir, options.report_dirs) |
| 190 | + |
186 | 191 | source_set = BuildSourceSet(sources) |
187 | 192 | errors = Errors(options.show_error_context, options.show_column_numbers) |
188 | 193 | plugin, snapshot = load_plugins(options, errors) |
@@ -214,8 +219,9 @@ def _build(sources: List[BuildSource], |
214 | 219 | (time.time() - manager.start_time, |
215 | 220 | len(manager.modules), |
216 | 221 | manager.errors.num_messages())) |
217 | | - # Finish the HTML or XML reports even if CompileError was raised. |
218 | | - reports.finish() |
| 222 | + if reports is not None: |
| 223 | + # Finish the HTML or XML reports even if CompileError was raised. |
| 224 | + reports.finish() |
219 | 225 |
|
220 | 226 |
|
221 | 227 | def default_data_dir() -> str: |
@@ -473,7 +479,7 @@ def __init__(self, data_dir: str, |
473 | 479 | search_paths: SearchPaths, |
474 | 480 | ignore_prefix: str, |
475 | 481 | source_set: BuildSourceSet, |
476 | | - reports: Reports, |
| 482 | + reports: Optional['Reports'], |
477 | 483 | options: Options, |
478 | 484 | version_id: str, |
479 | 485 | plugin: Plugin, |
@@ -504,10 +510,11 @@ def __init__(self, data_dir: str, |
504 | 510 | self.stale_modules = set() # type: Set[str] |
505 | 511 | self.rechecked_modules = set() # type: Set[str] |
506 | 512 | self.flush_errors = flush_errors |
| 513 | + has_reporters = reports is not None and reports.reporters |
507 | 514 | self.cache_enabled = (options.incremental |
508 | 515 | and (not options.fine_grained_incremental |
509 | 516 | or options.use_fine_grained_cache) |
510 | | - and not reports.reporters) |
| 517 | + and not has_reporters) |
511 | 518 | self.fscache = fscache |
512 | 519 | self.find_module_cache = FindModuleCache(self.search_paths, self.fscache, self.options) |
513 | 520 | if options.sqlite_cache: |
@@ -679,7 +686,7 @@ def report_file(self, |
679 | 686 | file: MypyFile, |
680 | 687 | type_map: Dict[Expression, Type], |
681 | 688 | options: Options) -> None: |
682 | | - if self.source_set.is_source(file): |
| 689 | + if self.reports is not None and self.source_set.is_source(file): |
683 | 690 | self.reports.file(file, type_map, options) |
684 | 691 |
|
685 | 692 | def stats_summary(self) -> Mapping[str, object]: |
@@ -1845,6 +1852,7 @@ def compute_fine_grained_deps(self) -> None: |
1845 | 1852 | # TODO: Not a reliable test, as we could have a package named typeshed. |
1846 | 1853 | # TODO: Consider relaxing this -- maybe allow some typeshed changes to be tracked. |
1847 | 1854 | return |
| 1855 | + from mypy.server.deps import get_dependencies # Lazy import to speed up startup |
1848 | 1856 | self.fine_grained_deps = get_dependencies(target=self.tree, |
1849 | 1857 | type_map=self.type_map(), |
1850 | 1858 | python_version=self.options.python_version, |
|
0 commit comments