|
1 | | -# Docstring |
2 | | -[Docstring](README.md) is a small Python package that allows you to extract docstrings from |
3 | | -source code and display them as plain-text, markdown, or JSON data. It is meant |
4 | | -to serve as a basic building-block for building customized documentation |
5 | | -systems. Simply put, [Docstring](README.md) extracts and parses docstrings and |
6 | | -gives you access to their data so you can decide what you want to do with it. |
7 | | - |
8 | | -* Support for `Python` code (support `C` is planned). |
| 1 | +# MyDocstring |
| 2 | +[MyDocstring](README.md) is a small Python package that allows you to extract docstrings display them as either plain-text, [markdown](http://commonmark.org/), or [JSON](https://www.json.org/) data. |
| 3 | + |
| 4 | +* Support for Python-code (support for C-code is planned). |
9 | 5 | * Support for [Google-style docstrings](http://google.github.io/styleguide/pyguide.html) |
10 | 6 | * Produces [JSON](https://www.json.org/), plain-text, and [markdown](http://commonmark.org/) output for modules, classes, functions, and |
11 | 7 | methods. |
12 | 8 |
|
13 | | -## Contents |
14 | | - * [Getting Started](#getting-started) |
15 | | - * [Usage](#usage) |
16 | | - * [Python Examples](#python-examples) |
17 | | - * [Installing](#installing) |
18 | | - * [Dependencies](#dependencies) |
19 | | - * [Troubleshooting](#troubleshooting) |
20 | | - * [Contributing](#contributing) |
21 | | - * [Showcase](#showcase) |
22 | | - * [Pull requests](#pull-requests) |
23 | | - * [Running tests](#running-tests) |
24 | | - * [License](#license) |
25 | | - |
26 | 9 | ## Getting Started |
27 | | -Once [installed](#installing), you can begin extracting and converting docstrings using the |
28 | | -command-line interface application `docstring`. |
29 | | - |
30 | | -### Usage |
31 | | - |
32 | | -``` |
33 | | -$ docstring --help |
34 | | -docstring |
35 | | -
|
36 | | -Usage: |
37 | | - docstring <file> <name> [-tmj] [-T=<tpl>] |
38 | | - docstring -h | --help |
39 | | - docstring --version |
40 | | -
|
41 | | -Options: |
42 | | - -h --help Show help (this screen). |
43 | | - --version Show version. |
44 | | - -m --markdown Output extracted docstring as Markdown. |
45 | | - -t --text Output extracted docstring as plain-text. |
46 | | - -j --json Output extracted docstring as JSON. |
47 | | - -T=<tpl> --template=<tpl> Set template for Markdown output. |
48 | | -
|
49 | | -Examples: |
50 | | - Extract the module docstring |
51 | | - docstring module.py . --markdown |
52 | | - Extract a module function docstring |
53 | | - docstring module.py function --markdown |
54 | | - Extract a class docstring |
55 | | - docstring module.py Class --markdown |
56 | | - Extract a method docstring |
57 | | - docstring module.py Class.method --markdown |
58 | | -
|
59 | | -Help: |
60 | | - Please see the issue tracker for the Github repository: |
61 | | - https://github.com/ooreilly/docstring |
62 | | -``` |
| 10 | +You can begin extracting and converting docstrings using the command line tool |
| 11 | +`mydocstring` that comes with package. Simply type `mydocstring --help` to see how to use it. |
63 | 12 |
|
| 13 | +Let's extract the docstring from the following example code and convert it to |
| 14 | +markdown: |
64 | 15 | ```python |
65 | 16 | def example_function(arg1, arg2=1): |
66 | 17 | """ |
67 | | - This is an example of a docstring that conforms to the Google style guide. |
68 | | - The indentation uses four spaces (no tabs). Note that each section starts |
69 | | - with a header such as `Arguments` or `Returns` and its contents is indented. |
| 18 | + This is an example of a Google-style docstring. |
70 | 19 |
|
71 | 20 | Arguments: |
72 | 21 |
|
73 | 22 | arg1 (`int`): This description for this argument fits on one line. |
74 | 23 | arg2 (`int`, optional): This description is too long to fit on a |
75 | 24 | single line. Note that it is continued by being indented. |
76 | | -
|
77 | | - Returns: |
78 | | -
|
79 | | - `bool` : Stating the return type here is optional. |
80 | | -
|
81 | | - We can continue putting explanations in this section as long as the text |
82 | | - is indented. |
83 | | -
|
84 | | - This text is no longer indented and therefore not part of the `Returns` |
85 | | - section. |
86 | | -
|
87 | | - Raises: |
88 | | -
|
89 | | - ValueError: This is exception is raised when arg1 and arg2 are equal. |
90 | | -
|
91 | 25 | """ |
92 | | - if arg1 == arg2: |
93 | | - raise ValueError("`arg1` and `arg2` cannot be equal.") |
94 | | - if arg1 > arg2: |
95 | | - return True |
96 | | - else: |
97 | | - return False |
98 | | -``` |
99 | | - |
100 | | -#### Plain-text |
101 | | - |
102 | | -Next, we extract the docstring for the function above and output it as |
103 | | -plain-text by calling |
104 | | -``` |
105 | | -$ docstring examples/example.py example_function --text > examples/example_py.txt |
106 | | -
|
| 26 | + pass |
107 | 27 | ``` |
108 | | -Go to [examples/example.txt](examples/example_py.txt) to view the output. |
109 | | - |
110 | | -#### Markdown |
111 | | -To output markdown, we simply call |
| 28 | +A more detailed example code is found in [examples/example.py](examples/example.py). |
112 | 29 |
|
113 | 30 | ``` |
114 | | -$ docstring examples/example.py --markdown > examples/example_py.md |
115 | | -
|
| 31 | +$ docstring examples/example.py example_function --markdown > examples/example_py.md |
116 | 32 | ``` |
117 | 33 | Go to [examples/example_py.md](examples/example_py.md) to |
118 | | -view the output. |
119 | | - |
120 | | -#### Customization |
121 | | - |
122 | | -If you are not satisfied with the resulting markdown, you can provide your own |
| 34 | +view the output. If you are not satisfied with the resulting markdown, you can provide your own |
123 | 35 | [mako](http://makotemplates.org) template |
| 36 | + |
124 | 37 | ``` |
125 | 38 | $ docstring examples/example.py example_function --markdown --template customization.md |
126 | | -
|
127 | 39 | ``` |
128 | | -Go to [docstring/templates/](docstring/templates/) to see how to make your own |
| 40 | +Go to [mydocstring/templates/](mydocstring/templates/) to see how to make your own |
129 | 41 | template. |
130 | 42 |
|
131 | | -#### JSON |
132 | | - |
133 | | -Another possibility is to output JSON data (then its up to you how you to |
134 | | -format the data) |
135 | | - |
136 | | -``` |
137 | | -$ docstring examples/example.py --json > examples/example_py.md |
138 | | -
|
139 | | -``` |
140 | | -Go to [examples/example_py.json](examples/example_py.json) to |
141 | | -view the output for this example. |
| 43 | +It is also possible to output plain-text, or JSON-data using the flags args |
| 44 | +`--text` and `--json`. Example output can be found [here](examples/). |
142 | 45 |
|
143 | | -### Installing |
144 | | -Use setup tools or pip to install this package. |
145 | 46 |
|
| 47 | +## Installation |
| 48 | +The package is available on the Python packaging index [PyPi](https://pypi.python.org/pypi) and can be installed via pip as follows. |
146 | 49 | ```bash |
147 | | -$ pip install docstring |
148 | | -``` |
149 | | -*or* |
150 | | -```bash |
151 | | -$ sudo python setup.py install |
| 50 | +$ pip install mydocstring |
152 | 51 | ``` |
153 | 52 |
|
154 | | -### Dependencies |
| 53 | +## Dependencies |
155 | 54 | This project uses: |
156 | 55 | * [docopt](http://docopt.org/) for the command-line interface application. |
157 | 56 | * [mako](http://www.makotemplates.org/) for producing markdown templates. |
158 | 57 | * [pytest](https://docs.pytest.org/en/latest/) for testing. |
159 | 58 |
|
160 | | -### Troubleshooting |
| 59 | +## Issues |
161 | 60 | If you are having problems extracting your docstrings, or parts of their content |
162 | | -end up missing. Please make sure that your are only using spaces (no tabs). |
163 | | -Four spaces should be used for each level of indentation as stated in PEP . |
| 61 | +end up missing, then please make sure that your are only using spaces (no tabs). |
| 62 | +Four spaces should be used for each level of indentation. |
164 | 63 | Also, make sure that you conform to the [Google style |
165 | 64 | guide](http://google.github.io/styleguide/pyguide.html) when writing your |
166 | | -docstrings. It's easy to forget indentation or mess something else up! |
167 | | - |
168 | | -That said, this tool likely breaks for some edge-cases and it is completely |
169 | | -possible that you have discovered a bug. Please see the issue tracker to see if |
170 | | -this problem is known. If not, please submit a new issue with a minimum example |
171 | | -that introduces the problem and also what the excepted output is supposed to be. |
| 65 | +docstrings. |
172 | 66 |
|
| 67 | +Otherwise, please submit a new issue using the [issue tracker](https://github.com/ooreilly/mydocstring/issues) and explain the problem. |
173 | 68 |
|
174 | 69 | ## Contributing |
175 | | -### Showcase |
| 70 | +Contributions are more than welcome. Please reach out via the issue tracker to |
| 71 | +discuss and also see [here](contributing.md) for |
| 72 | +some guidelines. |
| 73 | + |
| 74 | +## Showcase |
176 | 75 | If you end up using this tool in your project in one way or another. I would |
177 | 76 | love to hear about it and showcase it here. Please go ahead and make a pull |
178 | 77 | request. |
179 | 78 |
|
180 | | -## Pull requests |
181 | | -You are more than welcome to contribute to this project. In fact, getting some help |
182 | | -developing and maintaining this package would be fantastic! Please use the issue |
183 | | -tracker to look for any issues you think you can resolve, or feel free to post a |
184 | | -new issue if you want to suggest a new feature. Ideally, post a feature |
185 | | -request to discuss it before you implement it and make a pull request. |
186 | | - |
187 | | -If you are contributing new code, then |
188 | | -1. First, fork the repository and create your own branch. Commit your changes to |
189 | | - this branch. |
190 | | -2. In your commit, please include a test case that demonstrates that your |
191 | | - contribution works as expected using `pytest`. |
192 | | - Having a test case will make it easier to review your code and therefore lead |
193 | | - to your pull request being approved faster. Please also use `pylint` to check |
194 | | - for issues. During development it is usually simplest to disable |
195 | | - reports via `pylint my_feature.py --reports=n` and then enable again once all |
196 | | - issues have been corrected. Make sure that you test all parts of your code |
197 | | - using a coverage tool such as `py-cov`. |
198 | | -3. Update [ACKNOWLEDGMENTS](ACKNOWLEDGMENTS.md) to make sure you get credit for |
199 | | - your contribution. |
200 | | -4. Update [README](README.md) to explain how to use your feature. |
201 | | -5. Make all your commits to your feature branch and check that all tests pass. |
202 | | - Then go ahead and submit a pull request! |
203 | | - |
204 | | -## Running tests |
205 | | -[Pytest](https://docs.pytest.org/en/latest/) is used for testing. Currently, the |
206 | | -tests are quite limited in scope. More tests should definitely be developed to identify |
207 | | -edge cases and facilitate future code refactoring. |
208 | | - |
209 | | -To run the tests, go to the `docstring` directory and type |
210 | | - |
211 | | -```bash |
212 | | -$ pytest |
213 | | -``` |
214 | 79 | ## Acknowledgments |
215 | 80 | These are some projects that inspired me to develop this tool. |
216 | 81 | * [pdoc](https://github.com/BurntSushi/pdoc/) A tool for auto-generating API |
|
0 commit comments