Skip to content
Snippets Groups Projects
Commit bb0c70c9 authored by s-roscher's avatar s-roscher
Browse files

Update python-modularization.md:

- Added pictures to text
parent 0dda098e
No related branches found
No related tags found
2 merge requests!76Draft: Updated Python code example,!73Initial open source version
Pipeline #1512947 waiting for manual action
......@@ -51,12 +51,12 @@ No, seriously... PEP 8 is considered a common and official Python style guide. T
At some points, the standard leaves options. These are explained in more detail below.
### Code Layout
### Code layout
- Tabs or spaces? Spaces
- Maximum Line Length? 119 characters
- Line Break Before or After a Binary Operator? Before
### Naming Conventions
### Naming conventions
- Packages: all-lowercase, starting with "py" (e.g., `pymodulepackage` or `pymathpackage`)
- Modules: all-lowercase (e.g., `datapreprocessingmodule`)
- Functions: `lowercase_with_underscores`
......@@ -125,7 +125,7 @@ This means, for example:
- `read_paths_and_names`
- `read_xml_information`.
## Excursion: What is a Module?
## Excursion: What is a module?
- A **module** is a *.py file containing related code, allowing its functionality to be reused across different parts of an application.
- Modules can include variables, functions, classes, and more.
- Import modules using `import [module_name]`.
......@@ -137,8 +137,8 @@ This means, for example:
# Code modularity (Python-only modules) {#code-modularity-python-only-modules}
In the following, the modularized structure of a Python module is explained using the `cost_estimation` module. The according folder structure is shown in the following picture. It is also available for download.
![](../img/_01_code-modularity.png)
![](../../assets/images/developer/style/python-modularization_01_code-modularity.png)
@warning Check, if images displayed correctly here!
@warning Insert files here!
@warning {F216186}
......@@ -150,7 +150,8 @@ The following **layers** are selected for cost calculation:
3. Calculation method (e.g., `operating_cost_estimation_tu_berlin`, green folder)
4. Energy carrier (e.g., `kerosene` or `liquid_hydrogen`, grey folder) - **USER LAYER** (This is where the magic happens! \emoji mage)
@warning Insert files/images here! {F204708, layout=middle, float, size=full}
![](../../assets/images/developer/style/python-modularization_02_example-folder.png)
@warning Check, if images displayed correctly here!
## File structure
......@@ -192,23 +193,25 @@ rAircraftDesign
## Files that require changes by the module manager
The code is designed to be highly generalized, meaning that only a few files need changes by the module manager. These files are shown in the following image and are discussed below in more detail. In some parts of the code, dynamic import commands and function names are generated, with examples provided at relevant points to illustrate how these commands work.
![](../../assets/images/developer/style/python-modularization_03_example-folder-changes-module-manager.png)
@warning Check, if images displayed correctly here!
### The `main()`
- Update the module name in two places within the docString
- Customize the module configuration file name
- Adjust the `runtime_output_string`
@warning Upload files/images here!
@warning {F204719, layout=left, float, size=full}
@warning {F204721, layout=left, float, size=full}
@warning {F204723, layout=left, float, size=full}
![](../../assets/images/developer/style/python-modularization_04_main-01.png)
![](../../assets/images/developer/style/python-modularization_05_main-02.png)
@warning Check, if images displayed correctly here!
### The `data_preprocessing` (`datapreprocessing.py`)
- Update the layer description in the docString
- Customize the layer description within `layer_description_dict`. If a layer is unknown (e.g., `user_layer`), set it to 'None' rather than a path and call the relevant function (e.g., `read_energy_carrier`) as indicated (see lines 69 and following).
@warning Upload files/images here!
@warning {F204725, layout=left, float, size=full}
@warning {F204727, layout=left, float, size=full}
![](../../assets/images/developer/style/python-modularization_06_datapreprocessing-01.png)
![](../../assets/images/developer/style/python-modularization_07_datapreprocessing-02.png)
@warning Check, if images displayed correctly here!
**Example for `module_import_name`**
In this example, `module_import_name` at line 68 would be: `src.tube_and_wing.empirical.operating_cost_estimation_tu_berlin`.
......@@ -221,9 +224,9 @@ To import a module from `usermethoddatapreparation.py` at line 74, the command i
- Modify `paths_to_key_parameters_list`
- Adjust `module_key_parameters_dict`
@warning Upload files/images here!
@warning {F204729, layout=left, float, size=full}
@warning {F204731, layout=left, float, size=full}
![](../../assets/images/developer/style/python-modularization_08_datapostprocessing-01.png)
![](../../assets/images/developer/style/python-modularization_09_datapostprocessing-02.png)
@warning Check, if images displayed correctly here!
## Files that require changes by the user
Similarly, the code is structured so that only a few files require modifications by the user. These files are highlighted in the following image.
......@@ -239,6 +242,9 @@ Users are free to structure the code within these files but must ensure that all
More detailed instructions for required changes are available within the docStrings of each corresponding file.
![](../../assets/images/developer/style/python-modularization_10_example-folder-changes-user.png)
@warning Check, if images displayed correctly here!
# Logging and printing {#logging-and-printing}
The Python framework in this project has a customized logging function, which builds on Python’s [logging facility](https://docs.python.org/3/library/logging.html). The following logging levels are available:
......@@ -279,8 +285,8 @@ The necessary steps are listed below. Please ensure to read the respective expla
- **Windows:** `python -m pip install --upgrade pip`
2. Navigate to the `AircraftDesign/unicado_python_library` folder (illustrated below) to set up the required folder structure.
@warning Upload files/images here!
@warning {F204733, layout=left, float, size=full}
![](../../assets/images/developer/style/python-modularization_11_unicado-python-library.png)
@warning Check, if images displayed correctly here!
## Step 1: Create the package subfolder
In `unicado_python_library`, create a new subfolder for the package. Follow this naming convention:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment