20 KiB
Developers documentation
#
#
#
This document is for the use of developers. It describes the project architecture, the tools available to assist development and debugging. It also describes the procedures for creating packages and the configurations required to set up the gitlab runners. Finally, this document explains how documentation is written and modified, and how to contribute to the project by modifying, improving or adding documentation, translations or code.
Introduction
Pamhyr2 is free and open source software (FOSS) graphical user interface (GUI) for 1D hydro-sedimentary modelling of rivers developed in Python (with version 3.8). It use PyQt at version 5 and matplotlib in version 3.4.1 or later for the user insterface (see for details). The architecture of project code follow the Qt Model/View architecture 1 (see details in section /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/Architecture). Pamhyr2 packages can be build manually (see section /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/Building%20packages), but there are automatically build with the gitlab-ci (see the section [[Setup the CI environment]]). Documentation files are written with org-mode2, let see section /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/Documentation%20files. Finally, to see the contribution rules, see the section /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/How%20to%20contribute?.
TODO Architecture
Pamhyr2's architecture is based on Qt Model/View, see Figure /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/graph-architecture. It is made up of several different components: the model (in blue), the graphical components (in red), the actions/delegates (in green), the commands (in purple), the solvers (in yellow) and the save file (in grey).
The model is a set of python classes and can be exported to a single SQLite3 format backup file. The view can be made up of various components, generally a Qt window with other view components, such as: a table, a text box, a button, a plot, and so on. The user can view the data using the view and interact with certain components. These components are linked to an action (such as a Python function) or to a delegate class. These actions or delegate can create a command (based on Qt UndoCommand class), this command must implement two functions: One to modify the model, one to reverte this modification and reset the model to previous state. All model modification must be perform by a command to be cancelled. The user can also run a solver and add some simulation results to model data.
digraph {
bgcolor="transparent";
node[colorscheme=set19,shape=box,style="filled",fillcolor=white];
save[label="Pamhyr save",fillcolor="9",shape=note];
model[label="Model",fillcolor="2"];
view[label="View",fillcolor="1"];
delegate[label="Delegate",fillcolor="3"];
action[label="Action",fillcolor="3"];
solver[label="Solver",fillcolor="6"];
undocommand[label="Command",fillcolor="4"];
user[label="User",shape=ellipse];
model -> save[label="Save"];
save -> model[label="Load"];
model -> view[label="Rendering"];
view -> delegate[label="Rendering"];
delegate -> undocommand[label="Create"];
action -> undocommand[label="Create"];
action -> solver[label="Run"];
solver -> model[label="Add results"];
undocommand -> model[label="Modify"];
view -> user[label="Vizualize"];
user -> delegate[label="Modify"];
user -> action[label="Activate"];
}
All the model source code are in the directory (let see section /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/Model for more details), the View components, delegate and command are in (see section /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/View). Solvers classes are in (see section /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/Solver).
TODO Model
- Model de donnée Python
- Correspond à une sauvegarde SQL
digraph {
bgcolor="transparent";
node[colorscheme=set19,shape=box,style="filled",fillcolor="2"];
study[label="Study"];
river[label="River"];
subgraph cluster00 {
label="Network"
rnode[label="RiverNode"];
redge[label="RiverReach"];
}
frictionlist[label="FrictionList"];
subgraph cluster01 {
label="Stricklers";
stricklers[label="Stricklers"];
stricklerslist[label="StricklersList"];
}
subgraph cluster02 {
label="BoundaryCondition";
boundaryconditionlist[label="BoundaryConditionList"];
boundarycondition[label="BoundaryCondition"];
}
subgraph cluster03 {
label="LateralContribution";
lateralcontributionlist[label="LateralContributionList"];
lateralcontribution[label="LateralContribution"];
}
subgraph cluster04 {
label="InitialConditions";
initialconditionsdict[label="InitialConditionsDict"];
initialconditions[label="InitialConditions"];
}
solverparameterslist[label="SolverParametersList"];
subgraph cluster05 {
label="Sediment";
sedimentlayerlist[label="SedimentLayerList"];
sedimentlayer[label="SedimentLayer"];
layer[label="Layer"];
}
subgraph cluster06 {
label="Greometry"
georeach[label="Reach"];
geocrosssection[label="Cross-section"];
geopoint[label="Point"];
}
subgraph cluster07 {
label="Results"
results[label="Results"]
rriver[label="River"];
rreach[label="Reach"];
rcrosssection[label="Cross-section"];
}
study -> river;
river -> rnode;
river -> redge;
redge -> rnode;
river -> boundaryconditionlist -> boundarycondition -> rnode;
river -> lateralcontributionlist -> lateralcontribution -> redge;
river -> initialconditionsdict -> initialconditions;
initialconditions -> redge;
river -> stricklerslist -> stricklers;
river -> solverparameterslist;
river -> sedimentlayerlist -> sedimentlayer -> layer;
redge -> frictionlist -> stricklers;
redge -> georeach -> geocrosssection -> geopoint;
geocrosssection -> sedimentlayer;
geopoint -> sedimentlayer;
results -> study[style="dashed"];
results -> rriver;
rriver -> river[style="dashed"];
rriver -> rreach;
rreach -> georeach[style="dashed"];
rreach -> rcrosssection;
rcrosssection -> geocrosssection[style="dashed"];
}
TODO SQL study file
TODO List class
TODO Dict class
TODO View
TODO UI file
TODO Translate
TODO Window
TODO UndoCommand
TODO Table
TODO Plot
TODO Mainwindow
TODO Solver
digraph {
bgcolor="transparent";
node[colorscheme=set19,shape=box,style="filled",fillcolor=9];
subgraph cluster0 {
label="Pamhyr2"
config[label="Config",fillcolor=5];
model[label="Model",fillcolor=2];
obj[label="Solver",fillcolor=6];
results[label="Results",fillcolor=2];
view[label="View",fillcolor=1];
results -> model[style="dashed"];
results -> obj[style="dashed"];
}
config -> obj[label=""];
obj -> model[style="dashed"];
subgraph cluster1{
label="System";
in[label="Solver input files",shape=note];
out[label="Solver output files",shape=note];
bin[label="Solver binary",shape=note];
}
obj -> in[label="Write (1)"];
obj -> bin[label="Execute (2)"];
bin -> in[label="Read (2.1)"];
bin -> out[label="Write (2.2)"];
obj -> results[label="Create (3)"];
obj -> out[label="Read (3.1)"];
view -> model[style="dashed"];
view -> results[style="dashed"];
}
TODO Unit tests
TODO The debug mode
TODO Build the project
The project uses gitlab-ci runners to build packages, but it is possible to build packages manually.
Building packages
If you need an hand made package, you can script available in directory.
GNU/Linux
On GNU/Linux building GNU/Linux packages is easy, you just need python in version 3.8 must be installed with venv and pyinstaller packages (see Listing /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/linux-env-deb for Debian and derived system). Finally, run the script (see Listing /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/linux-pkg).
sudo apt install python3.8
python3 -m pip install venv
python3 -m pip install pyinstaller
cd packages
./linux.sh
Windows
To make the Windows packages you have two choice: If you use Windows you can use the script , other else you can use the script . Each script need a specific software environment.
On windows, you needs python on version 3.8, pyinstaller and NSIS3 installed. On GNU/Linux you need wget, wine and winetricks installed.
TODO Setup the CI environment
Documentation files
This document and the user documentation are org files. This text file format is formatted so that it can be exported in different formats: PDF (with latex), ODT, HTML, etc. It was originally designed for the GNUEmacs4 text editor, but can be edited with any text editor. Here we take a look at the different features used in these documents.
Org-mode
Document structure
Org uses the * character to define a new document section. To add a
sub-section, you can add an additional * to the current section[fn::
See document structure documentation:
https://orgmode.org/org.html#Headlines (last access 2023-09-15)].
* Top level headline
** Second level
*** Third level
some text
*** Third level
more text
* Another top level headline
Format
Org-mode is a markup file, using markup in the text to modify the appearance of a portion of text[fn:: See markup documentation: https://orgmode.org/org.html#Emphasis-and-Monospace (last access 2023-09-15)].
| Markup | Results |
|---|---|
*Bolt* |
Bolt |
/Italic/ |
Italic |
_underline_ |
underline |
=verbatim= |
verbatim |
~code~ |
code |
+strike-through+ |
Source code blocks
You can add some code blocks[fn:: See org-mode documentation for source code: https://orgmode.org/org.html#Working-with-Source-Code (last access 2023-09-15)] in the document.
Here is an example for python source code:
#+CAPTION: Get os type name in Python code
#+begin_src python
import os
print(f"Document build on system: {os.name}")
#+end_src
If you use GNUEmacs, it is also possible to run the code inside a block and export (or not) the reuslts in the document.
import os
print(f"Document build on system: {os.name}")
Document build on system: posix
LaTeX
If we export the file to PDF, org-mode use {{{latex}}}. So we can add
some piece of {{{latex}}} into the document[fn:: See {{{latex}}} part
in documentation: https://orgmode.org/org.html#Embedded-LaTeX (last
access 2023-09-15)]. For exemple, we can add math formula like
$E=mc^2$ ($E=mc^2$) or \[E=mc^2\]:
\[E=mc^2\]
But we can also add every type of {{{latex}}}:
# Add latex in line #+LATEX: <my line of latex> # Add multiple line of LaTeX #+BEGIN_EXPORT latex <my latex here> #+END_EXPORT
It is also possible to add specific +LATEX_HEADER=. In this document we use the file for all {{{latex}}} headers.
Macro
In this document, we use a few macros[fn:: See marcos documentation
https://orgmode.org/org.html#Macro-Replacement (last access
2023-09-15)] to simplify writing. They allow you to define sequences
of text to be replaced, so that the macro name is replaced by its
value. They are defined in the
file. Once defined, they can be used in the document as follows:
{{{<macro-name>}}}. You can also have macros with arguments, in this
case: {{{<macro-name>(arg1,...)}}}. Les macros peuvent aussi
utiliser du code emacs-lisp.
# Exemple of macro définition #+MACRO: toto tata #+MACRO: add \(($1 + $2)\) #+MACRO: emacs-version (eval (nth 2 (split-string (emacs-version))))
Macro apply:
- Marco
{{{toto}}}: {{{toto}}} - Marco
{{{add(x,y)}}}: - Marco
{{{emacs-version}}}: {{{emacs-version}}}
Footnotes
Footnote in org-mode is define with marker [fn:...][fn:: Create
footnotes in org-mode documentation
https://orgmode.org/org.html#Creating-Footnotes (last access
2023-09-15)]:
The Org website[fn:1] now looks a lot better than it used to. ... [fn:1] The link is: https://orgmode.org
or:
The Org website[fn:: The link is: https://orgmode.org] now looks a lot better than it used to. ...
References
The references use the bib file is in
and use for developers and user
documentation. In document, use {{{cite(<name>)}}} to cite a paper.
Export
To export the files, a script is available in the org
files directories. On GNU/Linux system you can build the documentation
PDF file with the command ./build.sh. Texlive package must be
installed, you can install only needed packages or all texlive
packages, for example on Debian (and some derived system) use command
Listing /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/texlive-install.
sudo apt install texlive-full
Some org-mode configuration used in documentations files are define in
/doc/tools/:
- : The {{{latex}}} document class
- : Available macro
- : {{{latex}}} configutation for documentations files
- : GNUEmacs configuration to build documentations
- : Bibtex files for documentations files
How to contribute?
Pamhyr2 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License5, either version 3 of the License, or any later version.
Guidelines
To contribute to Pamhyr2, we expect a minimum of respect between contributors. We therefore ask you to respect the following rules regarding communication and contribution content:
- No gender, racial, religious or social discrimination
- No insults, personal attacks or potentially offensive remarks
- Pamhyr2 is free software, and intended to remain so, so take care with the licensing of libraries and external content you want to add to the project
- Humour or hidden easter eggs are welcome if they respect the previous rules
Make a contribution
There are several ways to contribute: you can report a bug by creating an issue on the project's gitlab page6, or you can create a merge request on the same page with the changes you have made to the code, translation or documentation.
The Pamhyr2 copyright is owned by INRAE7, but we keep a record of each contributors. If you made a modification to pamhyr2 software, please add your name at the end of file and respect the Listing /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/auth-format format. You can update this file information for following contribution.
<first name> <last name> [(optional) email], <organisation>, <years>
AUTHORS file format
Translate
You can improve or add translation for the project. To contribute to Pamhyr2 translate, you need to use Qt Linguist8. Open Qt-linguist and edite the translation () file, finally, commit the new version of file and make a merge request.
If you want add a new language, edit the script like Listing /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/ts-it. Run the script and open the new file with Qt-linguist, setup target language (Figure /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/qt-linguist-setup) and complete translation. Finally, commit the new file and make a merge request.
...
LANG="fr it"
...

Code contribution
If you are developper you can improve and/or add features to Pamhyr2. Please, follow the architecture described in section /parouby/Pamhyr2/src/commit/12011846693d451e4efdcb4d93ae726a57402a35/doc/dev/Architecture as closely as possible. Keep the code simple, clear and efficient as possible. The master branch is reserved for the project maintainer; you can create a new branch or fork the project before the request.
{{{biblio}}}
Qt Model/View documentation: https://doc.qt.io/qt-5/model-view-programming.html (last access 2023-09-15)
The org-mode website: https://orgmode.org/ (last access 2023-09-15)
The NSIS web site: https://sourceforge.net/projects/nsis/
The GNUEmacs project website: https://gnu.org/s/emacs/ (last access 2023-09-15)
The GPLv3 web page: https://www.gnu.org/licenses/gpl-3.0.en.html
The Pamhyr2 Gitlab project page: https://gitlab.irstea.fr/theophile.terraz/pamhyr
The INRAE web site: https://www.inrae.fr/
The Qt linguist documentation web page: https://doc.qt.io/qt-5/qtlinguist-index.html (last access 2023-09-18)