Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

enforce code order in Python #1775

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ a.out
/test/fixtures/symlink-to-tmp
/test/force-auto
/test/make-perms-test
/test/order-py
/test/sotest/*.so*
/test/sotest/sotest
/test/sotest/bin/
Expand Down
68 changes: 67 additions & 1 deletion doc/dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,72 @@ Variable conventions in shell scripts and :code:`.bats` files
foo=${bar}/baz # yes
foo="${bar}/baz" # no

Statement ordering within source files
--------------------------------------

In general, we order things alphabetically.

Python
~~~~~~

The module as a whole, and each class, comprise a sequence of ordering units
separated by section header comments surrounded by two or more hashes, e.g.
:code:`## Globals ##`. Sections with the following names must be in this order
(omissions are fine). Other section names may appear in any order. There is
also an unnamed zeroth section.

#. Enums
#. Constants
#. Globals
#. Exceptions
#. Main
#. Functions
#. Supporting classes
#. Core classes
#. Classes

Within each section, statements occur in the following order.

#. imports

#. standard library
#. external imports not in the standard library
#. :code:`import charliecloud`
#. other Charliecloud imports

#. assignments

#. class definitions

#. function definitions

#. :code:`__init__`
#. static methods
#. class methods
#. other double-underscore methods (e.g. :code:`__str__`)
#. properties
#. “normal” functions (instance methods)

Within each group of statements above, identifiers must occur in alphabetical
order. Exceptions:

#. Classes must appear after their base class.
#. Assignments may appear in any order.

Statement types not listed above may appear in any order.

A statement that must be out of order is exempted with a comment on its first
line containing 👻, because a ghost says “OOO”, i.e. “out of order”.

Python code
-----------

Indentation width
~~~~~~~~~~~~~~~~~

3 spaces per level. No tab characters.


C code
------

Expand Down Expand Up @@ -1519,4 +1585,4 @@ What to do in each location should either be obvious or commented.

.. LocalWords: milestoned gh nv cht Chacon’s scottchacon mis cantfix tmpimg
.. LocalWords: rootfs cbd cae ce bafb bc weirdal yankovic nop cb fbe adb fd
.. LocalWords: abd bbf LOGFILE logfile rtd
.. LocalWords: abd bbf LOGFILE logfile rtd Enums
Loading