├── .gitignore ├── .travis.yml ├── CHANGES.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── docs ├── Makefile ├── _static │ └── .gitignore ├── autodoc_example.py ├── conf.py ├── index.rst └── make.bat ├── setup.cfg ├── setup.py └── sphinxcontrib ├── __init__.py └── asyncio.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | #Ipython Notebook 62 | .ipynb_checkpoints 63 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: no 2 | 3 | language: python 4 | 5 | python: 6 | - 3.5 7 | - 3.6 8 | - 3.7 9 | - 3.8 10 | 11 | os: 12 | - linux 13 | # - osx 14 | 15 | cache: 16 | directories: 17 | - $HOME/.cache/pip 18 | 19 | before_cache: 20 | - rm -f $HOME/.cache/pip/log/debug.log 21 | 22 | install: 23 | - pip install --upgrade pip wheel 24 | - pip install --upgrade setuptools 25 | - pip install flake8 26 | - pip install -e . 27 | 28 | script: 29 | - flake8 sphinxcontrib 30 | - make doc 31 | - python setup.py check -rms 32 | 33 | 34 | deploy: 35 | provider: pypi 36 | user: __token__ 37 | password: 38 | secure: dtMlrTS0u5EjwkYqLjBCoSNJSvqWxRQIf1DrjT4lwQTvuVyBLNy/CEXVHvY/iHlWiqnX/FjbVowm/FRVtAS6smIqiaSUHIJgvS3Hq+ykOsM3/umIxZyqeP7qQFH2+AUV2TsWvOi8kpFsG5SBmPUPJEMSFR5UEaL717Vc7VtJ3bjEZ/5WFeedQWyCybb+f/rRyn8x+5bnNNO53wwL7rcOWY6e4KYZmP6DUkYHCHTuvMx8kMpC9+ygmQ7Vy/cQ7Pjnv2xZzHREk4fkSSbAdrVVqF9UYSCQlxy57Q0Ek7hWb5DtCsNdwWvjjCQFqohjLUcX4icM+ZzVlZnERWfwaHyxY6yjhejf3GWZCZiFkjuL9B6lX9pR3yWINC1lNUOfqCMLsIrnUda/DUvyRw/qrkJJBIbEZr0rLY7ol5vGin/MFWaioZ3Z4cGrQBkLTWZEQ9XJc5G/PhD5Y9y5yMCz0hLPKEuqY3ElC3260u84b/S8F3P8GjOIMYF7odF/P1b3h0fUkMJ/JNo19DOMEDTbOfErPhvuySzbLj02Wq5cQ9b2AKY8WsDvl05fICvYuKCX2i8pw+gcQLRf8hClU+srGyMTWue5j054KYCinXO1b++eVIv1HMk74HrtooB4sfcIMxpbLJoMtZGVj7JgXyFuDSdjYeuUs7T8PkDhoC+M0uAV+kQ= 39 | distributions: "sdist bdist_wheel" 40 | skip_existing: true 41 | on: 42 | tags: true 43 | all_branches: true 44 | python: 3.8 45 | -------------------------------------------------------------------------------- /CHANGES.rst: -------------------------------------------------------------------------------- 1 | CHANGES 2 | ======= 3 | 4 | 5 | 0.3.0 (2020-08-19) 6 | ------------------ 7 | 8 | * Make the plugin compatible with Sphinx 3 9 | 10 | 11 | 0.2.0 (2016-04-15) 12 | ------------------ 13 | 14 | * Added autodoc support #1 15 | 16 | 17 | 0.1.0 (2016-03-07) 18 | ------------------- 19 | 20 | * Initial release 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 aio-libs collaboration. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include CHANGES.rst 3 | include README.rst 4 | include Makefile 5 | graft sphinxcontrib 6 | graft docs 7 | global-exclude *.pyc 8 | prune docs/_build 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: doc 2 | 3 | doc: 4 | make -C docs html 5 | @echo "open file://`pwd`/docs/_build/html/index.html" 6 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | sphinxcontrib-asyncio 2 | ===================== 3 | 4 | Sphinx extension for adding asyncio-specific markups 5 | 6 | Read docs https://sphinxcontrib-asyncio.readthedocs.io/en/latest/ for more details 7 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help 23 | help: 24 | @echo "Please use \`make ' where is one of" 25 | @echo " html to make standalone HTML files" 26 | @echo " dirhtml to make HTML files named index.html in directories" 27 | @echo " singlehtml to make a single large HTML file" 28 | @echo " pickle to make pickle files" 29 | @echo " json to make JSON files" 30 | @echo " htmlhelp to make HTML files and a HTML help project" 31 | @echo " qthelp to make HTML files and a qthelp project" 32 | @echo " applehelp to make an Apple Help Book" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | @echo " coverage to run coverage check of the documentation (if enabled)" 49 | 50 | .PHONY: clean 51 | clean: 52 | rm -rf $(BUILDDIR)/* 53 | 54 | .PHONY: html 55 | html: 56 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 57 | @echo 58 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 59 | 60 | .PHONY: dirhtml 61 | dirhtml: 62 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 63 | @echo 64 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 65 | 66 | .PHONY: singlehtml 67 | singlehtml: 68 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 69 | @echo 70 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 71 | 72 | .PHONY: pickle 73 | pickle: 74 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 75 | @echo 76 | @echo "Build finished; now you can process the pickle files." 77 | 78 | .PHONY: json 79 | json: 80 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 81 | @echo 82 | @echo "Build finished; now you can process the JSON files." 83 | 84 | .PHONY: htmlhelp 85 | htmlhelp: 86 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 87 | @echo 88 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 89 | ".hhp project file in $(BUILDDIR)/htmlhelp." 90 | 91 | .PHONY: qthelp 92 | qthelp: 93 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 94 | @echo 95 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 96 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 97 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/sphinxcontrib-asyncio.qhcp" 98 | @echo "To view the help file:" 99 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/sphinxcontrib-asyncio.qhc" 100 | 101 | .PHONY: applehelp 102 | applehelp: 103 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 104 | @echo 105 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 106 | @echo "N.B. You won't be able to view it unless you put it in" \ 107 | "~/Library/Documentation/Help or install it in your application" \ 108 | "bundle." 109 | 110 | .PHONY: devhelp 111 | devhelp: 112 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 113 | @echo 114 | @echo "Build finished." 115 | @echo "To view the help file:" 116 | @echo "# mkdir -p $$HOME/.local/share/devhelp/sphinxcontrib-asyncio" 117 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/sphinxcontrib-asyncio" 118 | @echo "# devhelp" 119 | 120 | .PHONY: epub 121 | epub: 122 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 123 | @echo 124 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 125 | 126 | .PHONY: latex 127 | latex: 128 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 129 | @echo 130 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 131 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 132 | "(use \`make latexpdf' here to do that automatically)." 133 | 134 | .PHONY: latexpdf 135 | latexpdf: 136 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 137 | @echo "Running LaTeX files through pdflatex..." 138 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 139 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 140 | 141 | .PHONY: latexpdfja 142 | latexpdfja: 143 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 144 | @echo "Running LaTeX files through platex and dvipdfmx..." 145 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 146 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 147 | 148 | .PHONY: text 149 | text: 150 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 151 | @echo 152 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 153 | 154 | .PHONY: man 155 | man: 156 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 157 | @echo 158 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 159 | 160 | .PHONY: texinfo 161 | texinfo: 162 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 163 | @echo 164 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 165 | @echo "Run \`make' in that directory to run these through makeinfo" \ 166 | "(use \`make info' here to do that automatically)." 167 | 168 | .PHONY: info 169 | info: 170 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 171 | @echo "Running Texinfo files through makeinfo..." 172 | make -C $(BUILDDIR)/texinfo info 173 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 174 | 175 | .PHONY: gettext 176 | gettext: 177 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 178 | @echo 179 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 180 | 181 | .PHONY: changes 182 | changes: 183 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 184 | @echo 185 | @echo "The overview file is in $(BUILDDIR)/changes." 186 | 187 | .PHONY: linkcheck 188 | linkcheck: 189 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 190 | @echo 191 | @echo "Link check complete; look for any errors in the above output " \ 192 | "or in $(BUILDDIR)/linkcheck/output.txt." 193 | 194 | .PHONY: doctest 195 | doctest: 196 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 197 | @echo "Testing of doctests in the sources finished, look at the " \ 198 | "results in $(BUILDDIR)/doctest/output.txt." 199 | 200 | .PHONY: coverage 201 | coverage: 202 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 203 | @echo "Testing of coverage in the sources finished, look at the " \ 204 | "results in $(BUILDDIR)/coverage/python.txt." 205 | 206 | .PHONY: xml 207 | xml: 208 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 209 | @echo 210 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 211 | 212 | .PHONY: pseudoxml 213 | pseudoxml: 214 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 215 | @echo 216 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 217 | -------------------------------------------------------------------------------- /docs/_static/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aio-libs/sphinxcontrib-asyncio/dbfa79e29980e73ad2dd9dec59f1238b1a8a7cd7/docs/_static/.gitignore -------------------------------------------------------------------------------- /docs/autodoc_example.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | 4 | class MyClass: 5 | 6 | def my_func(self): 7 | """ Normal function """ 8 | 9 | @asyncio.coroutine 10 | def my_coro(self): 11 | """ This is my coroutine """ 12 | 13 | 14 | @asyncio.coroutine 15 | def coro(param): 16 | """ Module level async function """ 17 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # sphinxcontrib-asyncio documentation build configuration file, created by 5 | # sphinx-quickstart on Fri Mar 4 23:56:21 2016. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | import codecs 17 | import os 18 | import re 19 | import sys 20 | 21 | # If extensions (or modules to document with autodoc) are in another directory, 22 | # add these directories to sys.path here. If the directory is relative to the 23 | # documentation root, use os.path.abspath to make it absolute, like shown here. 24 | sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../'))) 25 | 26 | _docs_path = os.path.dirname(__file__) 27 | _version_path = os.path.abspath(os.path.join(_docs_path, 28 | '..', 29 | 'sphinxcontrib', 30 | 'asyncio.py')) 31 | with codecs.open(_version_path, 'r', 'latin1') as fp: 32 | try: 33 | _version_info = re.search(r"^__version__ = '" 34 | r"(?P\d+)" 35 | r"\.(?P\d+)" 36 | r"\.(?P\d+)" 37 | r"(?P.*)?'$", 38 | fp.read(), re.M).groupdict() 39 | except IndexError: 40 | raise RuntimeError('Unable to determine version.') 41 | 42 | sys.path.append('..') 43 | 44 | # -- General configuration ------------------------------------------------ 45 | 46 | # If your documentation needs a minimal Sphinx version, state it here. 47 | needs_sphinx = '1.0' 48 | 49 | # Add any Sphinx extension module names here, as strings. They can be 50 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 51 | # ones. 52 | extensions = [ 53 | 'sphinx.ext.intersphinx', 54 | 'sphinx.ext.viewcode', 55 | 'sphinx.ext.autodoc', 56 | 'sphinxcontrib.asyncio', 57 | ] 58 | 59 | intersphinx_mapping = { 60 | 'python': ('http://docs.python.org/3', None) 61 | } 62 | 63 | 64 | # Add any paths that contain templates here, relative to this directory. 65 | templates_path = ['_templates'] 66 | 67 | # The suffix(es) of source filenames. 68 | # You can specify multiple suffix as a list of string: 69 | # source_suffix = ['.rst', '.md'] 70 | source_suffix = '.rst' 71 | 72 | # The encoding of source files. 73 | source_encoding = 'utf-8-sig' 74 | 75 | # The master toctree document. 76 | master_doc = 'index' 77 | 78 | # General information about the project. 79 | project = 'sphinxcontrib-asyncio' 80 | copyright = '2016, Andrew Svetlov' 81 | author = 'Andrew Svetlov' 82 | 83 | # The version info for the project you're documenting, acts as replacement for 84 | # |version| and |release|, also used in various other places throughout the 85 | # built documents. 86 | # 87 | # The short X.Y version. 88 | version = '{major}.{minor}'.format(**_version_info) 89 | # The full version, including alpha/beta/rc tags. 90 | release = '{major}.{minor}.{patch}-{tag}'.format(**_version_info) 91 | 92 | # The language for content autogenerated by Sphinx. Refer to documentation 93 | # for a list of supported languages. 94 | # 95 | # This is also used if you do content translation via gettext catalogs. 96 | # Usually you set "language" from the command line for these cases. 97 | language = None 98 | 99 | # There are two options for replacing |today|: either, you set today to some 100 | # non-false value, then it is used: 101 | # today = '' 102 | # Else, today_fmt is used as the format for a strftime call. 103 | today_fmt = '%B %d, %Y' 104 | 105 | # List of patterns, relative to source directory, that match files and 106 | # directories to ignore when looking for source files. 107 | exclude_patterns = ['_build'] 108 | 109 | # The reST default role (used for this markup: `text`) to use for all 110 | # documents. 111 | # default_role = None 112 | 113 | # If true, '()' will be appended to :func: etc. cross-reference text. 114 | # add_function_parentheses = True 115 | 116 | # If true, the current module name will be prepended to all description 117 | # unit titles (such as .. function::). 118 | # add_module_names = True 119 | 120 | # If true, sectionauthor and moduleauthor directives will be shown in the 121 | # output. They are ignored by default. 122 | # show_authors = False 123 | 124 | # The name of the Pygments (syntax highlighting) style to use. 125 | pygments_style = 'sphinx' 126 | 127 | # A list of ignored prefixes for module index sorting. 128 | # modindex_common_prefix = [] 129 | 130 | # If true, keep warnings as "system message" paragraphs in the built documents. 131 | # keep_warnings = False 132 | 133 | # If true, `todo` and `todoList` produce output, else they produce nothing. 134 | todo_include_todos = False 135 | 136 | 137 | # -- Options for HTML output ---------------------------------------------- 138 | 139 | # The theme to use for HTML and HTML Help pages. See the documentation for 140 | # a list of builtin themes. 141 | html_theme = 'alabaster' 142 | 143 | # Theme options are theme-specific and customize the look and feel of a theme 144 | # further. For a list of options available for each theme, see the 145 | # documentation. 146 | # html_theme_options = {} 147 | 148 | # Add any paths that contain custom themes here, relative to this directory. 149 | # html_theme_path = [] 150 | 151 | # The name for this set of Sphinx documents. If None, it defaults to 152 | # " v documentation". 153 | # html_title = None 154 | 155 | # A shorter title for the navigation bar. Default is the same as html_title. 156 | # html_short_title = None 157 | 158 | # The name of an image file (relative to this directory) to place at the top 159 | # of the sidebar. 160 | # html_logo = None 161 | 162 | # The name of an image file (within the static path) to use as favicon of the 163 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 164 | # pixels large. 165 | # html_favicon = None 166 | 167 | # Add any paths that contain custom static files (such as style sheets) here, 168 | # relative to this directory. They are copied after the builtin static files, 169 | # so a file named "default.css" will overwrite the builtin "default.css". 170 | html_static_path = ['_static'] 171 | 172 | # Add any extra paths that contain custom files (such as robots.txt or 173 | # .htaccess) here, relative to this directory. These files are copied 174 | # directly to the root of the documentation. 175 | # html_extra_path = [] 176 | 177 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 178 | # using the given strftime format. 179 | # html_last_updated_fmt = '%b %d, %Y' 180 | 181 | # If true, SmartyPants will be used to convert quotes and dashes to 182 | # typographically correct entities. 183 | # html_use_smartypants = True 184 | 185 | # Custom sidebar templates, maps document names to template names. 186 | # html_sidebars = {} 187 | 188 | # Additional templates that should be rendered to pages, maps page names to 189 | # template names. 190 | # html_additional_pages = {} 191 | 192 | # If false, no module index is generated. 193 | # html_domain_indices = True 194 | 195 | # If false, no index is generated. 196 | # html_use_index = True 197 | 198 | # If true, the index is split into individual pages for each letter. 199 | # html_split_index = False 200 | 201 | # If true, links to the reST sources are added to the pages. 202 | # html_show_sourcelink = True 203 | 204 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 205 | # html_show_sphinx = True 206 | 207 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 208 | # html_show_copyright = True 209 | 210 | # If true, an OpenSearch description file will be output, and all pages will 211 | # contain a tag referring to it. The value of this option must be the 212 | # base URL from which the finished HTML is served. 213 | # html_use_opensearch = '' 214 | 215 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 216 | # html_file_suffix = None 217 | 218 | # Language to be used for generating the HTML full-text search index. 219 | # Sphinx supports the following languages: 220 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' 221 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr' 222 | # html_search_language = 'en' 223 | 224 | # A dictionary with options for the search language support, empty by default. 225 | # Now only 'ja' uses this config value 226 | # html_search_options = {'type': 'default'} 227 | 228 | # The name of a javascript file (relative to the configuration directory) that 229 | # implements a search results scorer. If empty, the default will be used. 230 | # html_search_scorer = 'scorer.js' 231 | 232 | # Output file base name for HTML help builder. 233 | htmlhelp_basename = 'sphinxcontrib-asynciodoc' 234 | 235 | autodoc_member_order = 'bysource' 236 | add_module_names = False 237 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. sphinxcontrib-asyncio documentation master file, created by 2 | sphinx-quickstart on Fri Mar 4 23:56:21 2016. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | .. default-domain:: py 7 | 8 | sphinxcontrib-asyncio 9 | ===================== 10 | 11 | Add :ref:`coroutine` markup support to sphinx-based docs. 12 | 13 | .. _GitHub: https://github.com/aio-libs/sphinxcontrib-asyncio 14 | 15 | Installation 16 | ------------ 17 | 18 | 1. Install from PyPI: 19 | 20 | .. code-block:: shell 21 | 22 | $ pip install sphinxcontrib-asyncio 23 | 24 | 2. Enable ``sphinxcontrib-asyncio`` extension in your ``conf.py``: 25 | 26 | .. code-block:: python 27 | 28 | extensions = ['sphinxcontrib.asyncio'] 29 | 30 | Usage In Documents 31 | ------------------ 32 | 33 | Use ``cofunction`` instead of ``function``:: 34 | 35 | .. cofunction:: coro(a, b) 36 | 37 | Simple coroutine function. 38 | 39 | .. cofunction:: coro(a, b) 40 | :noindex: 41 | 42 | Simple coroutine function. 43 | 44 | and ``comethod`` instead of ``method``:: 45 | 46 | .. class:: A 47 | 48 | .. comethod:: meth(self, param) 49 | 50 | Coroutine method. 51 | 52 | .. class:: A 53 | :noindex: 54 | 55 | .. comethod:: meth(self, param) 56 | 57 | Coroutine method. 58 | 59 | For more complex markup use *directive options*, e.g. 60 | ``async-with`` for *asynchronous context managers factories*:: 61 | 62 | .. cofunction:: open_url(param) 63 | :async-with: 64 | 65 | A function that returns asynchronous context manager. 66 | 67 | 68 | .. cofunction:: open_url(param) 69 | :async-with: 70 | 71 | A function that returns asynchronous context manager. 72 | 73 | That means ``open_url`` can be used as:: 74 | 75 | async with open_url(arg) as cm: 76 | pass 77 | 78 | ``async-for`` may be used for *asynchronous generator* markup:: 79 | 80 | .. cofunction:: iter_vals(arg) 81 | :async-for: 82 | 83 | A function the returns asynchronous generator. 84 | 85 | .. cofunction:: iter_vals(arg) 86 | :async-for: 87 | :noindex: 88 | 89 | A function the returns asynchronous generator. 90 | 91 | ``iter_vals()`` can be used as:: 92 | 93 | async for item in iter_args(arg): 94 | pass 95 | 96 | By default ``async-for`` and ``async-with`` suppresses ``coroutine``. 97 | 98 | If both ``await func()`` and ``async with func():`` are allowed (func 99 | is both *coroutine* and *asynchronous context manager*) explicit 100 | **coroutine** flag:: 101 | 102 | .. cofunction:: get(url) 103 | :async-with: 104 | :coroutine: 105 | 106 | A function can be used in ``async with`` and ``await`` context. 107 | 108 | .. cofunction:: get(url) 109 | :async-with: 110 | :coroutine: 111 | :noindex: 112 | 113 | A function can be used in ``async with`` and ``await`` context. 114 | 115 | ``comethod`` also may be used with **staticmethod** and 116 | **classmethod** optional specifiers, e.g.:: 117 | 118 | .. class:: A 119 | 120 | .. comethod:: f(cls, arg) 121 | :classmethod: 122 | 123 | This is classmethod 124 | 125 | .. class:: A 126 | :noindex: 127 | 128 | .. comethod:: f(cls, arg) 129 | :classmethod: 130 | 131 | This is classmethod 132 | 133 | 134 | Usage in `sphinx.ext.autodoc` extension 135 | --------------------------------------- 136 | 137 | .. currentmodule:: autodoc_example 138 | 139 | ``sphinxcontrib-asyncio`` add special documenters for autodocs, which will use 140 | *cofunction* and *comethod* directives if the function is an ``async def`` or 141 | is marked with ``coroutine`` decorator. 142 | 143 | For example this source: 144 | 145 | .. literalinclude:: autodoc_example.py 146 | :language: python 147 | 148 | 149 | Using this simple configuration in your `.rst` file:: 150 | 151 | .. autocofunction:: coro 152 | 153 | .. autoclass:: MyClass 154 | :members: 155 | 156 | Will yield next documentation: 157 | 158 | .. autocofunction:: coro 159 | :noindex: 160 | 161 | .. autoclass:: MyClass 162 | :members: 163 | :noindex: 164 | 165 | You can set directive options by adding it to `autocofunction` and 166 | `autocomethod` directives:: 167 | 168 | .. autocofunction:: coro 169 | :async-for: 170 | :coroutine: 171 | 172 | .. autocofunction:: coro 173 | :async-for: 174 | :coroutine: 175 | :noindex: 176 | 177 | You can also force `coroutine` prefix on not-coroutine method by overriding it 178 | as `autocomethod` directive:: 179 | 180 | .. autoclass:: MyClass 181 | :members: 182 | :exclude-members: my_func 183 | 184 | .. autocomethod:: my_func() 185 | 186 | .. autoclass:: MyClass 187 | :members: 188 | :exclude-members: my_func 189 | :noindex: 190 | 191 | .. autocomethod:: my_func() 192 | 193 | Authors and License 194 | ------------------- 195 | 196 | The ``sphinxcontrib-asyncio`` package is written by Andrew Svetlov. 197 | 198 | It's *Apache 2* licensed and freely available. 199 | 200 | Feel free to improve this package and send a pull request to GitHub_. 201 | 202 | 203 | 204 | .. toctree:: 205 | :maxdepth: 2 206 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | echo. coverage to run coverage check of the documentation if enabled 41 | goto end 42 | ) 43 | 44 | if "%1" == "clean" ( 45 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 46 | del /q /s %BUILDDIR%\* 47 | goto end 48 | ) 49 | 50 | 51 | REM Check if sphinx-build is available and fallback to Python version if any 52 | %SPHINXBUILD% 1>NUL 2>NUL 53 | if errorlevel 9009 goto sphinx_python 54 | goto sphinx_ok 55 | 56 | :sphinx_python 57 | 58 | set SPHINXBUILD=python -m sphinx.__init__ 59 | %SPHINXBUILD% 2> nul 60 | if errorlevel 9009 ( 61 | echo. 62 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 63 | echo.installed, then set the SPHINXBUILD environment variable to point 64 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 65 | echo.may add the Sphinx directory to PATH. 66 | echo. 67 | echo.If you don't have Sphinx installed, grab it from 68 | echo.http://sphinx-doc.org/ 69 | exit /b 1 70 | ) 71 | 72 | :sphinx_ok 73 | 74 | 75 | if "%1" == "html" ( 76 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 77 | if errorlevel 1 exit /b 1 78 | echo. 79 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 80 | goto end 81 | ) 82 | 83 | if "%1" == "dirhtml" ( 84 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 85 | if errorlevel 1 exit /b 1 86 | echo. 87 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 88 | goto end 89 | ) 90 | 91 | if "%1" == "singlehtml" ( 92 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 93 | if errorlevel 1 exit /b 1 94 | echo. 95 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 96 | goto end 97 | ) 98 | 99 | if "%1" == "pickle" ( 100 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 101 | if errorlevel 1 exit /b 1 102 | echo. 103 | echo.Build finished; now you can process the pickle files. 104 | goto end 105 | ) 106 | 107 | if "%1" == "json" ( 108 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 109 | if errorlevel 1 exit /b 1 110 | echo. 111 | echo.Build finished; now you can process the JSON files. 112 | goto end 113 | ) 114 | 115 | if "%1" == "htmlhelp" ( 116 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 117 | if errorlevel 1 exit /b 1 118 | echo. 119 | echo.Build finished; now you can run HTML Help Workshop with the ^ 120 | .hhp project file in %BUILDDIR%/htmlhelp. 121 | goto end 122 | ) 123 | 124 | if "%1" == "qthelp" ( 125 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 129 | .qhcp project file in %BUILDDIR%/qthelp, like this: 130 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\sphinxcontrib-asyncio.qhcp 131 | echo.To view the help file: 132 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\sphinxcontrib-asyncio.ghc 133 | goto end 134 | ) 135 | 136 | if "%1" == "devhelp" ( 137 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 138 | if errorlevel 1 exit /b 1 139 | echo. 140 | echo.Build finished. 141 | goto end 142 | ) 143 | 144 | if "%1" == "epub" ( 145 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 146 | if errorlevel 1 exit /b 1 147 | echo. 148 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 149 | goto end 150 | ) 151 | 152 | if "%1" == "latex" ( 153 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 154 | if errorlevel 1 exit /b 1 155 | echo. 156 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 157 | goto end 158 | ) 159 | 160 | if "%1" == "latexpdf" ( 161 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 162 | cd %BUILDDIR%/latex 163 | make all-pdf 164 | cd %~dp0 165 | echo. 166 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 167 | goto end 168 | ) 169 | 170 | if "%1" == "latexpdfja" ( 171 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 172 | cd %BUILDDIR%/latex 173 | make all-pdf-ja 174 | cd %~dp0 175 | echo. 176 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 177 | goto end 178 | ) 179 | 180 | if "%1" == "text" ( 181 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 182 | if errorlevel 1 exit /b 1 183 | echo. 184 | echo.Build finished. The text files are in %BUILDDIR%/text. 185 | goto end 186 | ) 187 | 188 | if "%1" == "man" ( 189 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 190 | if errorlevel 1 exit /b 1 191 | echo. 192 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 193 | goto end 194 | ) 195 | 196 | if "%1" == "texinfo" ( 197 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 198 | if errorlevel 1 exit /b 1 199 | echo. 200 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 201 | goto end 202 | ) 203 | 204 | if "%1" == "gettext" ( 205 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 206 | if errorlevel 1 exit /b 1 207 | echo. 208 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 209 | goto end 210 | ) 211 | 212 | if "%1" == "changes" ( 213 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 214 | if errorlevel 1 exit /b 1 215 | echo. 216 | echo.The overview file is in %BUILDDIR%/changes. 217 | goto end 218 | ) 219 | 220 | if "%1" == "linkcheck" ( 221 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 222 | if errorlevel 1 exit /b 1 223 | echo. 224 | echo.Link check complete; look for any errors in the above output ^ 225 | or in %BUILDDIR%/linkcheck/output.txt. 226 | goto end 227 | ) 228 | 229 | if "%1" == "doctest" ( 230 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 231 | if errorlevel 1 exit /b 1 232 | echo. 233 | echo.Testing of doctests in the sources finished, look at the ^ 234 | results in %BUILDDIR%/doctest/output.txt. 235 | goto end 236 | ) 237 | 238 | if "%1" == "coverage" ( 239 | %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage 240 | if errorlevel 1 exit /b 1 241 | echo. 242 | echo.Testing of coverage in the sources finished, look at the ^ 243 | results in %BUILDDIR%/coverage/python.txt. 244 | goto end 245 | ) 246 | 247 | if "%1" == "xml" ( 248 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 249 | if errorlevel 1 exit /b 1 250 | echo. 251 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 252 | goto end 253 | ) 254 | 255 | if "%1" == "pseudoxml" ( 256 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 257 | if errorlevel 1 exit /b 1 258 | echo. 259 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 260 | goto end 261 | ) 262 | 263 | :end 264 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import codecs 2 | import os 3 | import re 4 | from setuptools import setup 5 | from setuptools.command.test import test as TestCommand 6 | 7 | with codecs.open(os.path.join(os.path.abspath(os.path.dirname( 8 | __file__)), 'sphinxcontrib', 'asyncio.py'), 'r', 'latin1') as fp: 9 | try: 10 | version = re.findall(r"^__version__ = '([^']+)'\r?$", 11 | fp.read(), re.M)[0] 12 | except IndexError: 13 | raise RuntimeError('Unable to determine version.') 14 | 15 | 16 | install_requires = ['sphinx>=3.0'] 17 | 18 | 19 | def read(f): 20 | return open(os.path.join(os.path.dirname(__file__), f)).read().strip() 21 | 22 | 23 | class PyTest(TestCommand): 24 | user_options = [] 25 | 26 | def run(self): 27 | import subprocess 28 | import sys 29 | errno = subprocess.call([sys.executable, '-m', 'pytest', 'tests']) 30 | raise SystemExit(errno) 31 | 32 | 33 | tests_require = install_requires + ['pytest'] 34 | 35 | 36 | setup( 37 | name='sphinxcontrib-asyncio', 38 | version=version, 39 | description=('sphinx extension to support coroutines in markup'), 40 | long_description='\n\n'.join((read('README.rst'), read('CHANGES.rst'))), 41 | classifiers=[ 42 | 'Environment :: Plugins', 43 | 'Framework :: AsyncIO', 44 | 'Framework :: Sphinx :: Extension', 45 | 'Intended Audience :: Developers', 46 | 'License :: OSI Approved :: Apache Software License', 47 | 'Programming Language :: Python', 48 | 'Programming Language :: Python :: 3', 49 | 'Programming Language :: Python :: 3.5', 50 | 'Programming Language :: Python :: 3.6', 51 | 'Programming Language :: Python :: 3.7', 52 | 'Programming Language :: Python :: 3.8', 53 | 'Programming Language :: Python :: 3.9', 54 | 'Topic :: Documentation :: Sphinx', 55 | 'Topic :: Software Development :: Documentation'], 56 | author='Andrew Svetlov', 57 | author_email='andrew.svetlov@gmail.com', 58 | url='https://github.com/aio-libs/sphinxcontrib-asyncio', 59 | license='Apache 2', 60 | packages=['sphinxcontrib'], 61 | install_requires=install_requires, 62 | tests_require=tests_require, 63 | include_package_data=True, 64 | cmdclass=dict(test=PyTest)) 65 | -------------------------------------------------------------------------------- /sphinxcontrib/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) 2 | -------------------------------------------------------------------------------- /sphinxcontrib/asyncio.py: -------------------------------------------------------------------------------- 1 | from docutils.parsers.rst import directives 2 | from sphinx.domains.python import PyFunction, PyMethod 3 | from sphinx.ext.autodoc import FunctionDocumenter, MethodDocumenter, \ 4 | bool_option 5 | try: 6 | from asyncio import iscoroutinefunction 7 | except ImportError: 8 | def iscoroutinefunction(func): 9 | """Return True if func is a decorated coroutine function.""" 10 | return getattr(func, '_is_coroutine', False) 11 | 12 | __version__ = '0.3.0' 13 | 14 | 15 | def merge_dicts(*dcts): 16 | ret = {} 17 | for d in dcts: 18 | for k, v in d.items(): 19 | ret[k] = v 20 | return ret 21 | 22 | 23 | class PyCoroutineMixin(object): 24 | option_spec = {'coroutine': directives.flag, 25 | 'async-with': directives.flag, 26 | 'async-for': directives.flag} 27 | 28 | def get_signature_prefix(self, sig): 29 | ret = '' 30 | if 'staticmethod' in self.options: 31 | ret += 'staticmethod ' 32 | if 'classmethod' in self.options: 33 | ret += 'classmethod ' 34 | if 'coroutine' in self.options: 35 | coroutine = True 36 | else: 37 | coroutine = ('async-with' not in self.options and 38 | 'async-for' not in self.options) 39 | if coroutine: 40 | ret += 'coroutine ' 41 | if 'async-with' in self.options: 42 | ret += 'async-with ' 43 | if 'async-for' in self.options: 44 | ret += 'async-for ' 45 | return ret 46 | 47 | 48 | class PyCoroutineFunction(PyCoroutineMixin, PyFunction): 49 | option_spec = merge_dicts(PyCoroutineMixin.option_spec, 50 | PyFunction.option_spec) 51 | 52 | def run(self): 53 | self.name = 'py:function' 54 | return super(PyCoroutineFunction, self).run() 55 | 56 | 57 | class PyCoroutineMethod(PyCoroutineMixin, PyMethod): 58 | option_spec = merge_dicts(PyCoroutineMixin.option_spec, 59 | PyMethod.option_spec, 60 | {'staticmethod': directives.flag, 61 | 'classmethod': directives.flag}) 62 | 63 | def run(self): 64 | self.name = 'py:method' 65 | return super(PyCoroutineMethod, self).run() 66 | 67 | 68 | class CoFunctionDocumenter(FunctionDocumenter): 69 | """ 70 | Specialized Documenter subclass for functions and coroutines. 71 | """ 72 | objtype = "cofunction" 73 | directivetype = "cofunction" 74 | priority = 2 75 | option_spec = merge_dicts( 76 | MethodDocumenter.option_spec, 77 | {'async-with': bool_option, 78 | 'async-for': bool_option, 79 | 'coroutine': bool_option 80 | }) 81 | 82 | @classmethod 83 | def can_document_member(cls, member, membername, isattr, parent): 84 | """Called to see if a member can be documented by this documenter.""" 85 | if not super().can_document_member(member, membername, isattr, parent): 86 | return False 87 | return iscoroutinefunction(member) 88 | 89 | def add_directive_header(self, sig): 90 | super().add_directive_header(sig) 91 | sourcename = self.get_sourcename() 92 | if self.options.async_with: 93 | self.add_line(' :async-with:', sourcename) 94 | if self.options.async_for: 95 | self.add_line(' :async-for:', sourcename) 96 | if self.options.coroutine: 97 | self.add_line(' :coroutine:', sourcename) 98 | 99 | 100 | class CoMethodDocumenter(MethodDocumenter): 101 | """ 102 | Specialized Documenter subclass for methods and coroutines. 103 | """ 104 | objtype = "comethod" 105 | priority = 3 # Higher than CoFunctionDocumenter 106 | option_spec = merge_dicts( 107 | MethodDocumenter.option_spec, 108 | {'staticmethod': bool_option, 109 | 'classmethod': bool_option, 110 | 'async-with': bool_option, 111 | 'async-for': bool_option, 112 | 'coroutine': bool_option 113 | }) 114 | 115 | @classmethod 116 | def can_document_member(cls, member, membername, isattr, parent): 117 | """Called to see if a member can be documented by this documenter.""" 118 | if not super().can_document_member(member, membername, isattr, parent): 119 | return False 120 | return iscoroutinefunction(member) 121 | 122 | def import_object(self): 123 | ret = super().import_object() 124 | # Was overridden by method documenter, return to default 125 | self.directivetype = "comethod" 126 | return ret 127 | 128 | def add_directive_header(self, sig): 129 | super().add_directive_header(sig) 130 | sourcename = self.get_sourcename() 131 | if self.options.staticmethod: 132 | self.add_line(' :staticmethod:', sourcename) 133 | if self.options.staticmethod: 134 | self.add_line(' :classmethod:', sourcename) 135 | if self.options.async_with: 136 | self.add_line(' :async-with:', sourcename) 137 | if self.options.async_for: 138 | self.add_line(' :async-for:', sourcename) 139 | if self.options.coroutine: 140 | self.add_line(' :coroutine:', sourcename) 141 | 142 | 143 | def setup(app): 144 | app.add_directive_to_domain('py', 'coroutinefunction', PyCoroutineFunction) 145 | app.add_directive_to_domain('py', 'coroutinemethod', PyCoroutineMethod) 146 | app.add_directive_to_domain('py', 'corofunction', PyCoroutineFunction) 147 | app.add_directive_to_domain('py', 'coromethod', PyCoroutineMethod) 148 | app.add_directive_to_domain('py', 'cofunction', PyCoroutineFunction) 149 | app.add_directive_to_domain('py', 'comethod', PyCoroutineMethod) 150 | 151 | app.add_autodocumenter(CoFunctionDocumenter) 152 | app.add_autodocumenter(CoMethodDocumenter) 153 | return {'version': '1.0', 'parallel_read_safe': True} 154 | --------------------------------------------------------------------------------