Re: [cctbxbb] [git/cctbx] master: libtbx.clean_clutter runs isort in supported locations (612869130)
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 < [email protected]> wrote:
Repository : ssh://g18-sc-serv-04.diamond.ac.uk/cctbx On branch : master
------------------------------
commit 612869130a6210d49a573a3cff04416a9de67808 Author: Markus Gerstel
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
Hi Aaron,
I didn't want to add it as a dependency in bootstrap since it is definitely only a developer tool, and I wouldn't want to install it with a distribution.
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?
-Markus
________________________________
From: [email protected] [[email protected]] on behalf of Aaron Brewster [[email protected]]
Sent: Thursday, October 26, 2017 17:54
To: cctbx mailing list
Cc: [email protected]
Subject: Re: [cctbxbb] [git/cctbx] master: libtbx.clean_clutter runs isort in supported locations (612869130)
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
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:
try:
from isort.main import main
except ImportError:
print "isort not available. Run 'libtbx.python -m pip install isort' and
try again."
exit()
On Thu, Oct 26, 2017 at 10:19 AM,
Hi Aaron,
I didn't want to add it as a dependency in bootstrap since it is definitely only a developer tool, and I wouldn't want to install it with a distribution. 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?
-Markus
________________________________ From: [email protected] [[email protected]] on behalf of Aaron Brewster [[email protected]] Sent: Thursday, October 26, 2017 17:54 To: cctbx mailing list Cc: [email protected] Subject: Re: [cctbxbb] [git/cctbx] master: libtbx.clean_clutter runs isort in supported locations (612869130)
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 < [email protected]mailto:[email protected]> wrote: Repository : ssh://g18-sc-serv-04.diamond.ac.uk/cctbx<http://g18-sc- serv-04.diamond.ac.uk/cctbx> On branch : master
________________________________
commit 612869130a6210d49a573a3cff04416a9de67808 Author: Markus Gerstel
> 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
-- 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. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. 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. 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
_______________________________________________ cctbxbb mailing list [email protected] http://phenix-online.org/mailman/listinfo/cctbxbb
participants (2)
-
Aaron Brewster
-
markus.gerstel@diamond.ac.uk