Skip to content

Commit 28f50a7

Browse files
authored
Regenerate enums (#537)
* Avoid subtracting `-1` from the number of possible enum values * Regenerate enums * Avoid generating redundant enums
1 parent 292db90 commit 28f50a7

File tree

4 files changed

+83
-115
lines changed

4 files changed

+83
-115
lines changed

examples/gen-enums.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import xml.etree.ElementTree as ET
55

66
from pyvips import ffi, enum_dict, flags_dict, \
7-
vips_lib, type_map, type_name, type_from_name
7+
type_map, type_name, type_from_name
88

99
# This file generates enums.py -- the set of classes giving the permissible
1010
# values for the pyvips enums/flags. Run with something like:
@@ -103,10 +103,6 @@ def add_nickname(gtype, a, b):
103103

104104
type_map(type_from_name('GEnum'), add_nickname)
105105

106-
# Filter internal enums
107-
blacklist = ['VipsImageType', 'VipsToken']
108-
all_nicknames = [name for name in all_nicknames if name not in blacklist]
109-
110106
for name in all_nicknames:
111107
gtype = type_from_name(name)
112108
python_name = remove_prefix(name)
@@ -198,11 +194,6 @@ def add_nickname(gtype, a, b):
198194

199195

200196
if __name__ == "__main__":
201-
# otherwise we're missing some enums
202-
vips_lib.vips_token_get_type()
203-
vips_lib.vips_saveable_get_type()
204-
vips_lib.vips_image_type_get_type()
205-
206197
print('# libvips enums -- this file is generated automatically')
207198
print('# flake8: noqa: E501') # ignore line too long error
208199
generate_enums()

pyvips/base.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,12 @@ def values_for_enum(gtype):
117117
g_type_class = gobject_lib.g_type_class_ref(gtype)
118118
g_enum_class = ffi.cast('GEnumClass *', g_type_class)
119119

120-
# -1 since we always have a "last" member.
121-
return [_to_string(g_enum_class.values[i].value_nick)
122-
for i in range(g_enum_class.n_values - 1)]
120+
result = [_to_string(g_enum_class.values[i].value_nick)
121+
for i in range(g_enum_class.n_values)]
122+
# FIXME: remove after https://github.com/libvips/libvips/pull/4520
123+
if 'last' in result:
124+
result.remove('last')
125+
return result
123126

124127

125128
def values_for_flag(gtype):
@@ -138,10 +141,12 @@ def enum_dict(gtype):
138141
g_type_class = gobject_lib.g_type_class_ref(gtype)
139142
g_enum_class = ffi.cast('GEnumClass *', g_type_class)
140143

141-
# -1 since we always have a "last" member.
142-
return {_to_string(g_enum_class.values[i].value_nick):
143-
g_enum_class.values[i].value
144-
for i in range(g_enum_class.n_values - 1)}
144+
result = {_to_string(g_enum_class.values[i].value_nick):
145+
g_enum_class.values[i].value
146+
for i in range(g_enum_class.n_values)}
147+
# FIXME: remove after https://github.com/libvips/libvips/pull/4520
148+
result.pop('last', None)
149+
return result
145150

146151

147152
def flags_dict(gtype):

0 commit comments

Comments
 (0)