Changes

From Gramps

Programming guidelines

65 bytes added, 03:57, 7 November 2024
Clarify that pylint is not enforced by CI, while still encouraging its use. Remove parentheses for simplicity and emphasis.
=== Tabs ===
* Do not use TABs. Use space characters. In Gramps we use 4 spaces for indentation. This does not mean you must set your TAB stops to 4. TABs and indents are not the same thing. Most editors have a configuration option to set indentation and TAB stops. Be careful to just set the '''indentation''' to 4, which automatically means it has to be '''spaces'''. (TABs are still necessary, in Makefiles for example, and they '''have to''' be equivalent to 8 spaces, '''always'''.) To summarize:
** uses spaces, no TABs
** indentation is 4
== Docstrings ==
* Python provides a docstrings to document classes and functions. If the class is a class used by others (such as the [http://www.gramps-project.org/docs/gen/gen_lib.html#module-gen.lib gen lib] classes), the docstrings should follow the restructuredtext ([http://docutils.sourceforge.net/docs/user/rst/quickstart.html#structure rst]) format. This allows us to extract [http://www.gramps-project.org/docs/ API] documentation [[Devhelp#See_also|using Sphinx]]. (Sphinx is , a documentation generator for Python code).
* Aside from adding doc strings to classes and functions, also the api generating rst files must be edited so as to extract the documentation. These files are in the [https://github.com/gramps-project/gramps/tree/master/docs docs directory], for info read the [https://github.com/gramps-project/gramps/blob/master/docs/README.txt /docs/README.txt] file.
== Pylint ==
* Run <code>pylint</code> on your code before checking in.
* New files shall have a Pylint score of 9 or higher. New files will , but not be accepted if they have a Pylint score lower than 9enforced by CI tools as Black formatting is.
* Any changes to existing files with a Pylint score lower than 9 shall not reduce the Pylint score. It is expected that over time, this policy will cause all files to eventually have a score of 9 or higher.
Note that you must run <code>pylint</code> in the <code>gramps</code> directory. If import errors still occur, add a PYTHONPATH. Example usage:
me@laptop:~/programs/master/src$ PYTHONPATH=plugins/lib/ pylint --include-ids=y --reports=y plugins/mapservices/googlemap.py
Set reports to '''n''' to have less output. Information on the meaning of codes can be found here:
* [http://pylint-messages.wikidot.com/all-codes All codes, PyLint 1.1.0] Messages: and what they're trying to tell you
== Best practices ==
* Maintain good code hygiene by following coding guidelines and running code analysis and formatting tools locally
 
* Always develop with [[Coding_for_translation|language translation]] in mind
56
edits

Navigation menu