From 70002e941ef3328680520e83119ee59e9e7c24e6 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Fri, 30 Oct 2020 18:13:39 -0700 Subject: [PATCH] build: log build sources with -v With the changes I've been making to mypy's import handling, I think this would be a useful thing to add preemptively. Note that I would have found this very useful at points, and I think others would too, eg #7672 and #8584 The existing logging ignores source_modules and source_text and won't help with determining what mypy things the module name for a given file is, which is useful for namespace package issues as in the complaint in #8584. --- mypy/build.py | 24 ++++++------------------ mypy/modulefinder.py | 2 +- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index b18c57dcc441..d956a828fed7 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -2541,37 +2541,25 @@ def skipping_ancestor(manager: BuildManager, id: str, path: str, ancestor_for: ' severity='note', only_once=True) -def log_configuration(manager: BuildManager) -> None: +def log_configuration(manager: BuildManager, sources: List[BuildSource]) -> None: """Output useful configuration information to LOG and TRACE""" manager.log() configuration_vars = [ ("Mypy Version", __version__), ("Config File", (manager.options.config_file or "Default")), - ] - - src_pth_str = "Source Path" - src_pths = list(manager.source_set.source_paths.copy()) - src_pths.sort() - - if len(src_pths) > 1: - src_pth_str += "s" - configuration_vars.append((src_pth_str, " ".join(src_pths))) - elif len(src_pths) == 1: - configuration_vars.append((src_pth_str, src_pths.pop())) - else: - configuration_vars.append((src_pth_str, "None")) - - configuration_vars.extend([ ("Configured Executable", manager.options.python_executable or "None"), ("Current Executable", sys.executable), ("Cache Dir", manager.options.cache_dir), ("Compiled", str(not __file__.endswith(".py"))), - ]) + ] for conf_name, conf_value in configuration_vars: manager.log("{:24}{}".format(conf_name + ":", conf_value)) + for source in sources: + manager.log("{:24}{}".format("Found source:", source)) + # Complete list of searched paths can get very long, put them under TRACE for path_type, paths in manager.search_paths._asdict().items(): if not paths: @@ -2591,7 +2579,7 @@ def dispatch(sources: List[BuildSource], manager: BuildManager, stdout: TextIO, ) -> Graph: - log_configuration(manager) + log_configuration(manager, sources) t0 = time.time() graph = load_graph(sources, manager) diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index 576354c5abcb..e2fce6e46cfd 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -85,7 +85,7 @@ def __init__(self, path: Optional[str], module: Optional[str], self.base_dir = base_dir # Directory where the package is rooted (e.g. 'xxx/yyy') def __repr__(self) -> str: - return '' % ( + return 'BuildSource(path=%r, module=%r, has_text=%s, base_dir=%r)' % ( self.path, self.module, self.text is not None,