<div dir="ltr">Hi Markus, I understand.  I think a try import followed by a print statement giving directions how to install it if not there could be sufficient? Something like this:<div><br></div><div><div>try:</div><div>   from isort.main import main<br></div><div>except ImportError:</div></div><div>  print &quot;isort not available.  Run &#39;libtbx.python -m pip install isort&#39; and try again.&quot;</div><div>  exit()</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 26, 2017 at 10:19 AM,  <span dir="ltr">&lt;<a href="mailto:markus.gerstel@diamond.ac.uk" target="_blank">markus.gerstel@diamond.ac.uk</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Aaron,<br>
<br>
I didn&#39;t want to add it as a dependency in bootstrap since it is definitely only a developer tool, and I wouldn&#39;t want to install it with a distribution.<br>
I guess we could just run it if it is installed and add a command to install this kinds of development stuff? What do you think?<br>
<br>
-Markus<br>
<br>
______________________________<wbr>__<br>
From: <a href="mailto:cctbxbb-bounces@phenix-online.org">cctbxbb-bounces@phenix-online.<wbr>org</a> [<a href="mailto:cctbxbb-bounces@phenix-online.org">cctbxbb-bounces@phenix-<wbr>online.org</a>] on behalf of Aaron Brewster [<a href="mailto:asbrewster@lbl.gov">asbrewster@lbl.gov</a>]<br>
Sent: Thursday, October 26, 2017 17:54<br>
To: cctbx mailing list<br>
Cc: <a href="mailto:CCTBX-COMMIT@jiscmail.ac.uk">CCTBX-COMMIT@jiscmail.ac.uk</a><br>
Subject: Re: [cctbxbb] [git/cctbx] master: libtbx.clean_clutter runs isort in supported locations (612869130)<br>
<span class=""><br>
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&#39;m nervous about pip being imported anywhere in our code, especially to install things when running code unrelated to installation.<br>
<br>
It&#39;s important to keep installation of stuff separate from running of stuff.  Otherwise, it&#39;s impossible to keep dependencies straight.<br>
<br>
-Aaron<br>
<br>
</span>On Thu, Oct 26, 2017 at 2:29 AM, CCTBX Commit via DLS Jenkins &lt;<a href="mailto:graeme.winter@gmail.com">graeme.winter@gmail.com</a>&lt;<wbr>mailto:<a href="mailto:graeme.winter@gmail.com">graeme.winter@gmail.com</a><wbr>&gt;&gt; wrote:<br>
Repository : ssh://<a href="http://g18-sc-serv-04.diamond.ac.uk/cctbx" rel="noreferrer" target="_blank">g18-sc-serv-04.diamond.<wbr>ac.uk/cctbx</a>&lt;<a href="http://g18-sc-serv-04.diamond.ac.uk/cctbx" rel="noreferrer" target="_blank">http://g18-sc-<wbr>serv-04.diamond.ac.uk/cctbx</a>&gt;<br>
<span class="">On branch  : master<br>
<br>
______________________________<wbr>__<br>
<br>
<br>
commit 612869130a6210d49a573a3cff0441<wbr>6a9de67808<br>
</span>Author: Markus Gerstel &lt;<a href="mailto:markus.gerstel@diamond.ac.uk">markus.gerstel@diamond.ac.uk</a>&lt;<wbr>mailto:<a href="mailto:markus.gerstel@diamond.ac.uk">markus.gerstel@diamond.<wbr>ac.uk</a>&gt;&gt;<br>
<div class="HOEnZb"><div class="h5">Date:   Thu Oct 26 10:29:05 2017 +0100<br>
<br>
    libtbx.clean_clutter runs isort in supported locations<br>
<br>
<br>
______________________________<wbr>__<br>
<br>
<br>
612869130a6210d49a573a3cff0441<wbr>6a9de67808<br>
libtbx/command_line/clean_<wbr>clutter.py | 26 ++++++++++++++++++++++++++<br>
1 file changed, 26 insertions(+)<br>
<br>
diff --git a/libtbx/command_line/clean_<wbr>clutter.py b/libtbx/command_line/clean_<wbr>clutter.py<br>
index d49bf4c25..8fc2e53c8 100644<br>
--- a/libtbx/command_line/clean_<wbr>clutter.py<br>
+++ b/libtbx/command_line/clean_<wbr>clutter.py<br>
@@ -32,6 +32,24 @@ def clean_clutter_in(files, tabsize=8):<br>
         os.remove(tmpname)<br>
         raise<br>
<br>
+def isort(path):<br>
+  try:<br>
+    import mock<br>
+    from isort.main import main<br>
+  except ImportError:<br>
+    # Install package if necessary<br>
+    import pip<br>
+    pip.main([&#39;install&#39;, &#39;isort&#39;, &#39;mock&#39;])<br>
+    import mock<br>
+    from isort.main import main<br>
+  with mock.patch.object(sys, &#39;argv&#39;, [&#39;isort&#39;, &#39;-y&#39;, &#39;-ac&#39;, &#39;-vb&#39;]):<br>
+    oldcwd = os.getcwd()<br>
+    try:<br>
+      os.chdir(path)<br>
+      main()<br>
+    finally:<br>
+      os.chdir(oldcwd)<br>
+<br>
def run():<br>
   opt_parser = (option_parser(<br>
     usage=&quot;&quot;&quot;<br>
@@ -60,6 +78,7 @@ by running svn commit.&quot;&quot;&quot;)<br>
   if co.committing and files:<br>
       opt_parser.show_help()<br>
       exit(1)<br>
+  run_isort_in_path = False<br>
   if co.committing:<br>
     try:<br>
       files = list(subversion.marked_for_<wbr>commit())<br>
@@ -72,7 +91,14 @@ by running svn commit.&quot;&quot;&quot;)<br>
       else: dir = files[0]<br>
       files = [ c.path for c in libtbx.file_clutter.gather([<wbr>dir])<br>
                 if c.is_cluttered(flag_x=False) ]<br>
+      if os.path.exists(os.path.join(<wbr>dir, &#39;.isort.cfg&#39;)):<br>
+        run_isort_in_path = dir<br>
   clean_clutter_in(files, tabsize=co.tabsize)<br>
+  if run_isort_in_path:<br>
+    try:<br>
+      isort(run_isort_in_path)<br>
+    except Exception as e:<br>
+      print(&quot;Did not run isort (%s)&quot; % str(e))<br>
<br>
if (__name__ == &quot;__main__&quot;):<br>
   import sys<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.<br>
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.<br>
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.<br>
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom<br>
<br>
<br>
______________________________<wbr>_________________<br>
cctbxbb mailing list<br>
<a href="mailto:cctbxbb@phenix-online.org">cctbxbb@phenix-online.org</a><br>
<a href="http://phenix-online.org/mailman/listinfo/cctbxbb" rel="noreferrer" target="_blank">http://phenix-online.org/<wbr>mailman/listinfo/cctbxbb</a><br>
</font></span></blockquote></div><br></div>