14
14
from datetime import datetime
15
15
from pycropml .modelunit import ModelUnit
16
16
from . import error
17
+ from . import split_function
17
18
18
19
DATATYPE = {}
19
20
DATATYPE ['INT' ] = "int"
@@ -70,6 +71,7 @@ def generate_package(self):
70
71
self .dir = directory .mkdir ()
71
72
72
73
files = []
74
+
73
75
count = 0
74
76
for model in self .models :
75
77
self .generate_component (model )
@@ -84,10 +86,13 @@ def generate_package(self):
84
86
85
87
def generate_component (self , model_unit ):
86
88
"""Todo"""
89
+
90
+ functions = []
87
91
if model_unit .modelid .split ("." )[0 ] != "function" :
88
92
func_name = f"model_{ signature (model_unit )} "
89
93
else :
90
94
func_name = signature (model_unit )
95
+
91
96
types = [inp .datatype for inp in model_unit .inputs ] + [out .datatype for out in model_unit .outputs ]
92
97
self .code = "import numpy\n "
93
98
self .code += "from math import *\n "
@@ -99,19 +104,15 @@ def generate_component(self, model_unit):
99
104
100
105
self .code += self .generate_function_signature (func_name , model_unit .inputs ) + "\n "
101
106
self .code += self .generate_function_doc (model_unit ) + "\n "
102
- if sys .version_info [0 ] >= 3 :
103
- self .code += self .generate_algorithm (model_unit ) + "\n "
104
- else :
105
- self .code += self .generate_algorithm (model_unit ).decode ("utf-8" ) + "\n "
106
-
107
- if model_unit .function :
108
- for function in model_unit .function :
109
- if function .language in ("Cyml" , "cyml" ):
110
- filefunc = Path (os .path .join (model_unit .path , "crop2ml" , function .filename ))
111
- with open (filefunc .encode ('utf-8' ), 'r' ) as f :
112
- source = f .read ()
113
- self .code += source
114
- self .code += "\n \n \n "
107
+ self .code += self .generate_algorithm (model_unit ) + "\n "
108
+
109
+ if model_unit .function :
110
+ function_files = [Path (os .path .join (model_unit .path , "crop2ml" , function .filename ))
111
+ for function in model_unit .function if function .language .lower () == "cyml" ]
112
+
113
+ content = split_function .unique_functions (function_files )
114
+ self .code += content
115
+ self .code += "\n "
115
116
116
117
return self .code
117
118
0 commit comments