Skip to content

Coding style

Dominik Gresch edited this page Apr 27, 2020 · 3 revisions

If you follow the instructions to set up your development environment, the AiiDA coding style is largely enforced automatically using pre-commit hooks.

This document mainly acts as a reference.

AiiDA Coding Style

AiiDA-specific conventions

  • Opening files:
    • When opening a general file for reading or writing, use open, and specify UTF-8 encoding for formatted files (e.g. open(path, 'w', encoding='utf8')).
    • When opening a file from the AiiDA repository, use aiida.common.folders.Folder.open().

Source file headers

Each source file should start with a common header (will be added automatically by helper scripts that are run just before a new release):

  1. Optional she-bang line e.g. #!/usr/bin/env python
  2. Coding declaration conforming to PEP 263: e.g. # -*- coding: utf-8 -*-
  3. A copyright header defined below
  4. Linter directives e.g. # pylint: disable=too-many-arguments
  5. Module docstrings

The copyright header is currently defined to be:

###########################################################################
# Copyright (c), The AiiDA team. All rights reserved.                     #
# This file is part of the AiiDA code.                                    #
#                                                                         #
# The code is hosted on GitHub at https://github.com/aiidateam/aiida_core #
# For further information on the license, see the LICENSE.txt file        #
# For further information please visit http://www.aiida.net               #
###########################################################################