All the generation code is gathered in /Generator. To simplify all the process, we have split the generation of the code in several independent steps. The first one is to read all the CSV files to create a complex structure (dictionary gen_dict) with all the reference data. Then this structure is used to generate the class. As the step are separated, they can evolve separately. For instance, you can change the way the data are stored in the CSV file without changing the generation as long as you keep the data structure organization.
The structure gen_dict is a dictionary gathering all the reference data for all the classes. It is the structure that is generated by the first step and which is used to generate the code.
The structure gen_dict is compose of several imbricated list and dict. The fist level is a dictionary with the group ‘Slot’, ‘Machine’… as key and dictionary as value. This first level match the group separation of CSV files.
At the second level, we have the content of an CSV file as a dictionary with CSV name (class name) as key and dictionary as value.
The third level correspond to the data of a class (or the sheet of the CSV file). These new dictionary contains the follows keys:
- properties : a list of dictionary with key matching the CSV sheet column: name, type, min, max, value, desc (one dictionary for each property of the class)
- constants: a list of dictionary with the key name, value (one for each constant of the class)
- methods: a list of all the class method name
- daughters: a list of all the class daughter name
- package: name of the group of the class (same as the first dictionary key, but useful for generation)
- desc: a string with the description of the class (for help text)
- mother: a string with the mother class name (if empty, FrozenClass will be used as default)
For instance, the description of the parameter H0 of Slot_Type_1_0 is stored in: gen_dict[‘Slot’][‘Slot_Type_1_0’][‘properties’][0][‘desc’] (if we suppose that H0 is first in the list of properties).
The gen_dict structure is then used for the class generation. The respective code can be found in /Generator/class_generator.py file. Note that some common function had been gathered in read_fct.
To gain in readability, the generated files have been split in several part and some function have been dedicated to generate specific part of the code. The generation process is very complex since there are many possible cases. For instance, we need to adapt the code according to the type of property (a PYLEECAN type would need the corresponding import at the start of the file, some class are inherited, some are not, some use numpy array, some don’t…). If you need to change this code, please consider that it should work for every single class in PYLEECAN: always start by modifying the class generation and then check that all the test are still right.
The result are saved in /Classes/class_name.py. As these files are completely rewritten by the generator, you must never modify them yourself. If you need to change the code of the generator, you should start by looking these files (for different cases with/without PYLEECAN classes, with/without inheritance…) to know what you need to generate.