Skip to content

Commit

Permalink
build: log build sources with -v (#9672)
Browse files Browse the repository at this point in the history
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.

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja authored Oct 31, 2020
1 parent 7e66e51 commit fd16f84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
24 changes: 6 additions & 18 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<BuildSource path=%r module=%r has_text=%s base_dir=%s>' % (
return 'BuildSource(path=%r, module=%r, has_text=%s, base_dir=%r)' % (
self.path,
self.module,
self.text is not None,
Expand Down

0 comments on commit fd16f84

Please sign in to comment.