Thanks for contributing to OpenFMS!💜 Here's a couple of guidelines that you should keep in mind.
We use tools such as autoformatter (fprettify) and linter (fortitude)
to keep our code nice and tidy. Instead of having the developer to
install these and run them manually, we use a tool called prek
which does this automatically on every commit.
To install prek and the configargparse dependency (needed for fprettify) run:
pip install --user prek configargparseThen you must run the following in the repository to install prek's pre-commit hook:
prek install
From now on, prek will execute hooks defined in .pre-commit-config.yaml before every commit.
You can also run the hooks manually at any point:
❯ prek run -a
don't commit to branch.................................Passed
check yaml.............................................Passed
check for added large files............................Passed
check for merge conflicts..............................Passed
check that executables have shebangs...................Passed
fortitude..............................................Passed
Check module usage.....................................Passed
Autoformat code........................................Passed
To run only autoformatter
❯ prek run -a format
Autoformat code........................................Passed
See prek documentation for more details.
Here's a quick summary of our code style that we try to adhere to (especially in new code):
- use
implicit noneeverywhere, no exceptions! This is enforced by the compiler in CI. - each function/subroutine argument should have the intent attribute.
- use
real(DefReal)for real numbers,integer(DefInt)for integers and complex(DefComp) for complex numbers. TheDefXXXconstants indicating the kind (precision) are defined inGlobalModule. - variables and subroutines in modules should be private by default, use
privateattribute,e.g.
module mod_my_module
private
integer :: public_var
integer :: private_var
public :: public_var
public :: public_subroutine
contains
subroutine public_subroutine
...
end subroutine public_subroutine
end module mod_my_moduleCode formatting is enforced using fprettify formatter,
and you don't need to think about it for the most part.
Here's a quick summary of our formatting style, as it is defined in .fprettify.rc config file.
- use 3 spaces for indentation, no tabs.
- use C-style relational operators (
< > == /=) instead of the old FORTRAN style (.gt. .lt.) - comments should start at the same indentation level as the code they are commenting.
- use an exclamation mark to start a comment
Last but not least, to get your code merged to the main repository, please open a Pull Request (PR) on Github. If you're not familiar with Pull Requests, take a look here.
To ignore bulk insignificant changes in git blame history (e.g. whitespace changes),
configure git blame to ignore commits specified in .git-blame-ignore-revs file.
git config blame.ignoreRevsFile .git-blame-ignore-revsThis is done automatically in GitHub UI.