Skip to content

Commit

Permalink
added setting to configure MYPYPATH for MyPy linter, resolves #581
Browse files Browse the repository at this point in the history
  • Loading branch information
DamnWidget committed Nov 10, 2016
1 parent 07d1772 commit d6972bd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Anaconda.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@
*/
"mypy": false,

/*
Set the following variable to set MyPy MYPYPATH
*/
"mypy_mypypath": "",

/*
MyPy Silent Imports
Expand Down
9 changes: 7 additions & 2 deletions anaconda_lib/linting/anaconda_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class MyPy(object):
"""MyPy class for Anaconda
"""

def __init__(self, code, filename, settings):
def __init__(self, code, filename, mypypath, settings):
self.code = code
self.filename = filename
self.mypypath = mypypath
self.settings = settings

@property
Expand Down Expand Up @@ -71,10 +72,14 @@ def check_source(self):
sys.executable, err_ctx,
' '.join(self.settings[:-1]), self.filename)
)
env = os.environ.copy()
if self.mypypath is not None and self.mypypath != "":
env['MYPYPATH'] = self.mypypath

kwargs = {
'cwd': os.path.dirname(os.path.abspath(__file__)),
'bufsize': -1,
'env': os.environ.copy()
'env': env
}
if os.name == 'nt':
startupinfo = subprocess.STARTUPINFO()
Expand Down
3 changes: 2 additions & 1 deletion anaconda_lib/linting/sublime.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ def run_linter(view=None, hook=None):
'pyflakes_explicit_ignore': get_settings(
view, 'pyflakes_explicit_ignore', []),
'use_mypy': get_settings(view, 'mypy', False),
'mypy_settings': get_mypy_settings(view)
'mypy_settings': get_mypy_settings(view),
'mypypath': get_settings(view, 'mypy_mypypath', '')
}

text = view.substr(sublime.Region(0, view.size()))
Expand Down
8 changes: 6 additions & 2 deletions anaconda_server/commands/mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ class MyPy(Command):
"""Run mypy linter and return back results
"""

def __init__(self, callback, uid, vid, linter, code, filename, settings):
def __init__(
self, callback, uid, vid, linter,
code, filename, mypypath, settings):
self.vid = vid
self.code = code
self.filename = filename
self.mypypath = mypypath
self.settings = settings['mypy_settings']
self.linter = linter
super(MyPy, self).__init__(callback, uid)
Expand All @@ -28,7 +31,8 @@ def run(self):
self.callback({
'success': True,
'errors': self.linter(
self.code, self.filename, self.settings).execute(),
self.code, self.filename, self.mypypath, self.settings
).execute(),
'uid': self.uid,
'vid': self.vid,
})
Expand Down
8 changes: 7 additions & 1 deletion anaconda_server/handlers/python_lint_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def mypy(self, settings, code=None, filename=None):
"""

lint = AnacondaMyPy
MyPy(self._merge, self.uid, self.vid, lint, code, filename, settings)
MyPy(
self._merge, self.uid, self.vid, lint,
code, filename, self.mypypath, settings
)

def _normalize(self, settings, data):
"""Normalize pylint data before to merge
Expand Down Expand Up @@ -168,6 +171,9 @@ def _configure_linters(self, settings):
if self._linters['pylint'] is True:
self._linters['pyflakes'] = False

if self._linters['mypy']:
self.mypypath = settings.get('mypypath')

def _merge(self, lint_result):
"""Merge the given linter results
"""
Expand Down

0 comments on commit d6972bd

Please sign in to comment.