| 1 |
# HOPE 8 -- Style Guide for Hug Code |
| 2 |
|
| 3 |
| | | |
| 4 |
|------------|---------------------------------------------| |
| 5 |
| HOPE: | 8 | |
| 6 |
| Title: | Style Guide for Hug Code | |
| 7 |
| Author(s): | Timothy Crosley <[email protected]> | |
| 8 |
| Status: | Active | |
| 9 |
| Type: | Process | |
| 10 |
| Created: | 19-May-2019 | |
| 11 |
| Updated: | 17-August-2019 | |
| 12 |
|
| 13 |
## Introduction |
| 14 |
|
| 15 |
This document gives coding conventions for the Hug code comprising the Hug core as well as all official interfaces, extensions, and plugins for the framework. |
| 16 |
Optionally, projects that use Hug are encouraged to follow this HOPE and link to it as a reference. |
| 17 |
|
| 18 |
## PEP 8 Foundation |
| 19 |
|
| 20 |
All guidelines in this document are in addition to those defined in Python's [PEP 8](https://www.python.org/dev/peps/pep-0008/) and [PEP 257](https://www.python.org/dev/peps/pep-0257/) guidelines. |
| 21 |
|
| 22 |
## Line Length |
| 23 |
|
| 24 |
Too short of lines discourage descriptive variable names where they otherwise make sense. |
| 25 |
Too long of lines reduce overall readability and make it hard to compare 2 files side by side. |
| 26 |
There is no perfect number: but for Hug, we've decided to cap the lines at 100 characters. |
| 27 |
|
| 28 |
## Descriptive Variable names |
| 29 |
|
| 30 |
Naming things is hard. Hug has a few strict guidelines on the usage of variable names, which hopefully will reduce some of the guesswork: |
| 31 |
- No one character variable names. |
| 32 |
- Except for x, y, and z as coordinates. |
| 33 |
- It's not okay to override built-in functions. |
| 34 |
- Except for `id`. Guido himself thought that shouldn't have been moved to the system module. It's too commonly used, and alternatives feel very artificial. |
| 35 |
- Avoid Acronyms, Abbreviations, or any other short forms - unless they are almost universally understand. |
| 36 |
|
| 37 |
## Adding new modules |
| 38 |
|
| 39 |
New modules added to the a project that follows the HOPE-8 standard should all live directly within the base `PROJECT_NAME/` directory without nesting. If the modules are meant only for internal use within the project, they should be prefixed with a leading underscore. For example, def _internal_function. Modules should contain a docstring at the top that gives a general explanation of the purpose and then restates the project's use of the MIT license. |
| 40 |
There should be a `tests/test_$MODULE_NAME.py` file created to correspond to every new module that contains test coverage for the module. Ideally, tests should be 1:1 (one test object per code object, one test method per code method) to the extent cleanly possible. |
| 41 |
|
| 42 |
## Automated Code Cleaners |
| 43 |
|
| 44 |
All code submitted should be formatted using Ruff and isort. |
| 45 |
Ruff should be run with the line length set to 100, and isort with Black compatible settings in place. |
| 46 |
|
| 47 |
## Automated Code Linting |
| 48 |
|
| 49 |
All code submitted should run through the following tools: |
| 50 |
|
| 51 |
- Ruff and isort verification. |
| 52 |
- Flake8 |
| 53 |
- flake8-bugbear |
| 54 |
- Bandit |
| 55 |
- ruff |
| 56 |
- pep8-naming |
| 57 |
- vulture |