pre-commit 753 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. from __future__ import absolute_import
  3. import os
  4. import sys
  5. from glob import glob
  6. from sentry.lint.engine import check_files
  7. text_type = type(u'')
  8. # git usurbs your bin path for hooks and will always run system python
  9. if 'VIRTUAL_ENV' in os.environ:
  10. site_packages = glob(
  11. '%s/lib/*/site-packages' % os.environ['VIRTUAL_ENV'])[0]
  12. sys.path.insert(0, site_packages)
  13. def main():
  14. from flake8.hooks import run
  15. gitcmd = "git diff-index --cached --name-only HEAD"
  16. _, files_modified, _ = run(gitcmd)
  17. files_modified = [
  18. text_type(f)
  19. for f in files_modified
  20. if os.path.exists(f)
  21. ]
  22. return check_files(files_modified)
  23. if __name__ == '__main__':
  24. sys.exit(main())