Merge pull request #3467 from hugovk/lint-can-fail

CI: Allow lint job to fail
This commit is contained in:
Hugo 2018-12-13 21:09:58 +02:00 committed by GitHub
commit 3ed5dcc928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 56 additions and 51 deletions

View File

@ -82,7 +82,9 @@ before_script:
script: script:
- | - |
if [ "$DOCKER" == "" ] && [ "$LINT" == "" ]; then if [ "$LINT" == "true" ]; then
flake8 --statistics --count
elif [ "$DOCKER" == "" ]; then
.travis/script.sh .travis/script.sh
elif [ "$DOCKER" ]; then elif [ "$DOCKER" ]; then
# the Pillow user in the docker container is UID 1000 # the Pillow user in the docker container is UID 1000
@ -92,8 +94,6 @@ script:
after_success: after_success:
- | - |
if [ "$LINT" == "true" ]; then if [ "$LINT" == "" ]; then
flake8 --statistics --count
else
.travis/after_success.sh .travis/after_success.sh
fi fi

View File

@ -2,7 +2,6 @@
from __future__ import print_function from __future__ import print_function
import base64 import base64
import os import os
import sys
if __name__ == "__main__": if __name__ == "__main__":
# create font data chunk for embedding # create font data chunk for embedding

View File

@ -84,7 +84,7 @@ class PillowTestCase(unittest.TestCase):
self.assertTrue( self.assertTrue(
all(x == y for x, y in zip(a, b)), all(x == y for x, y in zip(a, b)),
msg or "got %s, expected %s" % (a, b)) msg or "got %s, expected %s" % (a, b))
except: except Exception:
self.assertEqual(a, b, msg) self.assertEqual(a, b, msg)
def assert_image(self, im, mode, size, msg=None): def assert_image(self, im, mode, size, msg=None):
@ -149,7 +149,7 @@ class PillowTestCase(unittest.TestCase):
try: try:
url = test_image_results.upload(a, b) url = test_image_results.upload(a, b)
logger.error("Url for test images: %s" % url) logger.error("Url for test images: %s" % url)
except: except Exception:
pass pass
raise e raise e

View File

@ -18,7 +18,7 @@ A = Image.new("L", (1, 1), 1)
B = Image.new("L", (1, 1), 2) B = Image.new("L", (1, 1), 2)
Z = Image.new("L", (1, 1), 0) # Z for zero Z = Image.new("L", (1, 1), 0) # Z for zero
F = Image.new("F", (1, 1), 3) F = Image.new("F", (1, 1), 3)
I = Image.new("I", (1, 1), 4) I = Image.new("I", (1, 1), 4) # noqa: E741
A2 = A.resize((2, 2)) A2 = A.resize((2, 2))
B2 = B.resize((2, 2)) B2 = B.resize((2, 2))

View File

@ -43,7 +43,7 @@ def _mp_compile(self, sources, output_dir=None, macros=None,
pool = Pool(MAX_PROCS) pool = Pool(MAX_PROCS)
try: try:
print("Building using %d processes" % pool._processes) print("Building using %d processes" % pool._processes)
except: except Exception:
pass pass
arr = [(self, obj, build, cc_args, extra_postargs, pp_opts) arr = [(self, obj, build, cc_args, extra_postargs, pp_opts)
for obj in objects] for obj in objects]

View File

@ -1,6 +1,11 @@
[aliases] [aliases]
test=pytest test=pytest
[metadata] [metadata]
license_file = LICENSE license_file = LICENSE
[tool:pytest] [tool:pytest]
addopts = -vx Tests addopts = -vx Tests
[flake8]
max-line-length = 88

View File

@ -975,7 +975,7 @@ class Image(object):
if isinstance(t, tuple): if isinstance(t, tuple):
try: try:
t = trns_im.palette.getcolor(t) t = trns_im.palette.getcolor(t)
except: except Exception:
raise ValueError("Couldn't allocate a palette " raise ValueError("Couldn't allocate a palette "
"color for transparency") "color for transparency")
trns_im.putpixel((0, 0), t) trns_im.putpixel((0, 0), t)
@ -1012,7 +1012,7 @@ class Image(object):
if trns is not None: if trns is not None:
try: try:
new.info['transparency'] = new.palette.getcolor(trns) new.info['transparency'] = new.palette.getcolor(trns)
except: except Exception:
# if we can't make a transparent color, don't leave the old # if we can't make a transparent color, don't leave the old
# transparency hanging around to mess us up. # transparency hanging around to mess us up.
del(new.info['transparency']) del(new.info['transparency'])
@ -1042,7 +1042,7 @@ class Image(object):
if new_im.mode == 'P': if new_im.mode == 'P':
try: try:
new_im.info['transparency'] = new_im.palette.getcolor(trns) new_im.info['transparency'] = new_im.palette.getcolor(trns)
except: except Exception:
del(new_im.info['transparency']) del(new_im.info['transparency'])
warnings.warn("Couldn't allocate palette entry " + warnings.warn("Couldn't allocate palette entry " +
"for transparency") "for transparency")

View File

@ -197,7 +197,7 @@ class UnsharpMask(MultibandFilter):
.. _digital unsharp masking: https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking .. _digital unsharp masking: https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking
""" """ # noqa: E501
name = "UnsharpMask" name = "UnsharpMask"
def __init__(self, radius=2, percent=150, threshold=3): def __init__(self, radius=2, percent=150, threshold=3):

View File

@ -72,7 +72,7 @@ class ImageFont(object):
try: try:
fullname = os.path.splitext(filename)[0] + ext fullname = os.path.splitext(filename)[0] + ext
image = Image.open(fullname) image = Image.open(fullname)
except: except Exception:
pass pass
else: else:
if image and image.mode in ("1", "L"): if image and image.mode in ("1", "L"):

View File

@ -140,7 +140,7 @@ def _toqclass_helper(im):
if py3: if py3:
im = str(im.toUtf8(), "utf-8") im = str(im.toUtf8(), "utf-8")
else: else:
im = unicode(im.toUtf8(), "utf-8") im = unicode(im.toUtf8(), "utf-8") # noqa: F821
if isPath(im): if isPath(im):
im = Image.open(im) im = Image.open(im)

View File

@ -124,7 +124,7 @@ class PhotoImage(object):
self.__photo.name = None self.__photo.name = None
try: try:
self.__photo.tk.call("image", "delete", name) self.__photo.tk.call("image", "delete", name)
except: except Exception:
pass # ignore internal errors pass # ignore internal errors
def __str__(self): def __str__(self):
@ -244,7 +244,7 @@ class BitmapImage(object):
self.__photo.name = None self.__photo.name = None
try: try:
self.__photo.tk.call("image", "delete", name) self.__photo.tk.call("image", "delete", name)
except: except Exception:
pass # ignore internal errors pass # ignore internal errors
def width(self): def width(self):

View File

@ -181,14 +181,14 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
try: try:
fd = self.fp.fileno() fd = self.fp.fileno()
length = os.fstat(fd).st_size length = os.fstat(fd).st_size
except: except Exception:
fd = -1 fd = -1
try: try:
pos = self.fp.tell() pos = self.fp.tell()
self.fp.seek(0, 2) self.fp.seek(0, 2)
length = self.fp.tell() length = self.fp.tell()
self.fp.seek(pos, 0) self.fp.seek(pos, 0)
except: except Exception:
length = -1 length = -1
self.tile = [('jpeg2k', (0, 0) + self.size, 0, self.tile = [('jpeg2k', (0, 0) + self.size, 0,
@ -250,7 +250,7 @@ def _save(im, fp, filename):
if hasattr(fp, "fileno"): if hasattr(fp, "fileno"):
try: try:
fd = fp.fileno() fd = fp.fileno()
except: except Exception:
fd = -1 fd = -1
im.encoderconfig = ( im.encoderconfig = (

View File

@ -75,7 +75,7 @@ def APP(self, marker):
try: try:
jfif_unit = i8(s[7]) jfif_unit = i8(s[7])
jfif_density = i16(s, 8), i16(s, 10) jfif_density = i16(s, 8), i16(s, 10)
except: except Exception:
pass pass
else: else:
if jfif_unit == 1: if jfif_unit == 1:
@ -107,7 +107,7 @@ def APP(self, marker):
# extract Adobe custom properties # extract Adobe custom properties
try: try:
adobe_transform = i8(s[1]) adobe_transform = i8(s[1])
except: except Exception:
pass pass
else: else:
self.info["adobe_transform"] = adobe_transform self.info["adobe_transform"] = adobe_transform
@ -441,7 +441,7 @@ def _fixup_dict(src_dict):
try: try:
if len(value) == 1 and not isinstance(value, dict): if len(value) == 1 and not isinstance(value, dict):
return value[0] return value[0]
except: except Exception:
pass pass
return value return value
@ -512,7 +512,7 @@ def _getmp(self):
info = TiffImagePlugin.ImageFileDirectory_v2(head) info = TiffImagePlugin.ImageFileDirectory_v2(head)
info.load(file_contents) info.load(file_contents)
mp = dict(info) mp = dict(info)
except: except Exception:
raise SyntaxError("malformed MP Index (unreadable directory)") raise SyntaxError("malformed MP Index (unreadable directory)")
# it's an error not to have a number of images # it's an error not to have a number of images
try: try:

View File

@ -373,7 +373,7 @@ def pdf_repr(x):
elif isinstance(x, list): elif isinstance(x, list):
return bytes(PdfArray(x)) return bytes(PdfArray(x))
elif ((py3 and isinstance(x, str)) or elif ((py3 and isinstance(x, str)) or
(not py3 and isinstance(x, unicode))): (not py3 and isinstance(x, unicode))): # noqa: F821
return pdf_repr(encode_text(x)) return pdf_repr(encode_text(x))
elif isinstance(x, bytes): elif isinstance(x, bytes):
# XXX escape more chars? handle binary garbage # XXX escape more chars? handle binary garbage

View File

@ -340,7 +340,7 @@ class PngStream(ChunkStream):
self.im_size = i32(s), i32(s[4:]) self.im_size = i32(s), i32(s[4:])
try: try:
self.im_mode, self.im_rawmode = _MODES[(i8(s[8]), i8(s[9]))] self.im_mode, self.im_rawmode = _MODES[(i8(s[8]), i8(s[9]))]
except: except Exception:
pass pass
if i8(s[12]): if i8(s[12]):
self.im_info["interlace"] = 1 self.im_info["interlace"] = 1

View File

@ -214,7 +214,7 @@ class _PyAccessI16_L(PyAccess):
except TypeError: except TypeError:
color = min(color[0], 65535) color = min(color[0], 65535)
pixel.l = color & 0xFF pixel.l = color & 0xFF # noqa: E741
pixel.r = color >> 8 pixel.r = color >> 8
@ -231,10 +231,10 @@ class _PyAccessI16_B(PyAccess):
pixel = self.pixels[y][x] pixel = self.pixels[y][x]
try: try:
color = min(color, 65535) color = min(color, 65535)
except: except Exception:
color = min(color[0], 65535) color = min(color[0], 65535)
pixel.l = color >> 8 pixel.l = color >> 8 # noqa: E741
pixel.r = color & 0xFF pixel.r = color & 0xFF

View File

@ -218,7 +218,7 @@ def loadImageSeries(filelist=None):
continue continue
try: try:
im = Image.open(img).convert2byte() im = Image.open(img).convert2byte()
except: except Exception:
if not isSpiderImage(img): if not isSpiderImage(img):
print(img + " is not a Spider image file") print(img + " is not a Spider image file")
continue continue

View File

@ -541,7 +541,7 @@ class ImageFileDirectory_v2(MutableMapping):
def _setitem(self, tag, value, legacy_api): def _setitem(self, tag, value, legacy_api):
basetypes = (Number, bytes, str) basetypes = (Number, bytes, str)
if not py3: if not py3:
basetypes += unicode, basetypes += unicode, # noqa: F821
info = TiffTags.lookup(tag) info = TiffTags.lookup(tag)
values = [value] if isinstance(value, basetypes) else value values = [value] if isinstance(value, basetypes) else value
@ -594,7 +594,8 @@ class ImageFileDirectory_v2(MutableMapping):
except ValueError: except ValueError:
# We've got a builtin tag with 1 expected entry # We've got a builtin tag with 1 expected entry
warnings.warn( warnings.warn(
"Metadata Warning, tag %s had too many entries: %s, expected 1" % ( "Metadata Warning, tag %s had too many entries: "
"%s, expected 1" % (
tag, len(values))) tag, len(values)))
dest[tag] = values[0] dest[tag] = values[0]
@ -622,13 +623,13 @@ class ImageFileDirectory_v2(MutableMapping):
from .TiffTags import TYPES from .TiffTags import TYPES
if func.__name__.startswith("load_"): if func.__name__.startswith("load_"):
TYPES[idx] = func.__name__[5:].replace("_", " ") TYPES[idx] = func.__name__[5:].replace("_", " ")
_load_dispatch[idx] = size, func _load_dispatch[idx] = size, func # noqa: F821
return func return func
return decorator return decorator
def _register_writer(idx): def _register_writer(idx):
def decorator(func): def decorator(func):
_write_dispatch[idx] = func _write_dispatch[idx] = func # noqa: F821
return func return func
return decorator return decorator
@ -637,9 +638,9 @@ class ImageFileDirectory_v2(MutableMapping):
idx, fmt, name = idx_fmt_name idx, fmt, name = idx_fmt_name
TYPES[idx] = name TYPES[idx] = name
size = struct.calcsize("=" + fmt) size = struct.calcsize("=" + fmt)
_load_dispatch[idx] = size, lambda self, data, legacy_api=True: ( _load_dispatch[idx] = size, lambda self, data, legacy_api=True: ( # noqa: F821
self._unpack("{}{}".format(len(data) // size, fmt), data)) self._unpack("{}{}".format(len(data) // size, fmt), data))
_write_dispatch[idx] = lambda self, *values: ( _write_dispatch[idx] = lambda self, *values: ( # noqa: F821
b"".join(self._pack(fmt, value) for value in values)) b"".join(self._pack(fmt, value) for value in values))
list(map(_register_basic, list(map(_register_basic,
@ -1420,7 +1421,7 @@ def _save(im, fp, filename):
ifd[key] = info.get(key) ifd[key] = info.get(key)
try: try:
ifd.tagtype[key] = info.tagtype[key] ifd.tagtype[key] = info.tagtype[key]
except: except Exception:
pass # might not be an IFD, Might not have populated type pass # might not be an IFD, Might not have populated type
# additions written by Greg Couch, gregc@cgl.ucsf.edu # additions written by Greg Couch, gregc@cgl.ucsf.edu
@ -1514,7 +1515,7 @@ def _save(im, fp, filename):
if tag not in TiffTags.LIBTIFF_CORE: if tag not in TiffTags.LIBTIFF_CORE:
continue continue
if tag not in atts and tag not in blocklist: if tag not in atts and tag not in blocklist:
if isinstance(value, str if py3 else unicode): if isinstance(value, str if py3 else unicode): # noqa: F821
atts[tag] = value.encode('ascii', 'replace') + b"\0" atts[tag] = value.encode('ascii', 'replace') + b"\0"
elif isinstance(value, IFDRational): elif isinstance(value, IFDRational):
atts[tag] = float(value) atts[tag] = float(value)

View File

@ -11,10 +11,10 @@ if py3:
return isinstance(f, (bytes, str)) return isinstance(f, (bytes, str))
else: else:
def isStringType(t): def isStringType(t):
return isinstance(t, basestring) return isinstance(t, basestring) # noqa: F821
def isPath(f): def isPath(f):
return isinstance(f, basestring) return isinstance(f, basestring) # noqa: F821
# Checks if an object is a string, and that it points to a directory. # Checks if an object is a string, and that it points to a directory.

View File

@ -112,14 +112,14 @@ call %(python_path)s\%(executable)s setup.py %(imaging_libs)s %%BLDOPT%%
endlocal endlocal
endlocal endlocal
""" """ # noqa: E501
return script % args return script % args
def clean(): def clean():
try: try:
shutil.rmtree('../build') shutil.rmtree('../build')
except: except Exception:
# could already be removed # could already be removed
pass pass
run_script(('virtualenvs', setup_vms())) run_script(('virtualenvs', setup_vms()))

View File

@ -104,7 +104,7 @@ def setup_compiler(compiler):
return r"""setlocal EnableDelayedExpansion return r"""setlocal EnableDelayedExpansion
call "%%ProgramFiles%%\Microsoft SDKs\Windows\%(env_version)s\Bin\SetEnv.Cmd" /Release %(env_flags)s call "%%ProgramFiles%%\Microsoft SDKs\Windows\%(env_version)s\Bin\SetEnv.Cmd" /Release %(env_flags)s
set INCLIB=%%INCLIB%%\%(inc_dir)s set INCLIB=%%INCLIB%%\%(inc_dir)s
""" % compiler """ % compiler # noqa: E501
def end_compiler(): def end_compiler():
@ -202,7 +202,7 @@ rd /S /Q %%FREETYPE%%\objs
xcopy /Y /E /Q %%FREETYPE%%\include %%INCLIB%% xcopy /Y /E /Q %%FREETYPE%%\include %%INCLIB%%
copy /Y /B %%FREETYPE%%\objs\vc%(vc_version)s\%(platform)s\*.lib %%INCLIB%%\freetype.lib copy /Y /B %%FREETYPE%%\objs\vc%(vc_version)s\%(platform)s\*.lib %%INCLIB%%\freetype.lib
endlocal endlocal
""" % compiler """ % compiler # noqa: E501
def msbuild_freetype_70(compiler): def msbuild_freetype_70(compiler):
@ -217,7 +217,7 @@ xcopy /Y /E /Q %%FREETYPE%%\include %%INCLIB%%
xcopy /Y /E /Q %%FREETYPE%%\objs\win32\vc%(vc_version)s %%INCLIB%% xcopy /Y /E /Q %%FREETYPE%%\objs\win32\vc%(vc_version)s %%INCLIB%%
copy /Y /B %%FREETYPE%%\objs\win32\vc%(vc_version)s\*.lib %%INCLIB%%\freetype.lib copy /Y /B %%FREETYPE%%\objs\win32\vc%(vc_version)s\*.lib %%INCLIB%%\freetype.lib
endlocal endlocal
""" % compiler """ % compiler # noqa: E501
def build_lcms2(compiler): def build_lcms2(compiler):
@ -237,12 +237,12 @@ rem Build lcms2
setlocal setlocal
rd /S /Q %%LCMS%%\Lib rd /S /Q %%LCMS%%\Lib
rd /S /Q %%LCMS%%\Projects\VC%(vc_version)s\Release rd /S /Q %%LCMS%%\Projects\VC%(vc_version)s\Release
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:Clean /p:Configuration="Release" /p:Platform=Win32 /m %%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:Clean /p:Configuration="Release" /p:Platform=Win32 /m
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:lcms2_static /p:Configuration="Release" /p:Platform=Win32 /m %%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:lcms2_static /p:Configuration="Release" /p:Platform=Win32 /m
xcopy /Y /E /Q %%LCMS%%\include %%INCLIB%% xcopy /Y /E /Q %%LCMS%%\include %%INCLIB%%
copy /Y /B %%LCMS%%\Projects\VC%(vc_version)s\Release\*.lib %%INCLIB%% copy /Y /B %%LCMS%%\Projects\VC%(vc_version)s\Release\*.lib %%INCLIB%%
endlocal endlocal
""" % compiler """ % compiler # noqa: E501
def build_lcms_71(compiler): def build_lcms_71(compiler):
@ -251,12 +251,12 @@ rem Build lcms2
setlocal setlocal
rd /S /Q %%LCMS%%\Lib rd /S /Q %%LCMS%%\Lib
rd /S /Q %%LCMS%%\Projects\VC%(vc_version)s\Release rd /S /Q %%LCMS%%\Projects\VC%(vc_version)s\Release
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:Clean /p:Configuration="Release" /p:Platform=%(platform)s /m %%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:Clean /p:Configuration="Release" /p:Platform=%(platform)s /m
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:lcms2_static /p:Configuration="Release" /p:Platform=%(platform)s /m %%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:lcms2_static /p:Configuration="Release" /p:Platform=%(platform)s /m
xcopy /Y /E /Q %%LCMS%%\include %%INCLIB%% xcopy /Y /E /Q %%LCMS%%\include %%INCLIB%%
copy /Y /B %%LCMS%%\Lib\MS\*.lib %%INCLIB%% copy /Y /B %%LCMS%%\Lib\MS\*.lib %%INCLIB%%
endlocal endlocal
""" % compiler """ % compiler # noqa: E501
def add_compiler(compiler, bit): def add_compiler(compiler, bit):

View File

@ -34,7 +34,7 @@ libs = {
'dir': 'tiff-4.0.10', 'dir': 'tiff-4.0.10',
}, },
'freetype': { 'freetype': {
'url': 'https://download.savannah.gnu.org/releases/freetype/freetype-2.9.1.tar.gz', 'url': 'https://download.savannah.gnu.org/releases/freetype/freetype-2.9.1.tar.gz', # noqa: E501
'filename': PILLOW_DEPENDS_DIR + 'freetype-2.9.1.tar.gz', 'filename': PILLOW_DEPENDS_DIR + 'freetype-2.9.1.tar.gz',
'dir': 'freetype-2.9.1', 'dir': 'freetype-2.9.1',
}, },