Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flake8 warnings #460

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

import sys
import gc
import requests
import pyvips

Expand All @@ -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")

21 changes: 0 additions & 21 deletions examples/texput.log

This file was deleted.

47 changes: 25 additions & 22 deletions pyvips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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 *
Expand Down
8 changes: 4 additions & 4 deletions pyvips/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}


Expand All @@ -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)}


Expand Down
11 changes: 6 additions & 5 deletions pyvips/pyvips_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -14,7 +14,7 @@
ffibuilder.set_source("_libvips",
r"""
#include <vips/vips.h>
""",
""",
**pkgconfig.parse('vips'))

# pkgconfig 1.5+ has modversion ... otherwise, use a small shim
Expand All @@ -38,12 +38,13 @@ def modversion(package):
'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))

Expand Down
Loading