Skip to content

Commit

Permalink
allow linters to change how chdir is computed
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Solka committed Apr 15, 2016
1 parent 628befa commit 2bd6196
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lint/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,20 @@ def build_options(self, options, type_map, transform=None):

options[name] = value


def get_chdir(self, settings):
chdir = settings.get('chdir', None)

if chdir and os.path.isdir(chdir):
return chdir
persist.debug('chdir has been set to: {0}'.format(chdir))
else:
if self.filename:
return os.path.dirname(self.filename)
else:
return os.path.realpath('.')


def lint(self, hit_time):
"""
Perform the lint, retrieve the results, and add marks to the view.
Expand All @@ -1370,15 +1384,7 @@ def lint(self, hit_time):
return

settings = self.get_view_settings()
self.chdir = settings.get('chdir', None)

if self.chdir and os.path.isdir(self.chdir):
persist.debug('chdir has been set to: {0}'.format(self.chdir))
else:
if self.filename:
self.chdir = os.path.dirname(self.filename)
else:
self.chdir = os.path.realpath('.')
self.chdir = self.get_chdir(settings)

with util.cd(self.chdir):
output = self.run(cmd, self.code)
Expand Down

0 comments on commit 2bd6196

Please sign in to comment.