Differences between revisions 3 and 5 (spanning 2 versions)
Revision 3 as of 2013-08-23 16:53:37
Size: 556
Editor: TomTromey
Comment: more formatting fixes
Revision 5 as of 2021-05-07 15:31:02
Size: 1991
Editor: SimonMarchi
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
GDB follows the published {{{Python}}} coding standards in [[http://www.python.org/dev/peps/pep-0008/|PEP008]]. For everything that is not related to formatting (for that, see the Formatting section below), GDB follows the published {{{Python}}} coding standards in [[http://www.python.org/dev/peps/pep-0008/|PEP008]].
Line 5: Line 5:
In addition, the guidelines in the [[http://google-styleguide.googlecode.com/svn/trunk/pyguide.html|Google Python Style Guide]] are also followed where they do not conflict with PEP008. In addition, the guidelines in the [[https://github.com/google/styleguide/blob/gh-pages/pyguide.md|Google Python Style Guide]] are also followed where they do not conflict with PEP008.

==== Formatting ====

All Python source files under the `gdb/` directory must be formatted using the tool black, version 21.4b0. This is the latest version at the time of writing, if you notice that a more recent version is available, feel free to submit a patch to format the code with the newest version available (if that causes any differences). We can then update this page to mention the new version.

A specific version can be installed using the following steps. This example uses a virtual environment to avoid polluting the home or system directories, but obviously if you Know What You Are Doing, you don't need to.

{{{
$ python3 -m virtualenv env/
$ source env/bin/activate
(env) $ pip install 'black == 21.4b0'
(env) $ black --version
black, version 21.4b0
}}}

All you need to do to re-format files is run `black <file/directory>`. Black will re-format any Python file it finds in there. It runs quite fast, so the simplest is to do:

{{{
$ black gdb/
All done! ✨ 🍰 ✨
87 files left unchanged.
}}}

from the top-level.

If you notice that black produces changes unrelated to your patch, it's probably because someone forgot to run it before ou. In this case, don't include unrelated hunks in your patch. Push an obvious patch fixing the formatting and rebase your work on top of that.

GDB Python Coding Standards

For everything that is not related to formatting (for that, see the Formatting section below), GDB follows the published Python coding standards in PEP008.

In addition, the guidelines in the Google Python Style Guide are also followed where they do not conflict with PEP008.

Formatting

All Python source files under the gdb/ directory must be formatted using the tool black, version 21.4b0. This is the latest version at the time of writing, if you notice that a more recent version is available, feel free to submit a patch to format the code with the newest version available (if that causes any differences). We can then update this page to mention the new version.

A specific version can be installed using the following steps. This example uses a virtual environment to avoid polluting the home or system directories, but obviously if you Know What You Are Doing, you don't need to.

$ python3 -m virtualenv env/
$ source env/bin/activate
(env) $ pip install 'black == 21.4b0'
(env) $ black --version
black, version 21.4b0

All you need to do to re-format files is run black <file/directory>. Black will re-format any Python file it finds in there. It runs quite fast, so the simplest is to do:

$ black gdb/
All done! ✨ 🍰 ✨
87 files left unchanged.

from the top-level.

If you notice that black produces changes unrelated to your patch, it's probably because someone forgot to run it before ou. In this case, don't include unrelated hunks in your patch. Push an obvious patch fixing the formatting and rebase your work on top of that.

GDB-specific exceptions

There are a few exceptions to the published standards. They exist mainly for consistency with the C standards.

  • Use FIXME instead of TODO.

None: Internals GDB-Python-Coding-Standards (last edited 2022-03-18 15:53:24 by SimonMarchi)

All content (C) 2008 Free Software Foundation. For terms of use, redistribution, and modification, please see the WikiLicense page.