Skip to content

Commit

Permalink
Merge pull request #241 from AgriculturalModelExchangeInitiative/issu…
Browse files Browse the repository at this point in the history
…e240

Issue240
  • Loading branch information
pradal authored Oct 21, 2024
2 parents 3f16757 + 49441a9 commit a56c9e9
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 54 deletions.
2 changes: 1 addition & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ requirements:
run:
- python {{PY_VER}}
- antlr4-python3-runtime ==4.8
- cython
- cython ==0.29.21
- xmlformatter
- path
- numpy ==1.16.6
Expand Down
15 changes: 8 additions & 7 deletions src/pycropml/cyml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@author: midingoy
"""
import os
from os.path import isdir
from path import Path
import pycropml
from pycropml.transpiler.main import Main
Expand Down Expand Up @@ -72,31 +73,31 @@ def transpile_package(package, language):
dir_doc = Path(os.path.join(pkg, 'doc'))

# Generate packages if the directories does not exists.
if not output.isdir():
if not isdir(output):
output.mkdir()
if not dir_test.isdir():
if not isdir(dir_test):
dir_test.mkdir()
if not dir_doc.isdir():
if not isdir(dir_doc):
dir_doc.mkdir()

dir_images = Path(os.path.join(dir_doc, 'images'))
if not dir_images.isdir():
if not isdir(dir_images):
dir_images.mkdir()

m2p = render_cyml.Model2Package(models, dir=output)
m2p.generate_package() # generate cyml models in "pyx" directory
tg_rep1 = Path(os.path.join(output, language)) # target language models directory in output
dir_test_lang = Path(os.path.join(dir_test, language))

if not tg_rep1.isdir():
if not isdir(tg_rep1):
tg_rep1.mkdir()

namep_ = namep.replace("-", "_")
tg_rep = Path(os.path.join(tg_rep1, namep_))
if not tg_rep.isdir():
if not isdir(tg_rep):
tg_rep.mkdir()

if not dir_test_lang.isdir(): #Create if it doesn't exist
if not isdir(dir_test_lang): #Create if it doesn't exist
dir_test_lang.mkdir()

m2p.write_tests()
Expand Down
13 changes: 7 additions & 6 deletions src/pycropml/render_cyml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"""
from __future__ import print_function
from __future__ import absolute_import
from path import Path
from datetime import datetime
import os.path
from pycropml.modelunit import ModelUnit
from os.path import isdir
import sys
from path import Path
import six
import shutil
from datetime import datetime
from pycropml.modelunit import ModelUnit
from . import error
import sys

DATATYPE = {}
DATATYPE['INT'] = "int"
Expand Down Expand Up @@ -63,7 +64,7 @@ def generate_package(self):
# Create a directory (mymodel)

directory = Path(os.path.join(self.cwd, 'pyx'))
if directory.isdir():
if isdir(directory):
self.dir = directory
else:
self.dir = directory.mkdir()
Expand Down Expand Up @@ -335,7 +336,7 @@ def write_tests(self):
TODO: Manage several models rather than just one.
"""
self.rep = Path(os.path.join(self.rep, 'test', 'pyx'))
if not self.rep.isdir():
if not isdir(self.rep):
self.rep.mkdir()
files = []
count = 0
Expand Down
6 changes: 4 additions & 2 deletions src/pycropml/render_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"""
from __future__ import print_function
from __future__ import absolute_import
import six
import os
from os.path import isdir
from path import Path

# The package used to generate Notebook
import nbformat as nbf

from . import render_python as rp
import six



Expand Down Expand Up @@ -48,7 +50,7 @@ def generate_notebook(self):
# Create a directory (mymodel)
cwd = Path(self.dir)
directory=cwd/'python_notebook'
if (directory).isdir() :
if isdir(directory):
_dir = directory
else:
_dir = directory.mkdir()
Expand Down
4 changes: 3 additions & 1 deletion src/pycropml/render_notebook_csharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"""
from __future__ import print_function
from __future__ import absolute_import
import os
from os.path import isdir
from path import Path

# The package used to generate Notebook
Expand Down Expand Up @@ -51,7 +53,7 @@ def generate_notebook(self):
# Create a directory (mymodel)
cwd = Path(self.dir)
directory=cwd/'csharp_notebook'
if (directory).isdir() :
if isdir(directory):
_dir = directory
else:
_dir = directory.mkdir()
Expand Down
4 changes: 3 additions & 1 deletion src/pycropml/render_notebook_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"""
from __future__ import print_function
from __future__ import absolute_import
import os
from os.path import isdir
from path import Path

# The package used to generate Notebook
Expand Down Expand Up @@ -48,7 +50,7 @@ def generate_notebook(self):
# Create a directory (mymodel)
cwd = Path(self.dir)
directory=cwd/'java_notebook'
if (directory).isdir() :
if isdir(directory):
_dir = directory
else:
_dir = directory.mkdir()
Expand Down
12 changes: 7 additions & 5 deletions src/pycropml/render_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"""
from __future__ import print_function
from __future__ import absolute_import
from path import Path
import numpy
from datetime import datetime
import os.path
from os.path import isdir
import six
from datetime import datetime
from path import Path
import numpy

try:
from openalea.core import interface as inter
Expand Down Expand Up @@ -78,7 +79,7 @@ def generate_package(self):
# Create a directory (mymodel)
cwd = Path(self.dir)
directory=cwd/'python_model'
if (directory).isdir() :
if isdir(directory):
self.dir = directory
else:
self.dir = directory.mkdir()
Expand Down Expand Up @@ -458,7 +459,8 @@ def generate_doc(model):
Institution: %s
ExtendedDescription: %s
ShortDescription: %s
""" %(desc.Title, "-Version: " + model.version + " -Time step: " + model.timestep, desc.Authors, desc.Reference, desc.Institution, desc.ExtendedDescription, desc.ShortDescription)
""" %(desc.Title, "-Version: " + model.version + " -Time step: " + model.timestep,
desc.Authors, desc.Reference, desc.Institution, desc.ExtendedDescription, desc.ShortDescription)

code = '\n'
code += _doc
Expand Down
20 changes: 12 additions & 8 deletions src/pycropml/transpiler/antlr_py/bioma/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

from __future__ import absolute_import
from __future__ import print_function
from path import Path
import os
from os.path import isdir
from copy import deepcopy
from typing import *
from path import Path

import networkx as nx
import itertools

from pycropml.transpiler.antlr_py.to_CASG import to_dictASG, to_CASG
from pycropml.transpiler.antlr_py.bioma.biomaExtraction import BiomaExtraction
from pycropml.transpiler.pseudo_tree import Node
Expand All @@ -13,8 +20,6 @@
from pycropml.transpiler.antlr_py.generateCyml import writeCyml
from pycropml.transpiler.antlr_py.createXml import Pl2Crop2ml
from pycropml.transpiler.antlr_py import repowalk
from copy import deepcopy
from typing import *

from pycropml.transpiler.antlr_py.csharp.csharp_preprocessing import ExprStatNode, TransformLocal, CheckingInOut, Custom_call, Declarations,Assignment, Member_access, Binary_op, Index, Local
from pycropml.transpiler.antlr_py.codeExtraction import extraction
Expand Down Expand Up @@ -58,19 +63,18 @@

def create_package(output):
crop2ml_rep = Path(os.path.join(output, 'crop2ml'))
if not crop2ml_rep.isdir():
if not isdir(crop2ml_rep):
crop2ml_rep.mkdir()
algo_rep = Path(os.path.join(crop2ml_rep, 'algo'))
if not algo_rep.isdir():
if not isdir(algo_rep):
algo_rep.mkdir()
cyml_rep = Path(os.path.join(algo_rep, 'pyx'))
if not cyml_rep.isdir():
if not isdir(cyml_rep):
cyml_rep.mkdir()
return crop2ml_rep, cyml_rep


import networkx as nx
import itertools


def function_dependency(st, f):
r = [f]
Expand Down
17 changes: 10 additions & 7 deletions src/pycropml/transpiler/antlr_py/bioma/run2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

from __future__ import absolute_import
from __future__ import print_function
from path import Path
import os
from os.path import isdir
from path import Path
from copy import deepcopy
from typing import *

from collections import defaultdict

from pycropml.transpiler.antlr_py.to_CASG import to_dictASG, to_CASG
from pycropml.transpiler.antlr_py.bioma.biomaExtraction import BiomaExtraction
from pycropml.transpiler.pseudo_tree import Node
Expand All @@ -13,8 +19,6 @@
from pycropml.transpiler.antlr_py.generateCyml import writeCyml
from pycropml.transpiler.antlr_py.createXml import Pl2Crop2ml
from pycropml.transpiler.antlr_py import repowalk
from copy import deepcopy
from typing import *

from pycropml.transpiler.antlr_py.csharp.csharp_preprocessing import ExprStatNode, TransformLocal, CheckingInOut, Custom_call, Declarations,Assignment, Member_access, Binary_op, Index, Local

Expand Down Expand Up @@ -53,13 +57,13 @@

def create_package(output):
crop2ml_rep = Path(os.path.join(output, 'crop2ml'))
if not crop2ml_rep.isdir():
if not isdir(crop2ml_rep):
crop2ml_rep.mkdir()
algo_rep = Path(os.path.join(crop2ml_rep, 'algo'))
if not algo_rep.isdir():
if not isdir(algo_rep):
algo_rep.mkdir()
cyml_rep = Path(os.path.join(algo_rep, 'pyx'))
if not cyml_rep.isdir():
if not isdir(cyml_rep):
cyml_rep.mkdir()
return crop2ml_rep, cyml_rep

Expand Down Expand Up @@ -108,7 +112,6 @@ def redefine_params(m:Node, var_:Tuple, member_category, inputs, outputs)->List[



from collections import defaultdict

def inst_dclass(meth):
params = meth.params
Expand Down
14 changes: 6 additions & 8 deletions src/pycropml/transpiler/antlr_py/simplace/run.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import absolute_import
from __future__ import print_function

from path import Path
import os
from os.path import isdir
from path import Path

from pycropml.transpiler.antlr_py.to_CASG import to_CASG, to_dictASG
from pycropml.transpiler.antlr_py.createXml import Pl2Crop2ml
from pycropml.transpiler.antlr_py.generateCyml import writeCyml
Expand All @@ -16,10 +18,6 @@
from pycropml.transpiler.antlr_py.codeExtraction import remove






def translate(algo, names):

f = Declarations([], {},names)
Expand Down Expand Up @@ -76,13 +74,13 @@ def run_simplace(components, output):
simpleStrat= Path(components).glob('*.java')
compositeStrat = Path(components).glob('*.xml')[0]
crop2ml_rep = Path(os.path.join(output, 'crop2ml'))
if not crop2ml_rep.isdir():
if not isdir(crop2ml_rep):
crop2ml_rep.mkdir()
algo_rep = Path(os.path.join(crop2ml_rep, 'algo'))
if not algo_rep.isdir():
if not isdir(algo_rep):
algo_rep.mkdir()
cyml_rep = Path(os.path.join(algo_rep, 'pyx'))
if not cyml_rep.isdir():
if not isdir(cyml_rep):
cyml_rep.mkdir()
models = []
for strat in simpleStrat:
Expand Down
10 changes: 6 additions & 4 deletions src/pycropml/transpiler/antlr_py/stics/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from __future__ import absolute_import
from __future__ import print_function
import os
#import copy
from os.path import isdir
import tempfile
from path import Path
from collections import OrderedDict

from pycropml.composition import Description
from pycropml.transpiler.antlr_py import repowalk
from pycropml.transpiler.antlr_py.to_CASG import to_CASG, to_dictASG
Expand All @@ -9,16 +15,12 @@
from pycropml.transpiler.antlr_py.generateCyml import writeCyml
from pycropml.transpiler.antlr_py.fortran import f90_cyml
from pycropml.transpiler.antlr_py.cmake.cmakeTransformer import retrievefiles
from collections import OrderedDict
#from pycropml.transpiler.antlr_py.extraction import ExtractComments
from pycropml.transpiler.antlr_py.codeExtraction import extraction
from pycropml.transpiler.antlr_py.fortran.fortran_preprocessing import Declarations, Attr, Assignment, Call_stmt, Implicit_return, Local
from pycropml.transpiler.antlr_py.to_specification import extractMetaInfo, createObjectModel, extractcomments, createObjectCompo
from pycropml.transpiler.antlr_py.createXml import Pl2Crop2ml, generate_compositefile, generate_unitfile, create_repo
import tempfile
from pycropml.transpiler.antlr_py.extract_metadata_from_comment import ExtractComments, extract
import copy
from path import Path

types = ["float", "str", "list", "array", "int", "boolean"]

Expand Down
9 changes: 5 additions & 4 deletions src/pycropml/transpiler/antlr_py/tests/test_bioma.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

from __future__ import absolute_import
from __future__ import print_function
from path import Path
import os
from os.path import isdir
from path import Path
from pycropml.transpiler.antlr_py.to_CASG import to_dictASG, to_CASG
from pycropml.transpiler.antlr_py.bioma.biomaExtraction import BiomaExtraction
from pycropml.transpiler.pseudo_tree import Node
Expand All @@ -27,13 +28,13 @@

output = cwd/'examples'/'SiriusComponent'/'phenology'
crop2ml_rep = Path(os.path.join(output, 'crop2ml'))
if not crop2ml_rep.isdir():
if not isdir(crop2ml_rep):
crop2ml_rep.mkdir()
algo_rep = Path(os.path.join(crop2ml_rep, 'algo'))
if not algo_rep.isdir():
if not isdir(algo_rep):
algo_rep.mkdir()
cyml_rep = Path(os.path.join(algo_rep, 'pyx'))
if not cyml_rep.isdir():
if not isdir(cyml_rep):
cyml_rep.mkdir()


Expand Down

0 comments on commit a56c9e9

Please sign in to comment.