From c62586a3dd7991e84482a745edda22483c58d9a2 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 14 Aug 2014 19:28:02 +0200 Subject: [PATCH 1/6] ez_setup: Update to 5.6. --- scripts/ez_setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ez_setup.py b/scripts/ez_setup.py index 6de57c040..4b9eee61b 100644 --- a/scripts/ez_setup.py +++ b/scripts/ez_setup.py @@ -36,7 +36,7 @@ try: except ImportError: USER_SITE = None -DEFAULT_VERSION = "5.5.1" +DEFAULT_VERSION = "5.6" DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/" def _python_cmd(*args): From cc4fd46c6f1a2cd1ccbc290111ae4eba6ea81cf2 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 14 Aug 2014 20:08:30 +0200 Subject: [PATCH 2/6] run_checks: Refactor checks if checker is enabled. --- scripts/run_checks.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/scripts/run_checks.py b/scripts/run_checks.py index bacb17a6e..73980d39e 100755 --- a/scripts/run_checks.py +++ b/scripts/run_checks.py @@ -260,6 +260,17 @@ def _get_checkers(): return checkers +def _checker_enabled(args, group, name): + """Check if a named checker is enabled.""" + if args.checkers == 'all': + if not args.setup and group == 'setup': + return False + else: + return True + else: + return name in args.checkers.split(',') + + def main(): """Main entry point.""" exit_status = OrderedDict() @@ -274,22 +285,19 @@ def main(): groups = ['global'] groups += config.get('DEFAULT', 'targets').split(',') - if args.setup: - groups.append('setup') + groups.append('setup') for group in groups: print() print("==================== {} ====================".format(group)) - if args.checkers == 'all': - configured_checkers = None - else: - configured_checkers = args.checkers.split(',') for name, func in checkers[group].items(): - if configured_checkers is None or name in configured_checkers: - print("------ {} ------".format(name)) + print("------ {} ------".format(name)) + if _checker_enabled(args, group, name): status = func() exit_status['{}_{}'.format(group, name)] = status - + else: + print("Checker disabled.") + print() print("Exit status values:") for (k, v) in exit_status.items(): print(' {} - {}'.format(k, v)) From 0f1c819b896d64529c1bacd7875c3e2adde9dc53 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 14 Aug 2014 20:42:11 +0200 Subject: [PATCH 3/6] run_checks: Add some colors --- scripts/run_checks.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/run_checks.py b/scripts/run_checks.py index 73980d39e..abe566eed 100755 --- a/scripts/run_checks.py +++ b/scripts/run_checks.py @@ -18,7 +18,7 @@ # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see . -# pylint: disable=broad-except +# pylint: disable=broad-except, no-member """ Run different codecheckers over a codebase. @@ -42,6 +42,7 @@ from collections import OrderedDict from functools import partial from contextlib import contextmanager +import colorama as col import pep257 from pkg_resources import load_entry_point, DistributionNotFound @@ -154,7 +155,7 @@ def check_git(): untracked.append(name) if untracked: status = False - print("Untracked files:") + print("{}Untracked files:{}".format(col.Fore.RED, col.Fore.RESET)) print('\n'.join(untracked)) else: status = True @@ -273,6 +274,7 @@ def _checker_enabled(args, group, name): def main(): """Main entry point.""" + col.init() exit_status = OrderedDict() parser = argparse.ArgumentParser(description='Run various checkers.') parser.add_argument('-s', '--setup', help="Run additional setup checks", @@ -289,18 +291,25 @@ def main(): for group in groups: print() - print("==================== {} ====================".format(group)) + print("{}==================== {} ===================={}".format( + col.Fore.YELLOW, group, col.Fore.RESET)) for name, func in checkers[group].items(): - print("------ {} ------".format(name)) + print("{}------ {} ------{}".format(col.Fore.CYAN, name, + col.Fore.RESET)) if _checker_enabled(args, group, name): status = func() exit_status['{}_{}'.format(group, name)] = status else: - print("Checker disabled.") + print("{}Checker disabled.{}".format( + col.Fore.BLUE, col.Fore.RESET)) print() - print("Exit status values:") + print("{}Exit status values:{}".format(col.Fore.YELLOW, col.Fore.RESET)) for (k, v) in exit_status.items(): - print(' {} - {}'.format(k, v)) + if v is True or (not isinstance(v, bool) and v == 0): + color = col.Fore.GREEN + else: + color = col.Fore.RED + print('{} {} - {}{}'.format(color, k, v, col.Fore.RESET)) if all(val in (True, 0) for val in exit_status): return 0 From 7512d766d42e6ca38bb78af091103c754052de0b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 14 Aug 2014 20:58:39 +0200 Subject: [PATCH 4/6] run_checks: Colorize exit status --- scripts/run_checks.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/scripts/run_checks.py b/scripts/run_checks.py index abe566eed..264d43d1a 100755 --- a/scripts/run_checks.py +++ b/scripts/run_checks.py @@ -276,6 +276,7 @@ def main(): """Main entry point.""" col.init() exit_status = OrderedDict() + exit_status_bool = {} parser = argparse.ArgumentParser(description='Run various checkers.') parser.add_argument('-s', '--setup', help="Run additional setup checks", action='store_true') @@ -298,20 +299,29 @@ def main(): col.Fore.RESET)) if _checker_enabled(args, group, name): status = func() - exit_status['{}_{}'.format(group, name)] = status + key = '{}_{}'.format(group, name) + exit_status[key] = status + if name == 'flake8': + # pyflakes uses True for errors and False for ok. + exit_status_bool[key] = not status + elif isinstance(status, bool): + exit_status_bool[key] = status + else: + # sys.exit(0) means no problems -> True, anything != 0 + # means problems. + exit_status_bool[key] = (status == 0) else: print("{}Checker disabled.{}".format( col.Fore.BLUE, col.Fore.RESET)) print() print("{}Exit status values:{}".format(col.Fore.YELLOW, col.Fore.RESET)) for (k, v) in exit_status.items(): - if v is True or (not isinstance(v, bool) and v == 0): - color = col.Fore.GREEN - else: - color = col.Fore.RED - print('{} {} - {}{}'.format(color, k, v, col.Fore.RESET)) + ok = exit_status_bool[k] + color = col.Fore.GREEN if ok else col.Fore.RED + print('{} {} - {} ({}){}'.format(color, k, 'ok' if ok else 'FAIL', + v, col.Fore.RESET)) - if all(val in (True, 0) for val in exit_status): + if all(exit_status_bool): return 0 else: return 1 From 8be3d6f04648451aa60b64340abbd42f082f829d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 14 Aug 2014 21:01:39 +0200 Subject: [PATCH 5/6] Update HACKING --- doc/HACKING.asciidoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/HACKING.asciidoc b/doc/HACKING.asciidoc index 49dcac845..76e7f0fe7 100644 --- a/doc/HACKING.asciidoc +++ b/doc/HACKING.asciidoc @@ -106,8 +106,6 @@ https://docs.python.org/3.4/library/unittest.html[unittest] framework * http://pylint.org/[pylint] * A custom checker for the following things: - untracked git files - - whitespace/CRLF problems - - `set_trace` invocations - VCS conflict markers If you changed `setup.py` or `MANIFEST.in`, add the `--setup` argument to run @@ -116,6 +114,9 @@ the following additional checkers: * https://pypi.python.org/pypi/pyroma/0.9.3[pyroma] * https://github.com/mgedmin/check-manifest[check-manifest] +It needs all the checkers to be installed and also needs +https://pypi.python.org/pypi/colorama/[colorama]. + Please make sure this script runs without any warnings on your new contributions. There's of course the possibility of false-positives, and the following techniques are useful to handle these: From d18a025d6859818ffcc8b70c1a3f42ffde3eb145 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 15 Aug 2014 18:58:46 +0200 Subject: [PATCH 6/6] earlyinit: Beautify messages --- qutebrowser/utils/earlyinit.py | 60 ++++++++++++++++------------------ 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/qutebrowser/utils/earlyinit.py b/qutebrowser/utils/earlyinit.py index c81202fe5..89e714f2a 100644 --- a/qutebrowser/utils/earlyinit.py +++ b/qutebrowser/utils/earlyinit.py @@ -41,30 +41,29 @@ def _missing_str(name, debian=None, arch=None, windows=None, pip=None): windows: String to be displayed for Windows. pip: pypi package name. """ - blocks = ["Fatal error: {} is required to run qutebrowser but could " - "not be imported! Maybe it's not installed?".format(name)] + blocks = ["Fatal error: {} is required to run qutebrowser but " + "could not be imported! Maybe it's not installed?".format(name)] if debian is not None: - lines = ["On Debian/Ubuntu:"] - for line in debian.splitlines(): - lines.append(' ' + line) - blocks.append('\n'.join(lines)) + lines = ["On Debian/Ubuntu:"] + lines += debian.splitlines() + blocks.append('
'.join(lines)) if arch is not None: - lines = ["On Archlinux:"] - for line in arch.splitlines(): - lines.append(' ' + line) - blocks.append('\n'.join(lines)) + lines = ["On Archlinux:"] + lines += arch.splitlines() + blocks.append('
'.join(lines)) if windows is not None: - lines = ["On Windows:"] - for line in windows.splitlines(): - lines.append(' ' + line) - blocks.append('\n'.join(lines)) - lines = ["For other distributions:", - " Check your package manager for similiarly named packages."] + lines = ["On Windows:"] + lines += windows.splitlines() + blocks.append('
'.join(lines)) + lines = ["For other distributions:", + "Check your package manager for similiarly named packages or " + "install via pip."] + blocks.append('
'.join(lines)) if pip is not None: - lines.append(" Or run pip install {} (using python3/pip3)".format( - pip)) - blocks.append('\n'.join(lines)) - return '\n\n'.join(blocks) + lines = ["Using pip:"] + lines.append("pip3 install {}".format(pip)) + blocks.append('
'.join(lines)) + return '

'.join(blocks) def _die(message, exception=True): @@ -77,12 +76,14 @@ def _die(message, exception=True): exception: Whether to print an exception with --debug. """ from PyQt5.QtWidgets import QApplication, QMessageBox + from PyQt5.QtCore import Qt if '--debug' in sys.argv and exception: print(file=sys.stderr) traceback.print_exc() app = QApplication(sys.argv) msgbox = QMessageBox(QMessageBox.Critical, "qutebrowser: Fatal error!", message) + msgbox.setTextFormat(Qt.RichText) msgbox.resize(msgbox.sizeHint()) msgbox.exec_() app.quit() @@ -176,12 +177,15 @@ def check_pyqt_core(): text = _missing_str('PyQt5', debian="apt-get install python3-pyqt5 " "python3-pyqt5.qtwebkit", - arch="pacman -S python-pyqt5 qt5-webkit\n" + arch="pacman -S python-pyqt5 qt5-webkit
" "or install the qutebrowser package from AUR", windows="Use the installer by Riverbank computing " - "or the standalone qutebrowser exe.\n" + "or the standalone qutebrowser exe.
" "http://www.riverbankcomputing.co.uk/" "software/pyqt/download5") + text = text.replace('', '') + text = text.replace('', '') + text = text.replace('
', '\n') if Tk: root = Tk() root.withdraw() @@ -237,15 +241,9 @@ def check_pypeg2(): import pypeg2 # pylint: disable=unused-variable except ImportError: text = _missing_str("pypeg2", - debian="No package available, try:\n" - "pip3 install pypeg2 " - "--allow-external pypeg2 " - "--allow-unverified pypeg2", - arch="pacman -S python-pypeg2", - windows="pip install pypeg2 " - "--allow-external pypeg2 " - "--allow-unverified pypeg2 " - "(using python3)", + debian="No package available, install via pip.", + arch="Install python-pypeg2 from the AUR", + windows="Install via pip.", pip="pypeg2 --allow-external pypeg2 " "--allow-unverified pypeg2") _die(text)