better handling of deprecated args in py

we now allow optional deprecated args to be set
This commit is contained in:
John Cupitt 2016-02-25 11:15:47 +00:00
parent 840c3f2e63
commit 8911820d9e
1 changed files with 18 additions and 9 deletions

View File

@ -247,11 +247,12 @@ Vips.Argument = Argument
class Operation(Vips.Operation):
# find all the args for this op, sort into priority order
# remember to ignore deprecated ones
# we leave deprecated args in this list: for compatibility, we want users
# to be able to set them
# if you are (for example) generating docs, you'll need to filter out the
# deprecated args yourself
def get_args(self):
args = [Argument(self, x) for x in self.props]
args = [y for y in args
if not y.flags & Vips.ArgumentFlags.DEPRECATED]
args.sort(key = lambda x: x.priority)
return args
@ -295,9 +296,10 @@ def _call_base(name, required, optional, self = None, option_string = None):
enm = Vips.ArgumentFlags
# find all required, unassigned input args
# find all required, unassigned, undeprecated input args
required_input = [x for x in args if x.flags & enm.INPUT and
x.flags & enm.REQUIRED and
not x.flags & enm.DEPRECATED and
not x.isset]
# do we have a non-None self pointer? this is used to set the first
@ -342,6 +344,8 @@ def _call_base(name, required, optional, self = None, option_string = None):
# find all optional, unassigned input args ... make a hash from name to
# Argument
# we let deprecated ones through, we want to allow assigment to them for
# compat
optional_input = {x.name: x for x in args if x.flags & enm.INPUT and
not x.flags & enm.REQUIRED and
not x.isset}
@ -383,8 +387,8 @@ def _call_base(name, required, optional, self = None, option_string = None):
out = []
for x in args:
# required output arg
if x.flags & enm.OUTPUT and x.flags & enm.REQUIRED:
# required non-deprecated output arg
if x.flags & enm.OUTPUT and x.flags & enm.REQUIRED and not x.flags & enm.DEPRECATED:
out.append(x.get_value())
# modified input arg ... this will get the memory image we made above
@ -505,6 +509,10 @@ def generate_docstring(name):
# find all the args for this op, sort into priority order
args = op.get_args()
# we are only interested in non-deprecated args
args = [y for y in args
if not y.flags & Vips.ArgumentFlags.DEPRECATED]
enm = Vips.ArgumentFlags
# find all required, unassigned input args
@ -540,9 +548,10 @@ def generate_docstring(name):
result += member_x.name + "." + name + "("
else:
result += "Vips.Image." + name + "("
result += ", ".join([x.name for x in required_input
if x != member_x])
if len(optional_input) > 0:
required_input_args = [x.name for x in required_input if x != member_x]
result += ", ".join(required_input_args)
if len(optional_input) > 0 and len(required_input_args) > 0:
result += ", "
result += ", ".join([x.name + " = " + x.prop.value_type.name
for x in optional_input])