Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Set --ignore-missing-imports for mypy linter if not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jun 15, 2017
1 parent 9373acc commit 98072cc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions badwolf/lint/linters/mypy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import os
import logging

from badwolf.utils import run_command
Expand Down Expand Up @@ -33,6 +34,8 @@ def lint_files(self, files):
'--follow-imports',
'silent',
]
if not self._is_ignore_missing_imports_configured():
command.append('--ignore-missing-imports')
command += files
_, output = run_command(command, split=True, include_errors=True, cwd=self.working_dir)
if not output:
Expand All @@ -50,3 +53,18 @@ def _parse_line(self, line):
Parse the output for real data."""
parts = line.split(':', 3)
return parts[0], int(parts[1]), parts[2].strip(), parts[3].strip()

def _is_ignore_missing_imports_configured(self):
files = [
os.path.join(self.working_dir, 'mypy.ini'),
os.path.join(self.working_dir, 'setup.cfg'),
]
for path in files:
try:
with open(path, 'r', encoding='utf-8') as f:
config = f.read()
except OSError:
continue
if 'ignore_missing_imports' in config:
return True
return False

0 comments on commit 98072cc

Please sign in to comment.