mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-03 19:33:07 +03:00
Merge pull request #7421 from hugovk/update-pre-commit
Add checks to pre-commit
This commit is contained in:
commit
26fc975a65
|
@ -1,6 +1,12 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
rev: 23.7.0
|
rev: v3.13.0
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args: [--py38-plus]
|
||||||
|
|
||||||
|
- repo: https://github.com/psf/black-pre-commit-mirror
|
||||||
|
rev: 23.9.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
args: [--target-version=py38]
|
args: [--target-version=py38]
|
||||||
|
@ -33,7 +39,7 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat]
|
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat, flake8-logging]
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/pygrep-hooks
|
- repo: https://github.com/pre-commit/pygrep-hooks
|
||||||
rev: v1.10.0
|
rev: v1.10.0
|
||||||
|
@ -44,10 +50,15 @@ repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.4.0
|
rev: v4.4.0
|
||||||
hooks:
|
hooks:
|
||||||
|
- id: check-executables-have-shebangs
|
||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
- id: check-json
|
- id: check-json
|
||||||
- id: check-toml
|
- id: check-toml
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
exclude: ^Tests/images/
|
||||||
|
- id: trailing-whitespace
|
||||||
|
exclude: ^.github/.*TEMPLATE|^Tests/(fonts|images)/
|
||||||
|
|
||||||
- repo: https://github.com/sphinx-contrib/sphinx-lint
|
- repo: https://github.com/sphinx-contrib/sphinx-lint
|
||||||
rev: v0.6.8
|
rev: v0.6.8
|
||||||
|
|
0
Tests/check_j2k_leaks.py
Executable file → Normal file
0
Tests/check_j2k_leaks.py
Executable file → Normal file
|
@ -91,7 +91,7 @@ def assert_image_equal(a, b, msg=None):
|
||||||
if HAS_UPLOADER:
|
if HAS_UPLOADER:
|
||||||
try:
|
try:
|
||||||
url = test_image_results.upload(a, b)
|
url = test_image_results.upload(a, b)
|
||||||
logger.error(f"Url for test images: {url}")
|
logger.error("URL for test images: %s", url)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ def assert_image_similar(a, b, epsilon, msg=None):
|
||||||
if HAS_UPLOADER:
|
if HAS_UPLOADER:
|
||||||
try:
|
try:
|
||||||
url = test_image_results.upload(a, b)
|
url = test_image_results.upload(a, b)
|
||||||
logger.error(f"Url for test images: {url}")
|
logger.exception("URL for test images: %s", url)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
raise e
|
raise e
|
||||||
|
|
|
@ -22,4 +22,3 @@ and that the name of ICC shall not be used in advertising or publicity
|
||||||
pertaining to distribution of the software without specific, written
|
pertaining to distribution of the software without specific, written
|
||||||
prior permission. ICC makes no representations about the suitability
|
prior permission. ICC makes no representations about the suitability
|
||||||
of this software for any purpose.
|
of this software for any purpose.
|
||||||
|
|
||||||
|
|
0
Tests/images/negative_size.ppm
Executable file → Normal file
0
Tests/images/negative_size.ppm
Executable file → Normal file
0
_custom_build/backend.py
Executable file → Normal file
0
_custom_build/backend.py
Executable file → Normal file
|
@ -11,4 +11,3 @@ pushd $archive
|
||||||
meson build --prefix=/usr && sudo ninja -C build install
|
meson build --prefix=/usr && sudo ninja -C build install
|
||||||
|
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
|
|
@ -15,4 +15,3 @@ make && sudo make install
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,3 @@
|
||||||
|
|
||||||
pkg install -y python ndk-sysroot clang make \
|
pkg install -y python ndk-sysroot clang make \
|
||||||
libjpeg-turbo
|
libjpeg-turbo
|
||||||
|
|
||||||
|
|
|
@ -49,4 +49,3 @@ The external dependencies on libjpeg and zlib are now required by default.
|
||||||
If the headers or libraries are not found, then installation will abort
|
If the headers or libraries are not found, then installation will abort
|
||||||
with an error. This behaviour can be disabled with the ``--disable-libjpeg``
|
with an error. This behaviour can be disabled with the ``--disable-libjpeg``
|
||||||
and ``--disable-zlib`` flags.
|
and ``--disable-zlib`` flags.
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,3 @@ image size can lead to a smaller allocation than expected, leading to
|
||||||
arbitrary writes.
|
arbitrary writes.
|
||||||
|
|
||||||
This issue was found by Cris Neckar at Divergent Security.
|
This issue was found by Cris Neckar at Divergent Security.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,5 +20,3 @@ CPython 3.6.1 to not work on installations of C-Python 3.6.0. This fix
|
||||||
undefines PySlice_GetIndicesEx if it exists to restore compatibility
|
undefines PySlice_GetIndicesEx if it exists to restore compatibility
|
||||||
with both 3.6.0 and 3.6.1. See https://bugs.python.org/issue29943 for
|
with both 3.6.0 and 3.6.1. See https://bugs.python.org/issue29943 for
|
||||||
more details.
|
more details.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,4 +8,3 @@ Fixed Windows PyPy Build
|
||||||
|
|
||||||
A change in the 4.2.0 cycle broke the Windows PyPy build. This has
|
A change in the 4.2.0 cycle broke the Windows PyPy build. This has
|
||||||
been fixed, and PyPy is now part of the Windows CI matrix.
|
been fixed, and PyPy is now part of the Windows CI matrix.
|
||||||
|
|
||||||
|
|
|
@ -175,6 +175,3 @@ Dark theme for docs
|
||||||
^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
The https://pillow.readthedocs.io documentation will use a dark theme if the user has requested the system use one. Uses the ``prefers-color-scheme`` CSS media query.
|
The https://pillow.readthedocs.io documentation will use a dark theme if the user has requested the system use one. Uses the ``prefers-color-scheme`` CSS media query.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -68,11 +68,11 @@ def bdf_char(f):
|
||||||
# followed by the width in x (BBw), height in y (BBh),
|
# followed by the width in x (BBw), height in y (BBh),
|
||||||
# and x and y displacement (BBxoff0, BByoff0)
|
# and x and y displacement (BBxoff0, BByoff0)
|
||||||
# of the lower left corner from the origin of the character.
|
# of the lower left corner from the origin of the character.
|
||||||
width, height, x_disp, y_disp = [int(p) for p in props["BBX"].split()]
|
width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())
|
||||||
|
|
||||||
# The word DWIDTH
|
# The word DWIDTH
|
||||||
# followed by the width in x and y of the character in device pixels.
|
# followed by the width in x and y of the character in device pixels.
|
||||||
dwx, dwy = [int(p) for p in props["DWIDTH"].split()]
|
dwx, dwy = (int(p) for p in props["DWIDTH"].split())
|
||||||
|
|
||||||
bbox = (
|
bbox = (
|
||||||
(dwx, dwy),
|
(dwx, dwy),
|
||||||
|
|
|
@ -339,9 +339,9 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
# data start identifier (the image data follows after a single line
|
# data start identifier (the image data follows after a single line
|
||||||
# consisting only of this quoted value)
|
# consisting only of this quoted value)
|
||||||
image_data_values = byte_arr[11:bytes_read].split(None, 7)
|
image_data_values = byte_arr[11:bytes_read].split(None, 7)
|
||||||
columns, rows, bit_depth, mode_id = [
|
columns, rows, bit_depth, mode_id = (
|
||||||
int(value) for value in image_data_values[:4]
|
int(value) for value in image_data_values[:4]
|
||||||
]
|
)
|
||||||
|
|
||||||
if bit_depth == 1:
|
if bit_depth == 1:
|
||||||
self._mode = "1"
|
self._mode = "1"
|
||||||
|
|
|
@ -166,7 +166,7 @@ def grabclipboard():
|
||||||
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
|
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
|
||||||
raise NotImplementedError(msg)
|
raise NotImplementedError(msg)
|
||||||
|
|
||||||
p = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p = subprocess.run(args, capture_output=True)
|
||||||
err = p.stderr
|
err = p.stderr
|
||||||
if err:
|
if err:
|
||||||
msg = f"{args[0]} error: {err.strip().decode()}"
|
msg = f"{args[0]} error: {err.strip().decode()}"
|
||||||
|
|
|
@ -823,7 +823,7 @@ class ImageFileDirectory_v2(MutableMapping):
|
||||||
try:
|
try:
|
||||||
unit_size, handler = self._load_dispatch[typ]
|
unit_size, handler = self._load_dispatch[typ]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.debug(msg + f" - unsupported type {typ}")
|
logger.debug("%s - unsupported type %s", msg, typ)
|
||||||
continue # ignore unsupported type
|
continue # ignore unsupported type
|
||||||
size = count * unit_size
|
size = count * unit_size
|
||||||
if size > (8 if self._bigtiff else 4):
|
if size > (8 if self._bigtiff else 4):
|
||||||
|
@ -880,7 +880,7 @@ class ImageFileDirectory_v2(MutableMapping):
|
||||||
if tag == STRIPOFFSETS:
|
if tag == STRIPOFFSETS:
|
||||||
stripoffsets = len(entries)
|
stripoffsets = len(entries)
|
||||||
typ = self.tagtype.get(tag)
|
typ = self.tagtype.get(tag)
|
||||||
logger.debug(f"Tag {tag}, Type: {typ}, Value: {repr(value)}")
|
logger.debug("Tag %s, Type: %s, Value: %s", tag, typ, repr(value))
|
||||||
is_ifd = typ == TiffTags.LONG and isinstance(value, dict)
|
is_ifd = typ == TiffTags.LONG and isinstance(value, dict)
|
||||||
if is_ifd:
|
if is_ifd:
|
||||||
if self._endian == "<":
|
if self._endian == "<":
|
||||||
|
@ -929,7 +929,7 @@ class ImageFileDirectory_v2(MutableMapping):
|
||||||
|
|
||||||
# pass 2: write entries to file
|
# pass 2: write entries to file
|
||||||
for tag, typ, count, value, data in entries:
|
for tag, typ, count, value, data in entries:
|
||||||
logger.debug(f"{tag} {typ} {count} {repr(value)} {repr(data)}")
|
logger.debug("%s %s %s %s %s", tag, typ, count, repr(value), repr(data))
|
||||||
result += self._pack("HHL4s", tag, typ, count, value)
|
result += self._pack("HHL4s", tag, typ, count, value)
|
||||||
|
|
||||||
# -- overwrite here for multi-page --
|
# -- overwrite here for multi-page --
|
||||||
|
@ -1098,8 +1098,8 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self._n_frames = None
|
self._n_frames = None
|
||||||
|
|
||||||
logger.debug("*** TiffImageFile._open ***")
|
logger.debug("*** TiffImageFile._open ***")
|
||||||
logger.debug(f"- __first: {self.__first}")
|
logger.debug("- __first: %s", self.__first)
|
||||||
logger.debug(f"- ifh: {repr(ifh)}") # Use repr to avoid str(bytes)
|
logger.debug("- ifh: %s", repr(ifh)) # Use repr to avoid str(bytes)
|
||||||
|
|
||||||
# and load the first frame
|
# and load the first frame
|
||||||
self._seek(0)
|
self._seek(0)
|
||||||
|
@ -1137,12 +1137,15 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
msg = "no more images in TIFF file"
|
msg = "no more images in TIFF file"
|
||||||
raise EOFError(msg)
|
raise EOFError(msg)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Seeking to frame {frame}, on frame {self.__frame}, "
|
"Seeking to frame %s, on frame %s, __next %s, location: %s",
|
||||||
f"__next {self.__next}, location: {self.fp.tell()}"
|
frame,
|
||||||
|
self.__frame,
|
||||||
|
self.__next,
|
||||||
|
self.fp.tell(),
|
||||||
)
|
)
|
||||||
self.fp.seek(self.__next)
|
self.fp.seek(self.__next)
|
||||||
self._frame_pos.append(self.__next)
|
self._frame_pos.append(self.__next)
|
||||||
logger.debug("Loading tags, location: %s" % self.fp.tell())
|
logger.debug("Loading tags, location: %s", self.fp.tell())
|
||||||
self.tag_v2.load(self.fp)
|
self.tag_v2.load(self.fp)
|
||||||
if self.tag_v2.next in self._frame_pos:
|
if self.tag_v2.next in self._frame_pos:
|
||||||
# This IFD has already been processed
|
# This IFD has already been processed
|
||||||
|
@ -1330,18 +1333,18 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
fillorder = self.tag_v2.get(FILLORDER, 1)
|
fillorder = self.tag_v2.get(FILLORDER, 1)
|
||||||
|
|
||||||
logger.debug("*** Summary ***")
|
logger.debug("*** Summary ***")
|
||||||
logger.debug(f"- compression: {self._compression}")
|
logger.debug("- compression: %s", self._compression)
|
||||||
logger.debug(f"- photometric_interpretation: {photo}")
|
logger.debug("- photometric_interpretation: %s", photo)
|
||||||
logger.debug(f"- planar_configuration: {self._planar_configuration}")
|
logger.debug("- planar_configuration: %s", self._planar_configuration)
|
||||||
logger.debug(f"- fill_order: {fillorder}")
|
logger.debug("- fill_order: %s", fillorder)
|
||||||
logger.debug(f"- YCbCr subsampling: {self.tag.get(YCBCRSUBSAMPLING)}")
|
logger.debug("- YCbCr subsampling: %s", self.tag.get(YCBCRSUBSAMPLING))
|
||||||
|
|
||||||
# size
|
# size
|
||||||
xsize = int(self.tag_v2.get(IMAGEWIDTH))
|
xsize = int(self.tag_v2.get(IMAGEWIDTH))
|
||||||
ysize = int(self.tag_v2.get(IMAGELENGTH))
|
ysize = int(self.tag_v2.get(IMAGELENGTH))
|
||||||
self._size = xsize, ysize
|
self._size = xsize, ysize
|
||||||
|
|
||||||
logger.debug(f"- size: {self.size}")
|
logger.debug("- size: %s", self.size)
|
||||||
|
|
||||||
sample_format = self.tag_v2.get(SAMPLEFORMAT, (1,))
|
sample_format = self.tag_v2.get(SAMPLEFORMAT, (1,))
|
||||||
if len(sample_format) > 1 and max(sample_format) == min(sample_format) == 1:
|
if len(sample_format) > 1 and max(sample_format) == min(sample_format) == 1:
|
||||||
|
@ -1397,7 +1400,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
bps_tuple,
|
bps_tuple,
|
||||||
extra_tuple,
|
extra_tuple,
|
||||||
)
|
)
|
||||||
logger.debug(f"format key: {key}")
|
logger.debug("format key: %s", key)
|
||||||
try:
|
try:
|
||||||
self._mode, rawmode = OPEN_INFO[key]
|
self._mode, rawmode = OPEN_INFO[key]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
|
@ -1405,8 +1408,8 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
msg = "unknown pixel mode"
|
msg = "unknown pixel mode"
|
||||||
raise SyntaxError(msg) from e
|
raise SyntaxError(msg) from e
|
||||||
|
|
||||||
logger.debug(f"- raw mode: {rawmode}")
|
logger.debug("- raw mode: %s", rawmode)
|
||||||
logger.debug(f"- pil mode: {self.mode}")
|
logger.debug("- pil mode: %s", self.mode)
|
||||||
|
|
||||||
self.info["compression"] = self._compression
|
self.info["compression"] = self._compression
|
||||||
|
|
||||||
|
@ -1447,7 +1450,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
if fillorder == 2:
|
if fillorder == 2:
|
||||||
# Replace fillorder with fillorder=1
|
# Replace fillorder with fillorder=1
|
||||||
key = key[:3] + (1,) + key[4:]
|
key = key[:3] + (1,) + key[4:]
|
||||||
logger.debug(f"format key: {key}")
|
logger.debug("format key: %s", key)
|
||||||
# this should always work, since all the
|
# this should always work, since all the
|
||||||
# fillorder==2 modes have a corresponding
|
# fillorder==2 modes have a corresponding
|
||||||
# fillorder=1 mode
|
# fillorder=1 mode
|
||||||
|
@ -1610,7 +1613,7 @@ def _save(im, fp, filename):
|
||||||
info = exif
|
info = exif
|
||||||
else:
|
else:
|
||||||
info = {}
|
info = {}
|
||||||
logger.debug("Tiffinfo Keys: %s" % list(info))
|
logger.debug("Tiffinfo Keys: %s", list(info))
|
||||||
if isinstance(info, ImageFileDirectory_v1):
|
if isinstance(info, ImageFileDirectory_v1):
|
||||||
info = info.to_v2()
|
info = info.to_v2()
|
||||||
for key in info:
|
for key in info:
|
||||||
|
@ -1743,7 +1746,7 @@ def _save(im, fp, filename):
|
||||||
ifd[JPEGQUALITY] = quality
|
ifd[JPEGQUALITY] = quality
|
||||||
|
|
||||||
logger.debug("Saving using libtiff encoder")
|
logger.debug("Saving using libtiff encoder")
|
||||||
logger.debug("Items: %s" % sorted(ifd.items()))
|
logger.debug("Items: %s", sorted(ifd.items()))
|
||||||
_fp = 0
|
_fp = 0
|
||||||
if hasattr(fp, "fileno"):
|
if hasattr(fp, "fileno"):
|
||||||
try:
|
try:
|
||||||
|
@ -1811,7 +1814,7 @@ def _save(im, fp, filename):
|
||||||
if SAMPLEFORMAT in atts and len(atts[SAMPLEFORMAT]) == 1:
|
if SAMPLEFORMAT in atts and len(atts[SAMPLEFORMAT]) == 1:
|
||||||
atts[SAMPLEFORMAT] = atts[SAMPLEFORMAT][0]
|
atts[SAMPLEFORMAT] = atts[SAMPLEFORMAT][0]
|
||||||
|
|
||||||
logger.debug("Converted items: %s" % sorted(atts.items()))
|
logger.debug("Converted items: %s", sorted(atts.items()))
|
||||||
|
|
||||||
# libtiff always expects the bytes in native order.
|
# libtiff always expects the bytes in native order.
|
||||||
# we're storing image byte order. So, if the rawmode
|
# we're storing image byte order. So, if the rawmode
|
||||||
|
|
Loading…
Reference in New Issue
Block a user