Steppable 0.0.1
A CAS project written from scratch in C++
|
The Python code in this project follows the following standard.
snake_case
. Classes should be in PascalCase
._
) at the beginning or the end of the name, in order to differentiate from the keywords or other variables in the parent scope.#
for single-line comments. Use """</tt> for docstrings.
- Put a space after the <tt>\#</tt> character. If it is an inline comment, put two spaces before the <tt>\#</tt> character.
- <strong>Good</strong>:
@icode{python}
# This is a single-line comment.
def my_function():
""" This is a docstring. """
do_something() # This is an inline comment.
@endicode
- <strong>Bad</strong>:
@icode{python}
#This is a single-line comment.
def my_function():
# This is not a docstring.
do_something()# This is an inline comment.
@endicode
@section autotoc_md32 Imports
- Import statements should be on separate lines, and should be in alphabetical order.
\remark
Use the <tt>isort</tt> package to sort the imports.
\attention
Do <strong>NOT</strong> use <tt>from module import *</tt>. This will seriously affect the readability of the code.
- <strong>Good</strong>:
@icode{python}
import os
import sys
@endicode
- <strong>Bad</strong>:
@icode{python}
import os, sys
@endicode
@section autotoc_md33 File Structure
- The file structure should be as follows:
@icode{python}
# Header comments...
# Standard library imports
import os
import sys
# Third-party imports
import numpy as np
# Local application imports
from my_module import my_function
# Constants
MY_CONSTANT = 0
# Classes
class MyClass:
pass
# Functions
def my_function():
pass
# Main code (driver code) if necessary / for testing
if __name__ == "__main__":
my_function()
@endicode
@section autotoc_md34 Python Version
- The code should be compatible with the last 3 subversions of Python. The code should be tested with the latest version
of Python.
\note
As of now, the latest version is Python 3.12. Therefore, the last 3 subversions are 3.10, 3.11, and 3.12.
- Be very careful with version-specific features. If you use a feature that is not available in the last 3 subversions,
just do not use it.
<hr>
\remark
<br>
@section autotoc_md35 Tools
<br><br>
The Python code in this project follows the <a href="https://black.readthedocs.io/en/stable/" >Black code style. The code should be formatted using Black before pushing to the repository.
Formatting
The code should be formatted using Black. You can install Black using pip:
OR install everything in the pyproject.toml
file:
To format the code, use the following command:
and it will format the code according to the Black code style.
Sorting Imports
The imports should be sorted using isort
. You can install isort
using pip:
To sort the imports, use the following command:
and it will sort the imports according to alphabetical order.