The Ion code base generally follows the guidelines as set forth by PEP8.
- Indent using 4 spaces.
- Use underscores in favor of camel case for all names except the names of classes.
- Limit all lines to a maximum of 79 characters.
- Limit the line length of docstrings or comments to 72 characters.
- Separate top-level functions and class definitions with two blank lines.
- Separate method definitions inside a class with a single blank line.
- Use two spaces before inline comment and one space between the pound sign and comment/
- Use a plugin for your text editor to check for/remind you of PEP8 conventions.
- Capitalize and punctuate comments and git commit messages properly.
- Group imports in the following order:
- Standard library imports
- Imports from core Django
- Related third-party imports
- Local application or library specific imports, imports from Django apps
- Avoid using
import *
- Explicitly import each module used
Standard library imports:
from math import sqrt
from os.path import abspath
Core Django imports:
from django.db import models
Third-party app imports
from django_extensions.db.models import TimeStampedModel
Imports from your apps
from intranet.models import User
Explicit relative imports:
Used to avoid hardcoding a module's package. This greatly improves portability. Use these when importing from another module in the current app.
Absolute imports:
Used when importing outside the current app.
Implicit relative imports:
Don't use these. Using them makes it very difficult to change the name of the app, reducing portability.
Good:
from .models import SomeModel # explicit relative import
from otherdjangoapp.models import OtherModel # absolute import
Bad:
from currentapp.models import MyModel # implicit relative import