-
Notifications
You must be signed in to change notification settings - Fork 81
Contributing Style Guide
We write Python3.
We follow PEP8 conventions throughout all our Python code. Key principles include:
- Always use spaces for indentation. Four spaces make one tab.
- Maximum line length is 79 characters.
- Always encode source files in UTF-8.
Try to keep your imports small and only import those definitions of a module that you actually need in your script.
from django.views.generic import CreateView, TemplateView
If you, however, need many definitions from a single module it's more readable to import the module and call the definitions from the module.
Don't do:
from django.views.generic import (CreateView, TemplateView, ListView,
UpdateView, DeleteView)
Do this instead:
from django.views import generic as generic_views
(...)
generic_views.CreateView(...)
Never import *
from a module. This can significantly affect performance and might have other unwanted consequences.
Don't do this, ever:
from django.views import *
Use single quotes for symbol-like strings and double quotes for natural language messages:
MESSAGES = {
'English': "This organisation has no members.",
'German': "Diese Organisation hat keine Mitglieder."
}
Use triple-double quotes for doc strings:
def get_members(self):
"""Returns all members"""
return self.members
Make interpolated strings readable:
"{org_name} has {num_members} members.".format(
org_name="Habitat for Humanity",
num_members=10
)
Never use string concatenation—it makes internationalisation impossible.
Use the IDE or text editor you personally prefer.
The repository contains an EditorConfig file, which helps developers maintain consistent coding styles between different editors and IDEs. EditorConfig plugins are available for most editors:
Lint your code using Flake8 for potential errors before committing. Flake8 provider are available for several text editors:
- Vim: vim-flake8
- Sublime Text: SublimeLinter-flake8 (requires SublimeLinter)
- Atom: linter-flake8 (requires linter)
- Emacs: Flake8 works with flymake.
Airbnb has pulled together comprehensive ES6 and React guides that we follow for everything JavaScript.
Visit our User Documentation to learn more about using the Cadasta Platform.
If you'd like to contribute to the Cadasta Platform, start with our Contributing Guidelines.
Cadasta Wiki Home | Developer Setup Guide
Cadasta.org | About Cadasta | YouTube | Twitter | Facebook
- Installing & Running
- Contributing
- Planning & Sprints
- Platform Development
- Testing
- Utilities
- Outreachy
- Platform Site Map
- User Flows and Wireframes
- Other
- Quick Start Guide
- Glossary
- Questionnaire Guide