diff options
author | vries <vries@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-05-29 07:30:47 +0000 |
---|---|---|
committer | vries <vries@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-05-29 07:30:47 +0000 |
commit | 80885f4fc0c15dd2c2739e9537fa4ff9409b3068 (patch) | |
tree | 7e2edfa01c1d873a8ca8ea1e274c69b9975aa149 | |
parent | 831c3f49ec3438b138342f32ae6a953d23a0a0db (diff) | |
download | gcc-80885f4fc0c15dd2c2739e9537fa4ff9409b3068.tar.gz |
check_GNU_style_lib.py: Suggest to install all missing pip3 packages at once
Instead of:
...
$ ./contrib/check_GNU_style.py
termcolor module is missing (run: pip3 install termcolor)
$ pip3 install termcolor
$ ./contrib/check_GNU_style.py
unidiff module is missing (run: pip3 install unidiff)
$ pip3 install unidiff
$
...
Do:
...
$ ./contrib/check_GNU_style.py
termcolor and unidiff modules are missing (run: pip3 install termcolor unidiff)
$ pip3 install termcolor unidiff
$
...
2017-05-29 Tom de Vries <tom@codesourcery.com>
* check_GNU_style_lib.py: Use import_pip3 to import pip3 packages.
(import_pip3): New function.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248554 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | contrib/ChangeLog | 5 | ||||
-rwxr-xr-x | contrib/check_GNU_style_lib.py | 34 |
2 files changed, 28 insertions, 11 deletions
diff --git a/contrib/ChangeLog b/contrib/ChangeLog index ae0c246f4eb..582850857a8 100644 --- a/contrib/ChangeLog +++ b/contrib/ChangeLog @@ -1,3 +1,8 @@ +2017-05-29 Tom de Vries <tom@codesourcery.com> + + * check_GNU_style_lib.py: Use import_pip3 to import pip3 packages. + (import_pip3): New function. + 2017-05-24 Tom de Vries <tom@codesourcery.com> * check_GNU_style_lib.py: New file, factored out of ... diff --git a/contrib/check_GNU_style_lib.py b/contrib/check_GNU_style_lib.py index a1224c11008..d924e68ecbc 100755 --- a/contrib/check_GNU_style_lib.py +++ b/contrib/check_GNU_style_lib.py @@ -28,17 +28,29 @@ import sys import re import unittest -try: - from termcolor import colored -except ImportError: - print('termcolor module is missing (run: pip3 install termcolor)') - exit(3) - -try: - from unidiff import PatchSet -except ImportError: - print('unidiff module is missing (run: pip3 install unidiff)') - exit(3) +def import_pip3(*args): + missing=[] + for (module, names) in args: + try: + lib = __import__(module) + except ImportError: + missing.append(module) + continue + if not isinstance(names, list): + names=[names] + for name in names: + globals()[name]=getattr(lib, name) + if len(missing) > 0: + missing_and_sep = ' and '.join(missing) + missing_space_sep = ' '.join(missing) + print('%s %s missing (run: pip3 install %s)' + % (missing_and_sep, + ("module is" if len(missing) == 1 else "modules are"), + missing_space_sep)) + exit(3) + +import_pip3(('termcolor', 'colored'), + ('unidiff', 'PatchSet')) from itertools import * |