From 911f9227a0f485c2e862fd8a6cc2a765c5363016 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 17 Mar 2024 14:40:18 +0100 Subject: [PATCH] Fix flake8 warnings --- examples/stream.py | 6 ++---- examples/texput.log | 21 ------------------- pyvips/__init__.py | 47 ++++++++++++++++++++++-------------------- pyvips/base.py | 8 +++---- pyvips/pyvips_build.py | 11 +++++----- 5 files changed, 37 insertions(+), 56 deletions(-) delete mode 100644 examples/texput.log diff --git a/examples/stream.py b/examples/stream.py index bbda64e..2142a91 100755 --- a/examples/stream.py +++ b/examples/stream.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import sys -import gc import requests import pyvips @@ -20,8 +19,7 @@ source.on_read((lambda stream: stream.read)(stream)) tile = pyvips.Image.new_from_source(source, "", access="sequential") - image = image.composite2(tile, "over", x= 50 * (i + 1), y= 50 * (i + 1)) + image = image.composite2(tile, "over", x=50 * (i + 1), y=50 * (i + 1)) -print(f"writing output.jpg ...") +print("writing output.jpg ...") image.write_to_file("output.jpg") - diff --git a/examples/texput.log b/examples/texput.log deleted file mode 100644 index f2c4158..0000000 --- a/examples/texput.log +++ /dev/null @@ -1,21 +0,0 @@ -This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Debian) (preloaded format=pdflatex 2022.11.21) 4 DEC 2022 14:33 -entering extended mode - restricted \write18 enabled. - %&-line parsing enabled. -** - -! Emergency stop. -<*> - -End of file on the terminal! - - -Here is how much of TeX's memory you used: - 3 strings out of 479907 - 121 string characters out of 5886407 - 293384 words of memory out of 5000000 - 18315 multiletter control sequences out of 15000+600000 - 469259 words of font info for 28 fonts, out of 8000000 for 9000 - 59 hyphenation exceptions out of 8191 - 0i,0n,0p,1b,6s stack positions out of 10000i,1000n,20000p,200000b,200000s -! ==> Fatal error occurred, no output PDF file produced! diff --git a/pyvips/__init__.py b/pyvips/__init__.py index cfce9f7..6d783d1 100644 --- a/pyvips/__init__.py +++ b/pyvips/__init__.py @@ -26,15 +26,15 @@ gobject_lib = _libvips.lib # now check that the binary wrapper is for the same version of libvips that - # we find ourseleves linking to at runtime ... if it isn't, we must fall + # we find ourseleves linking to at runtime ... if it isn't, we must fall # back to ABI mode lib_major = vips_lib.vips_version(0) lib_minor = vips_lib.vips_version(1) wrap_major = vips_lib.VIPS_MAJOR_VERSION wrap_minor = vips_lib.VIPS_MINOR_VERSION - logger.debug('Module generated for libvips %s.%s' % - (wrap_major, wrap_minor)) - logger.debug('Linked to libvips %s.%s' % (lib_major, lib_minor)) + logger.debug('Module generated for libvips %s.%s' % + (wrap_major, wrap_minor)) + logger.debug('Linked to libvips %s.%s' % (lib_major, lib_minor)) if wrap_major != lib_major or wrap_minor != lib_minor: raise Exception('bad wrapper version') @@ -109,16 +109,17 @@ ffi.cdef(cdefs(features)) + from .error import * # redirect all vips warnings to logging class GLogLevelFlags(object): - # log flags + # log flags FLAG_RECURSION = 1 << 0 FLAG_FATAL = 1 << 1 - # GLib log levels + # GLib log levels LEVEL_ERROR = 1 << 2 # always fatal LEVEL_CRITICAL = 1 << 3 LEVEL_WARNING = 1 << 4 @@ -127,14 +128,15 @@ class GLogLevelFlags(object): LEVEL_DEBUG = 1 << 7 LEVEL_TO_LOGGER = { - LEVEL_DEBUG : 10, - LEVEL_INFO : 20, - LEVEL_MESSAGE : 20, - LEVEL_WARNING : 30, - LEVEL_ERROR : 40, - LEVEL_CRITICAL : 50, + LEVEL_DEBUG: 10, + LEVEL_INFO: 20, + LEVEL_MESSAGE: 20, + LEVEL_WARNING: 30, + LEVEL_ERROR: 40, + LEVEL_CRITICAL: 50, } + if API_mode: @ffi.def_extern() def _log_handler_callback(domain, level, message, user_data): @@ -151,16 +153,16 @@ def _log_handler_callback(domain, level, message, user_data): # keep a ref to the cb to stop it being GCd _log_handler_cb = ffi.callback('GLogFunc', _log_handler_callback) -_log_handler_id = glib_lib.g_log_set_handler(_to_bytes('VIPS'), - GLogLevelFlags.LEVEL_DEBUG | - GLogLevelFlags.LEVEL_INFO | - GLogLevelFlags.LEVEL_MESSAGE | - GLogLevelFlags.LEVEL_WARNING | - GLogLevelFlags.LEVEL_CRITICAL | - GLogLevelFlags.LEVEL_ERROR | - GLogLevelFlags.FLAG_FATAL | - GLogLevelFlags.FLAG_RECURSION, - _log_handler_cb, ffi.NULL) +_log_handler_id = glib_lib.g_log_set_handler(_to_bytes('VIPS'), + GLogLevelFlags.LEVEL_DEBUG | + GLogLevelFlags.LEVEL_INFO | + GLogLevelFlags.LEVEL_MESSAGE | + GLogLevelFlags.LEVEL_WARNING | + GLogLevelFlags.LEVEL_CRITICAL | + GLogLevelFlags.LEVEL_ERROR | + GLogLevelFlags.FLAG_FATAL | + GLogLevelFlags.FLAG_RECURSION, + _log_handler_cb, ffi.NULL) # ffi doesn't like us looking up methods during shutdown: make a note of the # remove handler here @@ -176,6 +178,7 @@ def _remove_log_handler(): _remove_handler(_to_bytes('VIPS'), _log_handler_id) _log_handler_id = None + atexit.register(_remove_log_handler) from .enums import * diff --git a/pyvips/base.py b/pyvips/base.py index b80bdaa..be76153 100644 --- a/pyvips/base.py +++ b/pyvips/base.py @@ -134,8 +134,8 @@ def enum_dict(gtype): g_enum_class = ffi.cast('GEnumClass *', g_type_class) # -1 since we always have a "last" member. - return {_to_string(g_enum_class.values[i].value_nick): - g_enum_class.values[i].value + return {_to_string(g_enum_class.values[i].value_nick): + g_enum_class.values[i].value for i in range(g_enum_class.n_values - 1)} @@ -145,8 +145,8 @@ def flags_dict(gtype): g_type_class = gobject_lib.g_type_class_ref(gtype) g_flags_class = ffi.cast('GFlagsClass *', g_type_class) - return {_to_string(g_flags_class.values[i].value_nick): - g_flags_class.values[i].value + return {_to_string(g_flags_class.values[i].value_nick): + g_flags_class.values[i].value for i in range(g_flags_class.n_values)} diff --git a/pyvips/pyvips_build.py b/pyvips/pyvips_build.py index 267d383..e03fee1 100644 --- a/pyvips/pyvips_build.py +++ b/pyvips/pyvips_build.py @@ -4,7 +4,7 @@ from cffi import FFI # we must have the vips package to be able to do anything -if not pkgconfig.exists('vips'): +if not pkgconfig.exists('vips'): raise Exception('unable to find pkg-config package "vips"') if pkgconfig.installed('vips', '< 8.2'): raise Exception('pkg-config "vips" is too old -- need libvips 8.2 or later') @@ -14,7 +14,7 @@ ffibuilder.set_source("_libvips", r""" #include - """, + """, **pkgconfig.parse('vips')) major, minor, micro = [int(s) for s in pkgconfig.modversion('vips').split('.')] @@ -26,12 +26,13 @@ 'api': True, } + import vdecls # handy for debugging -#with open('vips-source.txt','w') as f: -# c = vdecls.cdefs(features) -# f.write(c) +# with open('vips-source.txt','w') as f: +# c = vdecls.cdefs(features) +# f.write(c) ffibuilder.cdef(vdecls.cdefs(features))