Hi Markus, could isort be added as a dependency instead?  If I understand this commit right, when running libtbx.clean_clutter, if .isort.cfg is present and isort is not installed, pip is invoked to install isort.  l'm nervous about pip being imported anywhere in our code, especially to install things when running code unrelated to installation.

It's important to keep installation of stuff separate from running of stuff.  Otherwise, it's impossible to keep dependencies straight.

-Aaron

On Thu, Oct 26, 2017 at 2:29 AM, CCTBX Commit via DLS Jenkins <graeme.winter@gmail.com> wrote:
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_clutter.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