Commit 62cf0b90 authored by Aluriak's avatar Aluriak

implementation of some biseau specific types

parent 950d2367
......@@ -15,6 +15,7 @@ from collections import defaultdict
import clyngor
from biseau import utils
from biseau import run_on_types
from biseau import script as script_functions
from biseau.script import Script, Module
......@@ -286,9 +287,10 @@ def build_script_from_module(module, *, defaults:dict={}) -> Script or ScriptErr
argtype = args.annotations.get(arg)
isgroup = isinstance(argtype, (tuple, list, set, frozenset))
isrange = isinstance(argtype, range)
if not isgroup and not isrange and argtype not in OPTIONS_TYPES:
isbiseautype = not isgroup and argtype in run_on_types.all_types
if not isbiseautype and not isgroup and not isrange and argtype not in OPTIONS_TYPES:
bad_script_error(module, "Option {} does not have a valid annotation "
"({}). Only tuples, lists, (frozen)sets, and primitive types such as {} are accepted"
"({}). Only tuples, lists, (frozen)sets, types in biseau.run_on_types.types_all and primitive types such as {} are accepted"
"".format(arg, argtype, ', '.join(map(str, OPTIONS_TYPES))))
if isrange:
default = (args.kwonlydefaults or {}).get(arg, (argtype.start or 0) if argtype else 0)
......
"""Definition of some types, to be used as parameter
annotation in python plugins, e.g:
from biseau.run_on_types import percent
def run_on(models:iter, *, support:percent):
...
"""
def percent(value:int) -> int:
"A int between 0 and 100, inclusive"
return min(100, max(0, int(value)))
def ratio(value:float) -> float:
"A number between 0 and 1, inclusive"
return min(1., max(0, float(value)))
all_types = {percent, ratio}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment