codestyle.rst 2.84 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
2
3
4
Code Structure
==============
An example code structure is shown below.
Files/directories with asterisks (*) marks are optional.
BO ZHANG's avatar
BO ZHANG committed
5

BO ZHANG's avatar
BO ZHANG committed
6
.. code-block::
BO ZHANG's avatar
BO ZHANG committed
7

BO ZHANG's avatar
BO ZHANG committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    csst_proto                                # the repository name
    ├── csst_proto                            # the package name
    │   ├── data                              # package associated data directory
    │   ├── __init__.py                       # necessary file for a Python package
    │   ├── flip_image.py                     # Python modules
    │   ├── scratch.py
    │   ├── some_other_modules.py
    │   └── top_level_interface.py            # the top level interface module
    ├── doc                                   # *sphinx-based documentation directory
    │   ├── build
    │   ├── source
    │   ├── Makefile
    │   ├── apidoc.sh
    │   ├── contents.md
    │   ├── make.bat
    │   └── preview.sh
    ├── examples                              # *example scripts
    │   ├── how_this_code_will_be_used.py
    │   └── how_to_write_docstring.py
    ├── tests                                 # unit tests
    │   ├── test_flip_image.py
    │   └── test_other_functions.py
    ├── LICENSE                               # license file
    ├── README.md                             # README file (Markdown recommended)
    ├── install.sh                            # a single-line installation script
    ├── install_local.sh                      # local installation script
    ├── readthedocs.yml                       # *configuration file for readthedocs
    ├── requirements.txt                      # package dependencies
    └── setup.py                              # setup file
BO ZHANG's avatar
BO ZHANG committed
37
38


BO ZHANG's avatar
BO ZHANG committed
39
40
41
42
43
44
Code Style
==========
Python code should follow PEP 8
    - https://peps.python.org/pep-0008/
Whereas C/C++ code should follow PEP 7
    - https://peps.python.org/pep-0007/
BO ZHANG's avatar
BO ZHANG committed
45

BO ZHANG's avatar
BO ZHANG committed
46
47
48
49
50
51
52
53
54
55

Numpy-style docstring
=====================
There are several popular docstring styles, namely Google, reStructuredText, and Numpy.
The CSST DAS adopts Numpydoc-style among the three.
We refer our developers to the Numpydoc official style guide for instructions on
how to write docstrings.
    - https://numpydoc.readthedocs.io/en/latest/format.html
In particular, a complete example is available here.
    - https://numpydoc.readthedocs.io/en/latest/example.html
BO ZHANG's avatar
BO ZHANG committed
56
57


BO ZHANG's avatar
BO ZHANG committed
58
59
Markup language
===============
BO ZHANG's avatar
BO ZHANG committed
60
61
62
Markdown and reStructrured Text are two of popular markup languages.
reStructrured Text is used in Numpydoc docstrings as well as sphinx-based documentation.
Markdown is much easier and usually used to write `README` for a package.
BO ZHANG's avatar
BO ZHANG committed
63

BO ZHANG's avatar
BO ZHANG committed
64
65
- Markdown
    - https://www.markdownguide.org/
BO ZHANG's avatar
BO ZHANG committed
66
- reStructured Text
BO ZHANG's avatar
BO ZHANG committed
67
    - https://www.writethedocs.org/guide/writing/reStructuredText/