Merge branch 'master' of ssh://cmpl.cc:2323/qutebrowser

This commit is contained in:
Florian Bruhin 2014-08-20 15:08:07 +02:00
commit 05727b2584
4 changed files with 76 additions and 50 deletions

View File

@ -106,8 +106,6 @@ https://docs.python.org/3.4/library/unittest.html[unittest] framework
* http://pylint.org/[pylint] * http://pylint.org/[pylint]
* A custom checker for the following things: * A custom checker for the following things:
- untracked git files - untracked git files
- whitespace/CRLF problems
- `set_trace` invocations
- VCS conflict markers - VCS conflict markers
If you changed `setup.py` or `MANIFEST.in`, add the `--setup` argument to run 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://pypi.python.org/pypi/pyroma/0.9.3[pyroma]
* https://github.com/mgedmin/check-manifest[check-manifest] * 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 Please make sure this script runs without any warnings on your new
contributions. There's of course the possibility of false-positives, and the contributions. There's of course the possibility of false-positives, and the
following techniques are useful to handle these: following techniques are useful to handle these:

View File

@ -41,30 +41,29 @@ def _missing_str(name, debian=None, arch=None, windows=None, pip=None):
windows: String to be displayed for Windows. windows: String to be displayed for Windows.
pip: pypi package name. pip: pypi package name.
""" """
blocks = ["Fatal error: {} is required to run qutebrowser but could " blocks = ["Fatal error: <b>{}</b> is required to run qutebrowser but "
"not be imported! Maybe it's not installed?".format(name)] "could not be imported! Maybe it's not installed?".format(name)]
if debian is not None: if debian is not None:
lines = ["On Debian/Ubuntu:"] lines = ["<b>On Debian/Ubuntu:</b>"]
for line in debian.splitlines(): lines += debian.splitlines()
lines.append(' ' + line) blocks.append('<br />'.join(lines))
blocks.append('\n'.join(lines))
if arch is not None: if arch is not None:
lines = ["On Archlinux:"] lines = ["<b>On Archlinux:</b>"]
for line in arch.splitlines(): lines += arch.splitlines()
lines.append(' ' + line) blocks.append('<br />'.join(lines))
blocks.append('\n'.join(lines))
if windows is not None: if windows is not None:
lines = ["On Windows:"] lines = ["<b>On Windows:</b>"]
for line in windows.splitlines(): lines += windows.splitlines()
lines.append(' ' + line) blocks.append('<br />'.join(lines))
blocks.append('\n'.join(lines)) lines = ["<b>For other distributions:</b>",
lines = ["For other distributions:", "Check your package manager for similiarly named packages or "
" Check your package manager for similiarly named packages."] "install via pip."]
blocks.append('<br />'.join(lines))
if pip is not None: if pip is not None:
lines.append(" Or run pip install {} (using python3/pip3)".format( lines = ["<b>Using pip:</b>"]
pip)) lines.append("pip3 install {}".format(pip))
blocks.append('\n'.join(lines)) blocks.append('<br />'.join(lines))
return '\n\n'.join(blocks) return '<br /><br />'.join(blocks)
def _die(message, exception=True): def _die(message, exception=True):
@ -77,12 +76,14 @@ def _die(message, exception=True):
exception: Whether to print an exception with --debug. exception: Whether to print an exception with --debug.
""" """
from PyQt5.QtWidgets import QApplication, QMessageBox from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import Qt
if '--debug' in sys.argv and exception: if '--debug' in sys.argv and exception:
print(file=sys.stderr) print(file=sys.stderr)
traceback.print_exc() traceback.print_exc()
app = QApplication(sys.argv) app = QApplication(sys.argv)
msgbox = QMessageBox(QMessageBox.Critical, "qutebrowser: Fatal error!", msgbox = QMessageBox(QMessageBox.Critical, "qutebrowser: Fatal error!",
message) message)
msgbox.setTextFormat(Qt.RichText)
msgbox.resize(msgbox.sizeHint()) msgbox.resize(msgbox.sizeHint())
msgbox.exec_() msgbox.exec_()
app.quit() app.quit()
@ -176,12 +177,15 @@ def check_pyqt_core():
text = _missing_str('PyQt5', text = _missing_str('PyQt5',
debian="apt-get install python3-pyqt5 " debian="apt-get install python3-pyqt5 "
"python3-pyqt5.qtwebkit", "python3-pyqt5.qtwebkit",
arch="pacman -S python-pyqt5 qt5-webkit\n" arch="pacman -S python-pyqt5 qt5-webkit<br />"
"or install the qutebrowser package from AUR", "or install the qutebrowser package from AUR",
windows="Use the installer by Riverbank computing " windows="Use the installer by Riverbank computing "
"or the standalone qutebrowser exe.\n" "or the standalone qutebrowser exe.<br />"
"http://www.riverbankcomputing.co.uk/" "http://www.riverbankcomputing.co.uk/"
"software/pyqt/download5") "software/pyqt/download5")
text = text.replace('<b>', '')
text = text.replace('</b>', '')
text = text.replace('<br />', '\n')
if Tk: if Tk:
root = Tk() root = Tk()
root.withdraw() root.withdraw()
@ -237,15 +241,9 @@ def check_pypeg2():
import pypeg2 # pylint: disable=unused-variable import pypeg2 # pylint: disable=unused-variable
except ImportError: except ImportError:
text = _missing_str("pypeg2", text = _missing_str("pypeg2",
debian="No package available, try:\n" debian="No package available, install via pip.",
"pip3 install pypeg2 " arch="Install python-pypeg2 from the AUR",
"--allow-external pypeg2 " windows="Install via pip.",
"--allow-unverified pypeg2",
arch="pacman -S python-pypeg2",
windows="pip install pypeg2 "
"--allow-external pypeg2 "
"--allow-unverified pypeg2 "
"(using python3)",
pip="pypeg2 --allow-external pypeg2 " pip="pypeg2 --allow-external pypeg2 "
"--allow-unverified pypeg2") "--allow-unverified pypeg2")
_die(text) _die(text)

View File

@ -36,7 +36,7 @@ try:
except ImportError: except ImportError:
USER_SITE = None USER_SITE = None
DEFAULT_VERSION = "5.5.1" DEFAULT_VERSION = "5.6"
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/" DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
def _python_cmd(*args): def _python_cmd(*args):

View File

@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
# pylint: disable=broad-except # pylint: disable=broad-except, no-member
""" Run different codecheckers over a codebase. """ Run different codecheckers over a codebase.
@ -42,6 +42,7 @@ from collections import OrderedDict
from functools import partial from functools import partial
from contextlib import contextmanager from contextlib import contextmanager
import colorama as col
import pep257 import pep257
from pkg_resources import load_entry_point, DistributionNotFound from pkg_resources import load_entry_point, DistributionNotFound
@ -154,7 +155,7 @@ def check_git():
untracked.append(name) untracked.append(name)
if untracked: if untracked:
status = False status = False
print("Untracked files:") print("{}Untracked files:{}".format(col.Fore.RED, col.Fore.RESET))
print('\n'.join(untracked)) print('\n'.join(untracked))
else: else:
status = True status = True
@ -260,9 +261,22 @@ def _get_checkers():
return 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(): def main():
"""Main entry point.""" """Main entry point."""
col.init()
exit_status = OrderedDict() exit_status = OrderedDict()
exit_status_bool = {}
parser = argparse.ArgumentParser(description='Run various checkers.') parser = argparse.ArgumentParser(description='Run various checkers.')
parser.add_argument('-s', '--setup', help="Run additional setup checks", parser.add_argument('-s', '--setup', help="Run additional setup checks",
action='store_true') action='store_true')
@ -274,27 +288,40 @@ def main():
groups = ['global'] groups = ['global']
groups += config.get('DEFAULT', 'targets').split(',') groups += config.get('DEFAULT', 'targets').split(',')
if args.setup:
groups.append('setup') groups.append('setup')
for group in groups: for group in groups:
print() print()
print("==================== {} ====================".format(group)) print("{}==================== {} ===================={}".format(
if args.checkers == 'all': col.Fore.YELLOW, group, col.Fore.RESET))
configured_checkers = None
else:
configured_checkers = args.checkers.split(',')
for name, func in checkers[group].items(): for name, func in checkers[group].items():
if configured_checkers is None or name in configured_checkers: print("{}------ {} ------{}".format(col.Fore.CYAN, name,
print("------ {} ------".format(name)) col.Fore.RESET))
if _checker_enabled(args, group, name):
status = func() status = func()
exit_status['{}_{}'.format(group, name)] = status key = '{}_{}'.format(group, name)
exit_status[key] = status
print("Exit status values:") 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(): for (k, v) in exit_status.items():
print(' {} - {}'.format(k, v)) 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 return 0
else: else:
return 1 return 1