Repository : ssh://g18-sc-serv-04.diamond.ac.uk/cctbx
On branch : master
commit 612869130a6210d49a573a3cff04416a9de67808
Author: Markus Gerstel <markus.gerstel@diamond.ac.uk>
Date: Thu Oct 26 10:29:05 2017 +0100
libtbx.clean_clutter runs isort in supported locations
612869130a6210d49a573a3cff04416a9de67808
libtbx/command_line/clean_clutter.py | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/libtbx/command_line/clean_clutter.py b/libtbx/command_line/clean_cl utter.py
index d49bf4c25..8fc2e53c8 100644
--- a/libtbx/command_line/clean_clutter.py
+++ b/libtbx/command_line/clean_clutter.py
@@ -32,6 +32,24 @@ def clean_clutter_in(files, tabsize=8):
os.remove(tmpname)
raise
+def isort(path):
+ try:
+ import mock
+ from isort.main import main
+ except ImportError:
+ # Install package if necessary
+ import pip
+ pip.main(['install', 'isort', 'mock'])
+ import mock
+ from isort.main import main
+ with mock.patch.object(sys, 'argv', ['isort', '-y', '-ac', '-vb']):
+ oldcwd = os.getcwd()
+ try:
+ os.chdir(path)
+ main()
+ finally:
+ os.chdir(oldcwd)
+
def run():
opt_parser = (option_parser(
usage="""
@@ -60,6 +78,7 @@ by running svn commit.""")
if co.committing and files:
opt_parser.show_help()
exit(1)
+ run_isort_in_path = False
if co.committing:
try:
files = list(subversion.marked_for_commit())
@@ -72,7 +91,14 @@ by running svn commit.""")
else: dir = files[0]
files = [ c.path for c in libtbx.file_clutter.gather([dir])
if c.is_cluttered(flag_x=False) ]
+ if os.path.exists(os.path.join(dir, '.isort.cfg')):
+ run_isort_in_path = dir
clean_clutter_in(files, tabsize=co.tabsize)
+ if run_isort_in_path:
+ try:
+ isort(run_isort_in_path)
+ except Exception as e:
+ print("Did not run isort (%s)" % str(e))
if (__name__ == "__main__"):
import sys