Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pylama_isort.py 785B

1234567891011121314151617181920212223242526272829
  1. import os
  2. import sys
  3. from pylama.lint import Linter as BaseLinter
  4. from .isort import SortImports
  5. class Linter(BaseLinter):
  6. def allow(self, path):
  7. """Determine if this path should be linted."""
  8. return path.endswith('.py')
  9. def run(self, path, **meta):
  10. """Lint the file. Return an array of error dicts if appropriate."""
  11. with open(os.devnull, 'w') as devnull:
  12. # Suppress isort messages
  13. sys.stdout = devnull
  14. if SortImports(path, check=True).incorrectly_sorted:
  15. return [{
  16. 'lnum': 0,
  17. 'col': 0,
  18. 'text': 'Incorrectly sorted imports.',
  19. 'type': 'ISORT'
  20. }]
  21. else:
  22. return []