Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BOURNEUF Lucas
biseau
Commits
62cf0b90
Commit
62cf0b90
authored
Jul 02, 2019
by
Aluriak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implementation of some biseau specific types
parent
950d2367
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
biseau/module_loader.py
biseau/module_loader.py
+4
-2
biseau/run_on_types.py
biseau/run_on_types.py
+20
-0
No files found.
biseau/module_loader.py
View file @
62cf0b90
...
...
@@ -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
)
...
...
biseau/run_on_types.py
0 → 100644
View file @
62cf0b90
"""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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment