Ejemplo n.º 1
0
def generate_code(root_path):
    """Generate pyleecan Classes code according to doc in root_path

    Parameters
    ----------
    root_path : str
        Path to the main folder of Pyleecan

    Returns
    -------
    None
    """
    CLASS_DIR = join(root_path, "Classes")
    FUNC_DIR = join(root_path, "Functions")
    DOC_DIR = join(root_path, "Generator", "ClassesRef")
    print("Reading classes csv in :" + DOC_DIR)
    print("Saving generated files in :" + CLASS_DIR)

    # A file to import every classes quickly
    import_file = open(join(CLASS_DIR, "import_all.py"), "w")
    import_file.write("# -*- coding: utf-8 -*-\n\n")
    # A file to select the constructor according to a string
    load_file = open(join(FUNC_DIR, "load_switch.py"), "w")
    load_file.write("# -*- coding: utf-8 -*-\n")
    load_file.write("from pyleecan.Classes.import_all import *\n\n")
    load_file.write("load_switch = {\n")

    # Read all the csv files
    gen_dict = read_all(DOC_DIR)

    # Generate all the class files (sorted to remove "commit noise")
    for class_name, class_dict in iter(sorted(list(gen_dict.items()))):
        import_file.write("from pyleecan.Classes." + class_name + " import " +
                          class_name + "\n")
        load_file.write('    "' + class_name + '": ' + class_name + ",\n")
        print("Generation of " + class_name + " class")
        generate_class(gen_dict, class_name, CLASS_DIR)
    import_file.close()
    load_file.write("}\n")
    load_file.close()

    print("#############################\nGenerating gui....")
    generate_gui(gen_dict)
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-
"""Created on Mon Nov 10 15:44:20 2014
@author: pierre_b
"""
import sys
from os.path import dirname, abspath, normpath, join

sys.path.insert(0, normpath(abspath(join(dirname(__file__), "..", ".."))))

from pyleecan.Generator.run_generate_classes import generate_code
from pyleecan.Generator.gui_generator import generate_gui
from pyleecan.Generator.read_fct import read_all
from pyleecan.definitions import MAIN_DIR, DOC_DIR, INT_DIR

if __name__ == "__main__":
    gen_dict = read_all(DOC_DIR, is_internal=False, in_path=INT_DIR)
    generate_code(MAIN_DIR, gen_dict)
    generate_gui(gen_dict, is_gen_resource=True)
Ejemplo n.º 3
0
from pyleecan.Generator.ClassGenerator.init_method_generator import get_mother_attr
from pyleecan.definitions import DOC_DIR
from pyleecan.Tests.find import (
    find_test_value,
    is_type_list,
    is_type_dict,
    MissingTypeError,
    PYTHON_TYPE,
)

from pyleecan.Classes._check import CheckMinError, CheckTypeError, CheckMaxError
from pyleecan.Classes._check import NotADictError
from pyleecan.Classes._frozen import FrozenClass, FrozenError

# Get the dict of all the classes and their information
gen_dict = read_all(DOC_DIR)  # dict of class dict
# Remove one list level (packages Machine, Simulation, Material...)
class_list = list(gen_dict.values())
from pyleecan.Classes.import_all import *


@ddt
class test_all_Classes(TestCase):
    """This test check that all the classes matches the current documentation
    It makes sure that the class generator works and was run
    """
    @data(*class_list)
    def test_class_init_default(self, class_dict):
        """Check if every propeties in the doc is created
        by __init__ with the default value"""
        # Import and init the class
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-
"""Created on Mon Nov 10 15:44:20 2014
@author: pierre_b
"""
import sys
from os.path import dirname, abspath, normpath, join

sys.path.insert(0, normpath(abspath(join(dirname(__file__), "..", ".."))))

from os import mkdir
from os.path import isdir

from pyleecan.Generator.class_generator import generate_class
from pyleecan.Generator.gui_generator import generate_gui
from pyleecan.Generator.read_fct import read_all
from pyleecan.definitions import MAIN_DIR

if __name__ == "__main__":
    DOC_DIR = join(MAIN_DIR, "Generator", "ClassesRef")
    gen_dict = read_all(DOC_DIR)
    print("#############################\nGenerating gui....")
    generate_gui(gen_dict, is_gen_resource=False)
Ejemplo n.º 5
0
def generate_code(root_path, gen_dict=None):
    """Generate pyleecan Classes code according to doc in root_path

    Parameters
    ----------
    root_path : str
        Path to the main folder of Pyleecan
    gen_dict : dict
        Generation dictionnary (contains all the csv data)
    Returns
    -------
    None
    """
    CLASS_DIR = join(root_path, "Classes")
    FUNC_DIR = join(root_path, "Functions")
    DOC_DIR = join(root_path, "Generator", "ClassesRef")
    print("Reading classes csv in: " + DOC_DIR)
    print("Saving generated files in: " + CLASS_DIR)

    path = __file__[__file__.index("pyleecan") :]
    path = path.replace("\\", "/")

    # Deleting all the previous class
    print("Deleting old class files...")
    for file_name in listdir(CLASS_DIR):
        if file_name[0] != "_":
            remove(join(CLASS_DIR, file_name))

    # A file to import every classes quickly
    import_file = open(join(CLASS_DIR, "import_all.py"), "w")
    import_file.write("# -*- coding: utf-8 -*-\n\n")
    import_file.write('"""File generated by generate_code() - ' + path + "\n")
    import_file.write('WARNING! All changes made in this file will be lost!\n"""\n\n')

    # A file to select the constructor according to a string
    load_file = open(join(FUNC_DIR, "load_switch.py"), "w")
    load_file.write("# -*- coding: utf-8 -*-\n")
    load_file.write('"""File generated by generate_code() - ' + path + "\n")
    load_file.write('WARNING! All changes made in this file will be lost!\n"""\n\n')

    load_file.write("from pyleecan.Classes.import_all import *\n\n")
    load_file.write("load_switch = {\n")

    # Read all the csv files
    if gen_dict is None:
        gen_dict = read_all(DOC_DIR)

    # Generate all the class files (sorted to remove "commit noise")
    for class_name, _ in iter(sorted(list(gen_dict.items()))):
        import_file.write(
            "from pyleecan.Classes." + class_name + " import " + class_name + "\n"
        )
        load_file.write('    "' + class_name + '": ' + class_name + ",\n")
        print("Generation of " + class_name + " class")
        generate_class(gen_dict, class_name, CLASS_DIR)
    import_file.close()
    load_file.write("}\n")
    load_file.close()

    print("Generation of load_switch.py")
    print("Generation of import_all.py")

    # Save gen_dict
    class_dict_file = join(CLASS_DIR, "Class_Dict.json")
    with open(class_dict_file, "w") as json_file:
        json.dump(gen_dict, json_file, sort_keys=True, indent=4, separators=(",", ": "))