Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting use_package_names #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions linter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import os
import re
from SublimeLinter.lint import PythonLinter
from SublimeLinter.lint.linter import substitute_variables


logger = logging.getLogger('SublimeLinter.plugins.pylint')
Expand All @@ -20,7 +22,12 @@ class Pylint(PythonLinter):
'paths': [],
'selector': 'source.python',
'--rcfile=': '',
'--init-hook=;': None
'--init-hook=;': None,

# Instead of sending the file *path* to pylint as an arg,
# convert it to a ('dotted') package name relative to the
# working dir.
'use_package_names': False
}

def on_stderr(self, stderr):
Expand Down Expand Up @@ -49,9 +56,30 @@ def cmd(self):
'--module-rgx=.*', # don't check the module name
'--reports=n', # remove tables
'--persistent=n', # don't save the old score (no sense for temp)
'${args}'
'${args}',
'${file_on_disk}'
)

def finalize_cmd(self, cmd, context, **_kwargs):
# Note: `kwargs` and calling `super() is not necessary, bc they
# only implement deprecated features.

settings = self.get_view_settings()
if settings.get('use_package_names', False):
cwd = self.get_working_dir(settings)
filename = context.get('file_on_disk', '')
cwd, filename = map(os.path.normpath, (cwd, filename))

if os.path.commonprefix([cwd, filename]):
rel_path = os.path.relpath(filename, cwd)
package_name = '.'.join(
os.path.splitext(rel_path)[0].split(os.path.sep)
)

cmd = cmd[:-1] + [package_name]

return substitute_variables(context, cmd)

#############
# Try to extract a meaningful columns.
# multiple cases :
Expand Down