diff --git a/doc/Pacemaker_Development/en-US/Ch-Coding.txt b/doc/Pacemaker_Development/en-US/Ch-Coding.txt index b9e9caf360..2e6d0eb010 100644 --- a/doc/Pacemaker_Development/en-US/Ch-Coding.txt +++ b/doc/Pacemaker_Development/en-US/Ch-Coding.txt @@ -1,296 +1,286 @@ :compat-mode: legacy = C Coding Guidelines = //// We prefer [[ch-NAME]], but older versions of asciidoc don't deal well with that construct for chapter headings //// -anchor:ch-c-coding[Chapter 2, C Coding Guidelines] +anchor:ch-c-coding[Chapter 3, C Coding Guidelines] == Style Guidelines == Pacemaker is a large, distributed project accepting contributions from developers with a wide range of skill levels and organizational affiliations, and maintained by multiple people over long periods of time. The guidelines in this section are not technically better than alternative approaches, but make project management easier. Many of these simply ensure stylistic consistency, which makes reading, writing, and reviewing code easier. === C Boilerplate === indexterm:[C,boilerplate] indexterm:[licensing,C boilerplate] -Every C file should start with a short copyright notice listing the original -author, like: +Every C file should start with a short copyright notice: ==== [source,C] ---- /* - * Copyright Andrew Beekhof + * Copyright the Pacemaker project contributors * + * The version control history for this file may have further details. + * * This source code is licensed under WITHOUT ANY WARRANTY. */ ---- ==== -The first ++ is the year the code was 'originally' created. -footnote:[ -See the U.S. Copyright Office's https://www.copyright.gov/comp3/["Compendium -of U.S. Copyright Office Practices"], particularly "Chapter 2200: Notice of -Copyright", sections 2205.1(A) and 2205.1(F), or -https://techwhirl.com/updating-copyright-notices/["Updating Copyright -Notices"] for a more readable summary. -] -If the code is modified in later years, add +-YYYY+ with the most recent year -of modification. - ++ should follow the policy set forth in the https://github.com/ClusterLabs/pacemaker/blob/master/COPYING[+COPYING+] file, generally one of "GNU General Public License version 2 or later (GPLv2+)" or "GNU Lesser General Public License version 2.1 or later (LGPLv2.1+)". Header files should additionally protect against multiple inclusion by defining a unique symbol. ==== [source,C] ---- #ifndef MY_HEADER_NAME__H # define MY_HEADER_NAME__H // header code here #endif // MY_HEADER_NAME__H ---- ==== Public API header files should additionally declare "C" compatibility for inclusion by C++, and give a Doxygen file description. For example: ==== [source,C] ---- #ifdef __cplusplus extern "C" { #endif /*! * \file * \brief My brief description here * \ingroup core */ // header code here #ifdef __cplusplus } #endif ---- ==== === Line Formatting === indexterm:[C,whitespace] - Indentation must be 4 spaces, no tabs. - Do not leave trailing whitespace. - Lines should be no longer than 80 characters unless limiting line length significantly impacts readability. === Pointers === indexterm:[C,pointers] - The +*+ goes by the variable name, not the type: ==== [source,C] ---- char *foo; ---- ==== - Use a space before the +*+ and after the closing parenthesis in a cast: ==== [source,C] ---- char *foo = (char *) bar; ---- ==== === Function Definitions === indexterm:[C,functions] - In the function definition, put the return type on its own line, and place the opening brace by itself on a line. - For functions with enough arguments that they must break to the next line, align arguments with the first argument. - When a function argument is a function itself, use the pointer form. ==== [source,C] ---- static int function_name(int bar, const char *a, const char *b, const char *c, void (*d)()) { ---- ==== - If a function name gets really long, start the arguments on their own line with 8 spaces of indentation: ==== [source,C] ---- static int really_really_long_function_name_this_is_getting_silly_now( int bar, const char *a, const char *b, const char *c, const char *d) { ---- ==== === Control Statements (if, else, while, for, switch) === - The keyword is followed by one space, then left parenthesis without space, condition, right parenthesis, space, opening bracket on the same line. +else+ and +else if+ are on the same line with the ending brace and opening brace, separated by a space. - Always use braces around control statement blocks, even if they only contain one line. This makes code review diffs smaller if a line gets added in the future, and avoids any chance of bad indenting making a line incorrectly appear to be part of the block. - Do not put assignments in +if+ or +while+ conditionals. This ensures that the developer's intent is always clear, making code reviews easier and reducing the chance of using assignment where comparison is intended. ==== [source,C] ---- a = f(); if (a < 0) { statement1; } else if (some_other_condition) { statement2; } else { statement3; } ---- ==== - In a +switch+ statement, +case+ is indented one level, and the body of each +case+ is indented by another level. The opening brace is on the same line as +switch+. ==== [source,C] ---- switch (expression) { case 0: command1; break; case 1: command2; break; default: command3; } ---- ==== === Operators === indexterm:[C,operators] - Operators have spaces from both sides. - Do not rely on operator precedence; use parentheses when mixing operators with different priority. - No space is used after opening parenthesis and before closing parenthesis. ==== [source,C] ---- x = a + b - (c * d); ---- ==== == Best Practices == The guidelines in this section offer technical advantages. === New Struct and Enum Members === In the public APIs, always add new struct members to the end of the struct. This allows us to maintain backward API/ABI compatibility (as long as the application being linked allocates structs via API functions). This generally applies to enum values as well, as the compiler will define enum values to 0, 1, etc., in the order given, so inserting a value in the middle will change the numerical values of all later values, making them backward-incompatible. However, if enum numerical values are explicitly specified rather than left to the compiler, new values can be added anywhere. === Documentation === All public API header files, functions, structs, enums, etc., should be documented with Doxygen comment blocks, as Pacemaker's http://clusterlabs.org/pacemaker/doxygen/[online API documentation] is automatically generated via Doxygen. It is helpful to document private symbols in the same way, with an +\internal+ tag in the Doxygen comment. === Symbol Naming === indexterm:[C,naming] - All file and function names should be unique across the entire project, to allow for individual tracing via +PCMK_trace_files+ and +PCMK_trace_functions+, as well as making detail logs easier to follow. - Any exposed symbols in libraries (non-+static+ function names, type names, etc.) must begin with a prefix appropriate to the library, for example, +crm_+, +pe_+, +st_+, +lrm_+. This reduces the chance of naming collisions with software linked against the library. - Time intervals are sometimes represented in Pacemaker code as user-defined text specifications (e.g. "10s"), other times as an integer number of seconds or milliseconds, and still other times as a string representation of an integer number. Variables for these should be named with an indication of which is being used (e.g. +interval_spec+, +interval_ms+, or +interval_ms_s+ instead of +interval+). === Memory Allocation === Always use calloc() rather than malloc(). It has no additional cost on modern operating systems, and reduces the severity of uninitialized memory usage bugs. === Logging === - When format strings are used for derived data types whose implementation may vary across platforms (+pid_t+, +time_t+, etc.), the safest approach is to use +%lld+ in the format string, and cast the value to +(long long)+. === Regular Expressions === - Use +REG_NOSUB+ with +regcomp()+ whenever possible, for efficiency. - Be sure to use +regfree()+ appropriately. === vim Settings === indexterm:[vim] Developers who use +vim+ to edit source code can add the following settings to their +~/.vimrc+ file to follow Pacemaker C coding guidelines: ---- " follow Pacemaker coding guidelines when editing C source code files filetype plugin indent on au FileType c setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80 autocmd BufNewFile,BufRead *.h set filetype=c let c_space_errors = 1 ---- diff --git a/doc/Pacemaker_Development/en-US/Ch-Evolution.txt b/doc/Pacemaker_Development/en-US/Ch-Evolution.txt index af3f151df2..4c1e657729 100644 --- a/doc/Pacemaker_Development/en-US/Ch-Evolution.txt +++ b/doc/Pacemaker_Development/en-US/Ch-Evolution.txt @@ -1,104 +1,104 @@ :compat-mode: legacy = Evolution of the project = -anchor:ch-evolution[Chapter 3. Evolution] +anchor:ch-evolution[Chapter 5. Evolution] == Foreword == This chapter is currently not meant as a definite summary of how Pacemaker got into where it stands now, but rather to provide few valuable pointers an entusiasts (presumably software archeologist type of person) may find useful. Moreover, well-intentioned contributors to Pacemaker project may want to review them occasionally since, as the famous quote has it, "those who do not learn history are doomed to repeat it". For anything more talkative with less emphasis on actual code, other places will serve better for the time being (and if not, should not be too hard to volunteer extensions to those writeups): * https://wiki.clusterlabs.org/wiki/Pacemaker[main entry at ClusterLabs community wiki] * https://en.wikipedia.org/wiki/Pacemaker_(software)[entry at wikipedia.org] * https://www.alteeve.com/w/AN!Cluster_Tutorial_2#What_about_Pacemaker.3F[ brief section dedicated to Pacemaker in Digimer's tutorial regarding setting up the cluster with the old Red Hat Cluster Suite like stack] == Common ancestor: 'heartbeat' project == Pacemaker can be considered as a spin-off from `heartbeat', original comprehensive HA suite started by Alan Robertson, and some portions of code are shared, at least on the conceptual level if not verbatim, till today, even if the effective percentage continually declines. Note that till Pacemaker 2.0, it also used to stand for one (and initially the only) of supported messaging back-ends (removal of this support made for one such notable drop of reused code), see also https://github.com/ClusterLabs/pacemaker/commit/55ab749bf0f0143bd1cd050c1bbe302aecb3898e[ pre-2.0 commit 55ab749bf]. The codebase for heartbeat used to be hosted at http://hg.linux-ha.org, but since that does not appear reliably available recently, an archive checkout from 2016 is shared at https://gitlab.com/poki/archived-heartbeat[ as a dedicated read-only repository], and anchored there, the most notable commits are: * https://gitlab.com/poki/archived-heartbeat/commit/bb48551be418291c46980511aa31c7c2df3a85e4[ initial check-in of what turned up to be the basis for Pacemaker later on] * https://gitlab.com/poki/archived-heartbeat/commit/74573ac6182785820d765ec76c5d70086381931a[ drop of now-detached Pacemaker code] Regarding the Pacemaker's split from heartbeat, it evolved stepwise (as opposed to one-off cut), and the last step of full dependency is depicted in https://www.kernel.org/doc/ols/2008/ols2008v1-pages-85-100.pdf#page=14[ The Corosync Cluster Engine] paper, fig. 10. This article also provides a good reference regarding wider historical context of the tangentially (and deeper in some cases) meeting components around that time. === Influence of 'heartbeat' on Pacemaker === On a closer look, we can identify these things in common: * extensive use of data types and functions of https://wiki.gnome.org/Projects/GLib[GLib] * Cluster Testing System (CTS) is inherited from initial implementation by Alan Robertson * ... == Notable Restructuring Steps in the Codebase == File renames may not appear as notable ... unless one runs into complicated +git blame+ and +git log+ scenarios, so some more massive ones may be stated as well. * watchdog/'sbd' functionality spin-off: ** https://github.com/ClusterLabs/pacemaker/commit/eb7cce2a172a026336f4ba6c441dedce42f41092[ start separating, eb7cce2a1] ** https://github.com/ClusterLabs/pacemaker/commit/5884db78080941cdc4e77499bc76677676729484[ finish separating, 5884db780] * daemons' rename for 2.0 (in chronological order) ** https://github.com/ClusterLabs/pacemaker/commit/318a2e003d2369caf10a450fe7a7616eb7ffb264[ start of moving daemon sources from their top-level directories under new +/daemons+ hierarchy, 318a2e003] ** https://github.com/ClusterLabs/pacemaker/commit/01563cf2637040e9d725b777f0c42efa8ab075c7[ +attrd+ -> +pacemaker-attrd+, 01563cf26] ** https://github.com/ClusterLabs/pacemaker/commit/36a00e2376fd50d52c2ccc49483e235a974b161c[ +lrmd+ -> +pacemaker-execd+, 36a00e237] ** https://github.com/ClusterLabs/pacemaker/commit/e4f4a0d64c8b6bbc4961810f2a41383f52eaa116[ +pacemaker_remoted+ -> +pacemaker-remoted+, e4f4a0d64] ** https://github.com/ClusterLabs/pacemaker/commit/db5536e40c77cdfdf1011b837f18e4ad9df45442[ +crmd+ -> +pacemaker-controld+, db5536e40] ** https://github.com/ClusterLabs/pacemaker/commit/e2fdc2baccc3ae07652aac622a83f317597608cd[ +pengine+ -> +pacemaker-schedulerd+, e2fdc2bac] ** https://github.com/ClusterLabs/pacemaker/commit/038c465e2380c5349fb30ea96c8a7eb6184452e0[ +stonithd+ -> +pacemaker-fenced+, 038c465e2] ** https://github.com/ClusterLabs/pacemaker/commit/50584c234e48cd8b99d355ca9349b0dfb9503987[ +cib daemon+ -> +pacemaker-based+, 50584c234] //// TBD: - standalone tengine -> part of crmd/pacemaker-controld //// diff --git a/doc/Pacemaker_Development/en-US/Ch-FAQ.txt b/doc/Pacemaker_Development/en-US/Ch-FAQ.txt index 78f14e45a5..a5d448206a 100644 --- a/doc/Pacemaker_Development/en-US/Ch-FAQ.txt +++ b/doc/Pacemaker_Development/en-US/Ch-FAQ.txt @@ -1,119 +1,121 @@ :compat-mode: legacy = Frequently Asked Questions = [qanda] Who is this document intended for?:: Anyone who wishes to read and/or edit the Pacemaker source code. Casual contributors should feel free to read just this FAQ, and consult other chapters as needed. Where is the source code for Pacemaker?:: indexterm:[downloads] indexterm:[source code] indexterm:[git,GitHub] The https://github.com/ClusterLabs/pacemaker[source code for Pacemaker] is kept on https://github.com/[GitHub], as are all software projects under the https://github.com/ClusterLabs[ClusterLabs] umbrella. Pacemaker uses https://git-scm.com/[Git] for source code management. If you are a Git newbie, the http://schacon.github.io/git/gittutorial.html[gittutorial(7) man page] is an excellent starting point. If you're familiar with using Git from the command line, you can create a local copy of the Pacemaker source code with: `git clone https://github.com/ClusterLabs/pacemaker.git` What are the different Git branches and repositories used for?:: indexterm:[branches] * The https://github.com/ClusterLabs/pacemaker/tree/master[master branch] is the primary branch used for development. * The https://github.com/ClusterLabs/pacemaker/tree/2.0[2.0 branch] contains the latest official release, and normally does not receive any changes. During the release cycle, it will contain release candidates for the next official release, and will receive only bug fixes. * The https://github.com/ClusterLabs/pacemaker/tree/1.1[1.1 branch] is similar to both the master and 2.0 branches, but for the 1.1 release series. The 1.1 branch receives only backports of certain bug fixes and backward-compatible features from the master branch. During the release cycle, it will contain release candidates for the next official 1.1 release. * The https://github.com/ClusterLabs/pacemaker-1.0[1.0 repository] is a frozen snapshot of the 1.0 release series, and is no longer developed. * Messages will be posted to the http://clusterlabs.org/mailman/listinfo/developers[developers@clusterlabs.org] mailing list during the release cycle, with instructions about which branches to use when submitting requests. How do I build from the source code?:: See https://github.com/ClusterLabs/pacemaker/blob/master/INSTALL.md[INSTALL.md] in the main checkout directory. What coding style should I follow?:: You'll be mostly fine if you simply follow the example of existing code. When unsure, see the relevant chapter of this document for language-specific recommendations. Pacemaker has grown and evolved organically over many years, so you will see much code that doesn't conform to the current guidelines. We discourage making changes solely to bring code into conformance, as any change requires developer time for review and opens the possibility of adding bugs. However, new code should follow the guidelines, and it is fine to bring lines of older code into conformance when modifying that code for other reasons. How should I format my Git commit messages?:: indexterm:[git,commit messages] See existing examples in the git log. The first line should look like +change-type: affected-code: explanation+ where +change-type+ should be +Fix+ or +Bug+ for most bug fixes, +Feature+ for new features, +Log+ for changes to log messages or handling, +Doc+ for changes to documentation or comments, or +Test+ for changes in CTS and regression tests. You will sometimes see +Low+, +Med+ (or +Mid+) and +High+ used instead for bug fixes, to indicate the severity. The important thing is that only commits with +Feature+, +Fix+, +Bug+, or +High+ will automatically be included in the change log for the next release. The +affected-code+ is the name of the component(s) being changed, for example, +controller+ or +libcrmcommon+ (it's more free-form, so don't sweat getting it exact). The +explanation+ briefly describes the change. The git project recommends the entire summary line stay under 50 characters, but more is fine if needed for clarity. Except for the most simple and obvious of changes, the summary should be followed by a blank line and then a longer explanation of 'why' the change was made. How can I test my changes?:: Most importantly, Pacemaker has regression tests for most major components; these will automatically be run for any pull requests submitted through GitHub. Additionally, Pacemaker's Cluster Test Suite (CTS) can be used to set up a test cluster and run a wide variety of complex tests. This document will have more detail on testing in the future. What is Pacemaker's license?:: indexterm:[licensing] Except where noted otherwise in the file itself, the source code for all Pacemaker programs is licensed under version 2 or later of the GNU General Public License (https://www.gnu.org/licenses/gpl-2.0.html[GPLv2+]), its headers and libraries under version 2.1 or later of the less restrictive GNU Lesser General Public License (https://www.gnu.org/licenses/lgpl-2.1.html[LGPLv2.1+]), its documentation under version 4.0 or later of the Creative Commons Attribution-ShareAlike International Public License (https://creativecommons.org/licenses/by-sa/4.0/legalcode[CC-BY-SA-4.0]), and its init scripts under the https://opensource.org/licenses/BSD-3-Clause[Revised BSD] license. If you find any deviations from this policy, or wish to inquire about alternate licensing arrangements, please e-mail the mailto:developers@clusterlabs.org[developers@ClusterLabs.org] mailing list. Licensing issues are also discussed on the https://wiki.clusterlabs.org/wiki/License[ClusterLabs wiki]. How can I contribute my changes to the project?:: Contributions of bug fixes or new features are very much appreciated! Patches can be submitted as https://help.github.com/articles/using-pull-requests/[pull requests] via GitHub (the preferred method, due to its excellent https://github.com/features/[features]), or e-mailed to the http://clusterlabs.org/mailman/listinfo/developers[developers@clusterlabs.org] - mailing list as an attachment in a format Git can import. + mailing list as an attachment in a format Git can import. Authors may only + submit changes that they have the right to submit under the open source + license indicated in the affected files. What if I still have questions?:: indexterm:[mailing lists] Ask on the http://clusterlabs.org/mailman/listinfo/developers[developers@clusterlabs.org] mailing list for development-related questions, or on the http://clusterlabs.org/mailman/listinfo/users[users@clusterlabs.org] mailing list for general questions about using Pacemaker. Developers often also hang out on http://freenode.net/[freenode's] #clusterlabs IRC channel. diff --git a/doc/Pacemaker_Development/en-US/Ch-General.txt b/doc/Pacemaker_Development/en-US/Ch-General.txt new file mode 100644 index 0000000000..65362c23d8 --- /dev/null +++ b/doc/Pacemaker_Development/en-US/Ch-General.txt @@ -0,0 +1,33 @@ +:compat-mode: legacy += General Guidelines for All Languages = + +== Copyright == + +indexterm:[copyright] + +When copyright notices are added to a file, they should look like this: +==== +Copyright the Pacemaker project contributors + +The version control history for this file may have further details. +==== + +The first ++ is the year the file was originally published. The original +date is important for two reasons: when two entities claim copyright ownership +of the same work, the earlier claim generally prevails; and copyright +expiration is generally calculated from the original publication date. +footnote:[ +See the U.S. Copyright Office's https://www.copyright.gov/comp3/["Compendium +of U.S. Copyright Office Practices"], particularly "Chapter 2200: Notice of +Copyright", sections 2205.1(A) and 2205.1(F), or +https://techwhirl.com/updating-copyright-notices/["Updating Copyright +Notices"] for a more readable summary. +] + +If the file is modified in later years, add +-YYYY+ with the most recent year +of modification. Even though Pacemaker is an ongoing project, copyright notices +are about the years of 'publication' of specific content. + +Copyright notices are intended to indicate, but do not affect, copyright +'ownership', which is determined by applicable laws and regulations. Authors +may put more specific copyright notices in their commit messages if desired. diff --git a/doc/Pacemaker_Development/en-US/Ch-Python.txt b/doc/Pacemaker_Development/en-US/Ch-Python.txt index bd450fc3c6..42d35b649b 100644 --- a/doc/Pacemaker_Development/en-US/Ch-Python.txt +++ b/doc/Pacemaker_Development/en-US/Ch-Python.txt @@ -1,155 +1,141 @@ :compat-mode: legacy = Python Coding Guidelines = //// We prefer [[ch-NAME]], but older versions of asciidoc don't deal well with that construct for chapter headings //// -anchor:ch-python-coding[Chapter 3, Python Coding Guidelines] +anchor:ch-python-coding[Chapter 4, Python Coding Guidelines] [[s-python-boilerplate]] == Python Boilerplate == indexterm:[Python,boilerplate] indexterm:[licensing,Python boilerplate] If a Python file is meant to be executed (as opposed to imported), it should have a +.in+ extension, and its first line should be: ==== ---- #!@PYTHON@ ---- ==== which will be replaced with the appropriate python executable when Pacemaker is built. To make that happen, add an AC_CONFIG_FILES() line to configure.ac, and add the file name without .in to .gitignore (see existing examples). After the above line if any, every Python file should start like this: ==== [source,Python] ---- """ """ # Pacemaker targets compatibility with Python 2.7 and 3.2+ from __future__ import print_function, unicode_literals, absolute_import, division -__copyright__ = "Copyright Andrew Beekhof " +__copyright__ = "Copyright the Pacemaker project contributors" __license__ = " WITHOUT ANY WARRANTY" ---- ==== -If the file is meant to be directly executed, the first line (++) -should be +#!/usr/bin/python+. If it is meant to be imported, omit this line. - ++ is obviously a brief description of the file's purpose. The string may contain any other information typically used in a Python file https://www.python.org/dev/peps/pep-0257/[docstring]. The +import+ statement is discussed further in <>. -++ is the year the code was 'originally' created. -footnote:[ -See the U.S. Copyright Office's https://www.copyright.gov/comp3/["Compendium -of U.S. Copyright Office Practices"], particularly "Chapter 2200: Notice of -Copyright", sections 2205.1(A) and 2205.1(F), or -https://techwhirl.com/updating-copyright-notices/["Updating Copyright -Notices"] for a more readable summary. -] -If the code is modified in later years, add +-YYYY+ with the most recent year -of modification. - ++ should follow the policy set forth in the https://github.com/ClusterLabs/pacemaker/blob/master/COPYING[+COPYING+] file, generally one of "GNU General Public License version 2 or later (GPLv2+)" or "GNU Lesser General Public License version 2.1 or later (LGPLv2.1+)". == Python Compatibility == indexterm:[Python,2] indexterm:[Python,3] indexterm:[Python,versions] Pacemaker targets compatibility with Python 2.7, and Python 3.2 and later. These versions have added features to be more compatible with each other, allowing us to support both the 2 and 3 series with the same code. It is a good idea to test any changes with both Python 2 and 3. [[s-python-future-imports]] === Python Future Imports === The future imports used in <> mean: * All print statements must use parentheses, and printing without a newline is accomplished with the +end=' '+ parameter rather than a trailing comma. * All string literals will be treated as Unicode (the +u+ prefix is unnecessary, and must not be used, because it is not available in Python 3.2). * Local modules must be imported using +from . import+ (rather than just +import+). To import one item from a local module, use +from .modulename import+ (rather than +from modulename import+). * Division using +/+ will always return a floating-point result (use +//+ if you want the integer floor instead). === Other Python Compatibility Requirements === * When specifying an exception variable, always use +as+ instead of a comma (e.g. +except Exception as e+ or +except (TypeError, IOError) as e+). Use +e.args+ to access the error arguments (instead of iterating over or subscripting +e+). * Use +in+ (not +has_key()+) to determine if a dictionary has a particular key. * Always use the I/O functions from the +io+ module rather than the native I/O functions (e.g. +io.open()+ rather than +open()+). * When opening a file, always use the +t+ (text) or +b+ (binary) mode flag. * When creating classes, always specify a parent class to ensure that it is a "new-style" class (e.g. +class Foo(object):+ rather than +class Foo:+) * Be aware of the bytes type added in Python 3. Many places where strings are used in Python 2 use bytes or bytearrays in Python 3 (for example, the pipes used with +subprocess.Popen()+). Code should handle both possibilities. * Be aware that the +items()+, +keys()+, and +values()+ methods of dictionaries return lists in Python 2 and views in Python 3. In many case, no special handling is required, but if the code needs to use list methods on the result, cast the result to list first. * Do not raise or catch strings as exceptions (e.g. +raise "Bad thing"+). * Do not use the +cmp+ parameter of sorting functions (use +key+ instead, if needed) or the +$$__cmp__()$$+ method of classes (implement rich comparison methods such as +$$__lt__()$$+ instead, if needed). * Do not use the +buffer+ type. * Do not use features not available in all targeted Python versions. Common examples include: ** The +html+, +ipaddress+, and +UserDict+ modules ** The +subprocess.run()+ function ** The +subprocess.DEVNULL+ constant ** +subprocess+ module-specific exceptions === Python Usages to Avoid === Avoid the following if possible, otherwise research the compatibility issues involved (hacky workarounds are often available): * long integers * octal integer literals * mixed binary and string data in one data file or variable * metaclasses * +locale.strcoll+ and +locale.strxfrm+ * the +configparser+ and +ConfigParser+ modules * importing compatibility modules such as +six+ (so we don't have to add them to Pacemaker's dependencies) == Formatting Python Code == indexterm:[Python,formatting] * Indentation must be 4 spaces, no tabs. * Do not leave trailing whitespace. * Lines should be no longer than 80 characters unless limiting line length significantly impacts readability. For Python, this limitation is flexible since breaking a line often impacts readability, but definitely keep it under 120 characters. * Where not conflicting with this style guide, it is recommended (but not required) to follow https://www.python.org/dev/peps/pep-0008/[PEP 8]. * It is recommended (but not required) to format Python code such that `pylint --disable=line-too-long,too-many-lines,too-many-instance-attributes,too-many-arguments,too-many-statements` produces minimal complaints (even better if you don't need to disable all those checks). diff --git a/doc/Pacemaker_Development/en-US/Pacemaker_Development.xml b/doc/Pacemaker_Development/en-US/Pacemaker_Development.xml index 288d667bf2..c02d705c90 100644 --- a/doc/Pacemaker_Development/en-US/Pacemaker_Development.xml +++ b/doc/Pacemaker_Development/en-US/Pacemaker_Development.xml @@ -1,14 +1,15 @@ %BOOK_ENTITIES; ]> +