Fix lint in scripts

This commit is contained in:
Florian Bruhin 2014-05-15 08:24:10 +02:00
parent 5de6084e50
commit 7f3a21e4f0
6 changed files with 26 additions and 15 deletions

View File

@ -0,0 +1 @@
"""Various scripts used to develop/install qutebrowser."""

View File

@ -32,14 +32,16 @@ lint = ['build', 'dist', 'pkg/pkg', 'pkg/qutebrowser-*.pkg.tar.xz', 'pkg/src',
'setuptools-*.zip'] 'setuptools-*.zip']
def remove(path): def remove(path):
"""Remove either a file or directory unless --dry-run is given."""
if os.path.isdir(path): if os.path.isdir(path):
print("rm -r '{}'".format(path)) print("rm -r '{}'".format(path))
if not '--dry-run' in sys.argv: shutil.rmtree(path) if not '--dry-run' in sys.argv:
shutil.rmtree(path)
else: else:
print("rm '{}'".format(path)) print("rm '{}'".format(path))
if not '--dry-run' in sys.argv: os.remove(path) if not '--dry-run' in sys.argv:
os.remove(path)
for elem in lint: for elem in lint:

View File

@ -80,8 +80,8 @@ executable = Executable('qutebrowser/__main__.py', base=base,
try: try:
write_git_file() write_git_file()
setup( setup(
executables = [executable], executables=[executable],
options = { options={
'build_exe': build_exe_options, 'build_exe': build_exe_options,
'bdist_msi': bdist_msi_options, 'bdist_msi': bdist_msi_options,
}, },

View File

@ -15,6 +15,8 @@
# 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
""" Run different codecheckers over a codebase. """ Run different codecheckers over a codebase.
Runs flake8, pylint, pep257, a CRLF/whitespace/conflict-checker and pyroma by Runs flake8, pylint, pep257, a CRLF/whitespace/conflict-checker and pyroma by
@ -71,6 +73,7 @@ if os.name == 'nt':
# arrows in configdata.py # arrows in configdata.py
options['exclude_pep257'].append('configdata.py') options['exclude_pep257'].append('configdata.py')
def run(name, target, args=None): def run(name, target, args=None):
"""Run a checker via distutils with optional args. """Run a checker via distutils with optional args.
@ -122,18 +125,20 @@ def check_pep257(target, args=None):
def check_unittest(): def check_unittest():
"""Run the unittest checker."""
print("==================== unittest ====================") print("==================== unittest ====================")
suite = unittest.TestLoader().discover('.') suite = unittest.TestLoader().discover('.')
result = unittest.TextTestRunner().run(suite) result = unittest.TextTestRunner().run(suite)
print() print()
status['unittest'] = result.wasSuccessful() status['unittest'] = result.wasSuccessful()
def check_line(target): def check_line(target):
"""Run _check_file over a filetree.""" """Run _check_file over a filetree."""
print("------ line ------") print("------ line ------")
ret = [] ret = []
try: try:
for (dirpath, dirnames, filenames) in os.walk(target): for (dirpath, _dirnames, filenames) in os.walk(target):
for name in (e for e in filenames if e.endswith('.py')): for name in (e for e in filenames if e.endswith('.py')):
fn = os.path.join(dirpath, name) fn = os.path.join(dirpath, name)
ret.append(_check_file(fn)) ret.append(_check_file(fn))
@ -170,6 +175,7 @@ def _get_args(checker):
Return: Return:
A list of commandline arguments. A list of commandline arguments.
""" """
# pylint: disable=too-many-branches
args = [] args = []
if checker == 'pylint': if checker == 'pylint':
try: try:
@ -206,7 +212,7 @@ def _get_args(checker):
except KeyError: except KeyError:
pass pass
try: try:
args += ['--match=(?!{}).*\.py'.format('|'.join( args += [r'--match=(?!{}).*\.py'.format('|'.join(
options['exclude'] + options['exclude_pep257']))] options['exclude'] + options['exclude_pep257']))]
except KeyError: except KeyError:
pass pass
@ -220,14 +226,14 @@ def _get_args(checker):
check_unittest() check_unittest()
for target in options['targets']: for trg in options['targets']:
print("==================== {} ====================".format(target)) print("==================== {} ====================".format(trg))
if do_check_257: if do_check_257:
check_pep257(target, _get_args('pep257')) check_pep257(trg, _get_args('pep257'))
for checker in ['pylint', 'flake8', 'pyroma']: for chk in ['pylint', 'flake8', 'pyroma']:
# FIXME what the hell is the flake8 exit status? # FIXME what the hell is the flake8 exit status?
run(checker, target, _get_args(checker)) run(chk, trg, _get_args(chk))
check_line(target, ) check_line(trg, )
print("Exit status values:") print("Exit status values:")
for (k, v) in status.items(): for (k, v) in status.items():

View File

@ -10,7 +10,7 @@ from shutil import rmtree
sys.path.insert(0, getcwd()) sys.path.insert(0, getcwd())
from qutebrowser.app import QuteBrowser from qutebrowser.app import QuteBrowser # pylint: disable=unused-import
tempdir = mkdtemp() tempdir = mkdtemp()

View File

@ -16,7 +16,7 @@
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Data used by setup.py and scripts/freeze.py""" """Data used by setup.py and scripts/freeze.py."""
import sys import sys
import os import os
@ -34,6 +34,7 @@ except NameError:
def read_file(name): def read_file(name):
"""Get the string contained in the file named name."""
with open(name, encoding='utf-8') as f: with open(name, encoding='utf-8') as f:
return f.read() return f.read()
@ -58,6 +59,7 @@ def _git_str():
def write_git_file(): def write_git_file():
"""Write the git-commit-id file with the current commit."""
gitstr = _git_str() gitstr = _git_str()
if gitstr is None: if gitstr is None:
gitstr = '' gitstr = ''