Skip to content

Commit

Permalink
Merge pull request #640 from kkoomen/feature/python-doxygen
Browse files Browse the repository at this point in the history
Implement doxygen doc standard for python
  • Loading branch information
kkoomen authored Oct 27, 2023
2 parents 6b7ce96 + e731259 commit 1e40f53
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 19 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,24 @@ Is your favorite language not supported?
Is your favorite doc standard not supported?
[Suggest a new doc standard][suggest-doc-standard] :tada:

| | Language | Doc standards |
| :----------------- | :----------------------------------------------------- | :--------------------------------------------------------------------------- |
| :white_check_mark: | Python | [reST][py-rest], [Numpy][py-numpy], [Google][py-google], [Sphinx][py-sphinx] |
| :white_check_mark: | PHP | [phpdoc][phpdoc] |
| :white_check_mark: | JavaScript (Vanilla, ES6, FlowJS, NodeJS, Svelte, Vue) | [JSDoc][jsdoc] |
| :white_check_mark: | TypeScript | [JSDoc][jsdoc] |
| :white_check_mark: | HTML (through inline `<script>` tags) | [JSDoc][jsdoc] |
| :white_check_mark: | Lua | [LDoc][ldoc] |
| :white_check_mark: | Java | [JavaDoc][javadoc] |
| :white_check_mark: | Groovy | [JavaDoc][javadoc] |
| :white_check_mark: | Ruby | [YARD][yard] |
| :white_check_mark: | C++ | [Doxygen][doxygen] |
| :white_check_mark: | C | [Doxygen][doxygen], [KernelDoc][kerneldoc] |
| :white_check_mark: | C# | [XMLDoc][xmldoc] |
| :white_check_mark: | Bash | [Google][sh-google] |
| :white_check_mark: | Rust | [RustDoc][rustdoc] |
| :white_check_mark: | R | [Roxygen2][roxygen2] |
| :white_check_mark: | Scala | [ScalaDoc][scaladoc] |
| | Language | Doc standards |
| :----------------- | :----------------------------------------------------- | :----------------------------------------------------------------------------------------------- |
| :white_check_mark: | Python | [reST][py-rest], [Numpy][py-numpy], [Google][py-google], [Sphinx][py-sphinx], [Doxygen][doxygen] |
| :white_check_mark: | PHP | [phpdoc][phpdoc] |
| :white_check_mark: | JavaScript (Vanilla, ES6, FlowJS, NodeJS, Svelte, Vue) | [JSDoc][jsdoc] |
| :white_check_mark: | TypeScript | [JSDoc][jsdoc] |
| :white_check_mark: | HTML (through inline `<script>` tags) | [JSDoc][jsdoc] |
| :white_check_mark: | Lua | [LDoc][ldoc] |
| :white_check_mark: | Java | [JavaDoc][javadoc] |
| :white_check_mark: | Groovy | [JavaDoc][javadoc] |
| :white_check_mark: | Ruby | [YARD][yard] |
| :white_check_mark: | C++ | [Doxygen][doxygen] |
| :white_check_mark: | C | [Doxygen][doxygen], [KernelDoc][kerneldoc] |
| :white_check_mark: | C# | [XMLDoc][xmldoc] |
| :white_check_mark: | Bash | [Google][sh-google] |
| :white_check_mark: | Rust | [RustDoc][rustdoc] |
| :white_check_mark: | R | [Roxygen2][roxygen2] |
| :white_check_mark: | Scala | [ScalaDoc][scaladoc] |

# Getting started

Expand Down Expand Up @@ -162,7 +162,7 @@ Here is the full list of available doc standards per filetype:

| Variable | Default | Supported |
| :------------------------------- | :------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `g:doge_doc_standard_python` | `'reST'` | `'reST'`, `'numpy'`, `'google'`, `'sphinx'` |
| `g:doge_doc_standard_python` | `'reST'` | `'reST'`, `'numpy'`, `'google'`, `'sphinx'`, `'doxygen'` |
| `g:doge_doc_standard_php` | `'phpdoc'` | `'phpdoc'` |
| `g:doge_doc_standard_javascript` | `'jsdoc'` | `'jsdoc'` |
| `g:doge_doc_standard_html` | `'jsdoc'` | `'jsdoc'` |
Expand Down
1 change: 1 addition & 0 deletions doc/demos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Supported:
- Doc standards
- reST
- Sphinx
- Doxygen
- Numpy
- Google
- Python 3.7+ type hints
Expand Down
1 change: 1 addition & 0 deletions ftplugin/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let b:doge_supported_doc_standards = [
\ 'numpy',
\ 'google',
\ 'sphinx',
\ 'doxygen',
\ ]
let b:doge_doc_standard = doge#buffer#get_doc_standard('python')

Expand Down
1 change: 1 addition & 0 deletions helper/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub fn load_doc_config_str<'a>(parser_name: &'a str, doc_name: &'a str) -> &'a s
"python_numpy" => include_str!("python/docs/numpy.yaml"),
"python_google" => include_str!("python/docs/google.yaml"),
"python_sphinx" => include_str!("python/docs/sphinx.yaml"),
"python_doxygen" => include_str!("python/docs/doxygen.yaml"),

"cpp_doxygen_cpp_comment_exclamation" => include_str!("cpp/docs/doxygen_cpp_comment_exclamation.yaml"),
"cpp_doxygen_cpp_comment_slash" => include_str!("cpp/docs/doxygen_cpp_comment_slash.yaml"),
Expand Down
30 changes: 30 additions & 0 deletions helper/src/python/docs/doxygen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# https://www.woolseyworkshop.com/2020/06/25/documenting-python-programs-with-doxygen/

templates:
function:
node_types:
- function_definition
template: |
{% if not params and not exceptions and not return_type %}
"""! @brief [TODO:description]"""
{% else %}
"""!
@brief [TODO:description]
{% if params %}
~
{% for param in params %}
@param {{ param.name }} [TODO:description]
{% endfor %}
{% endif %}
{% if return_type %}
~
@return [TODO:description]
{% endif %}
{% if exceptions %}
~
{% for exception in exceptions %}
@throws {{ exception.name | default(value="[TODO:name]") }} [TODO:description]
{% endfor %}
{% endif %}
"""
{% endif %}
117 changes: 117 additions & 0 deletions test/filetypes/python/functions-doc-doxygen.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# ==============================================================================
# Functions using the Doxygen doc standard.
# ==============================================================================
Given python(function without parameters without return type where b:doge_doc_standard='doxygen'):
def myFunc():
pass

Do (trigger doge):
:let b:doge_doc_standard='doxygen'\<CR>
\<C-d>

Expect python (generated comment with nothing but the text 'TODO'):
def myFunc():
"""! @brief [TODO:description]"""
pass

# ------------------------------------------------------------------------------

Given python(function with parameters without type hints without return type where b:doge_doc_standard='doxygen'):
def myFunc(p1, p2, p3 = ''):
pass

Do (trigger doge):
:let b:doge_doc_standard='doxygen'\<CR>
\<C-d>

Expect python (generated comment without type hints with defaults and optional):
def myFunc(p1, p2, p3 = ''):
"""!
@brief [TODO:description]

@param p1 [TODO:description]
@param p2 [TODO:description]
@param p3 [TODO:description]
"""
pass

# ------------------------------------------------------------------------------

Given python(function with parameters with type hints without return type where b:doge_doc_standard='doxygen'):
def myFunc(p1, p2: Callable[[int], None], p3: Callable[[int, Exception], None] = []):
pass

Do (trigger doge):
:let b:doge_doc_standard='doxygen'\<CR>
\<C-d>

Expect python (generated comment with type hints, defaults and optional):
def myFunc(p1, p2: Callable[[int], None], p3: Callable[[int, Exception], None] = []):
"""!
@brief [TODO:description]

@param p1 [TODO:description]
@param p2 [TODO:description]
@param p3 [TODO:description]
"""
pass

# ------------------------------------------------------------------------------

Given python(function with parameters with type hints with return type where b:doge_doc_standard='doxygen'):
def myFunc(p1, p2: Callable[[int], None], p3: Callable[[int, Exception], None] = []) -> Sequence[T]:
pass

Do (trigger doge):
:let b:doge_doc_standard='doxygen'\<CR>
\<C-d>

Expect python (generated comment with @param and @return tags):
def myFunc(p1, p2: Callable[[int], None], p3: Callable[[int, Exception], None] = []) -> Sequence[T]:
"""!
@brief [TODO:description]

@param p1 [TODO:description]
@param p2 [TODO:description]
@param p3 [TODO:description]

@return [TODO:description]
"""
pass

# ==============================================================================
# Read out the exceptions in the function body
# ==============================================================================
Given python (function with exceptions being raised in the body):
def myFunc(p1, p2: Callable[[int], None], p3: Callable[[int, Exception], None] = []) -> Sequence[T]:
try:
foo = ValueError()
raise foo
raise Exception()
except Exception as error:
pass

Do (trigger doge):
:let b:doge_doc_standard='doxygen'\<CR>
\<C-d>

Expect python (generated comment with @param and @throws tags):
def myFunc(p1, p2: Callable[[int], None], p3: Callable[[int, Exception], None] = []) -> Sequence[T]:
"""!
@brief [TODO:description]

@param p1 [TODO:description]
@param p2 [TODO:description]
@param p3 [TODO:description]

@return [TODO:description]

@throws [TODO:name] [TODO:description]
@throws Exception [TODO:description]
"""
try:
foo = ValueError()
raise foo
raise Exception()
except Exception as error:
pass

0 comments on commit 1e40f53

Please sign in to comment.