sphinx-lua 1.1.6__tar.gz → 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sphinx_lua-1.1.6/sphinx_lua.egg-info → sphinx_lua-1.2.1}/PKG-INFO +60 -15
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/README.rst +53 -0
- sphinx_lua-1.2.1/pyproject.toml +7 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/setup.py +5 -4
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/__init__.py +12 -1
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/directives.py +17 -1
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/luadoc.py +4 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/renderers.py +102 -84
- sphinx_lua-1.2.1/sphinx_lua/templates/alias.rst +3 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/templates/class.rst +2 -2
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/templates/function.rst +4 -2
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/templates/method.rst +5 -3
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/templates/module.rst +8 -2
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/templates/type.rst +1 -1
- sphinx_lua-1.2.1/sphinx_lua/version.py +1 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1/sphinx_lua.egg-info}/PKG-INFO +60 -15
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua.egg-info/SOURCES.txt +2 -0
- sphinx_lua-1.2.1/sphinx_lua.egg-info/requires.txt +7 -0
- sphinx_lua-1.1.6/sphinx_lua/version.py +0 -1
- sphinx_lua-1.1.6/sphinx_lua.egg-info/requires.txt +0 -4
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/LICENSE.txt +0 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/MANIFEST.in +0 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/setup.cfg +0 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/templates/attribute.rst +0 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/templates/classsummary.rst +0 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua/templates/param_list.rst +0 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua.egg-info/dependency_links.txt +0 -0
- {sphinx_lua-1.1.6 → sphinx_lua-1.2.1}/sphinx_lua.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: sphinx-lua
|
|
3
|
-
Version: 1.1
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: Support for using Sphinx on Luadoc-documented Lua code
|
|
5
5
|
Author: Eliott Dumeix
|
|
6
6
|
Author-email: eliott.dumeix@gmail.com
|
|
@@ -17,20 +17,12 @@ Classifier: Topic :: Documentation :: Sphinx
|
|
|
17
17
|
Classifier: Topic :: Software Development :: Documentation
|
|
18
18
|
Requires-Python: >=3.9
|
|
19
19
|
License-File: LICENSE.txt
|
|
20
|
-
Requires-Dist: six
|
|
21
20
|
Requires-Dist: Jinja2>3.0
|
|
22
|
-
Requires-Dist: luadoc>=1.
|
|
23
|
-
Requires-Dist: sphinxcontrib-luadomain>=1.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Dynamic: description
|
|
28
|
-
Dynamic: keywords
|
|
29
|
-
Dynamic: license
|
|
30
|
-
Dynamic: license-file
|
|
31
|
-
Dynamic: requires-dist
|
|
32
|
-
Dynamic: requires-python
|
|
33
|
-
Dynamic: summary
|
|
21
|
+
Requires-Dist: luadoc>=1.4.1
|
|
22
|
+
Requires-Dist: sphinxcontrib-luadomain>=1.2.0
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest; extra == "test"
|
|
25
|
+
Requires-Dist: Sphinx; extra == "test"
|
|
34
26
|
|
|
35
27
|
###############################################################################
|
|
36
28
|
sphinx-lua
|
|
@@ -130,6 +122,59 @@ The following directives are available:
|
|
|
130
122
|
|
|
131
123
|
.. lua:autoclasssummary:: ^pl.
|
|
132
124
|
|
|
125
|
+
.. lua:autoalias:: SourceFn
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
``automodule`` also accepts a regex, documenting every matching module in one
|
|
129
|
+
call, which is handy to generate the whole documentation for everything found
|
|
130
|
+
in ``lua_source_path``:
|
|
131
|
+
|
|
132
|
+
.. code-block:: rst
|
|
133
|
+
|
|
134
|
+
.. lua:automodule:: .*
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
``@alias`` tags are rendered as ``lua:alias`` directives (either standalone via
|
|
138
|
+
``autoalias``, or automatically as part of ``automodule``'s output), and any
|
|
139
|
+
``@param``/``@return``/``@field`` referencing an alias or class by name is
|
|
140
|
+
turned into a link to its definition:
|
|
141
|
+
|
|
142
|
+
.. code-block:: lua
|
|
143
|
+
|
|
144
|
+
---@alias SourceFn fun():string|nil,string|nil
|
|
145
|
+
|
|
146
|
+
---@param callback SourceFn
|
|
147
|
+
local function some_function(callback)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
A method whose name is a known Lua metamethod (``__index``, ``__eq``,
|
|
152
|
+
``__call``, etc., per the Lua 5.4 manual) is automatically rendered with
|
|
153
|
+
``lua:metamethod`` instead of ``lua:method``:
|
|
154
|
+
|
|
155
|
+
.. code-block:: lua
|
|
156
|
+
|
|
157
|
+
---Compare two instances for equality.
|
|
158
|
+
---@param self Class
|
|
159
|
+
---@param other Class
|
|
160
|
+
---@return boolean
|
|
161
|
+
function cls.__eq(self, other)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
Markdown-style fenced code blocks (as commonly used in EmmyLua doc comments)
|
|
166
|
+
in descriptions are rendered as proper, syntax-highlighted code blocks:
|
|
167
|
+
|
|
168
|
+
.. code-block:: lua
|
|
169
|
+
|
|
170
|
+
---Returns 16-bit color.
|
|
171
|
+
---
|
|
172
|
+
---Example:
|
|
173
|
+
---```lua
|
|
174
|
+
---local color = display.color565(255, 0, 0)
|
|
175
|
+
---```
|
|
176
|
+
function display.color565(r, g, b) end
|
|
177
|
+
|
|
133
178
|
|
|
134
179
|
You can also use directive provided by ``sphinxcontrib.luadomain``:
|
|
135
180
|
|
|
@@ -96,6 +96,59 @@ The following directives are available:
|
|
|
96
96
|
|
|
97
97
|
.. lua:autoclasssummary:: ^pl.
|
|
98
98
|
|
|
99
|
+
.. lua:autoalias:: SourceFn
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
``automodule`` also accepts a regex, documenting every matching module in one
|
|
103
|
+
call, which is handy to generate the whole documentation for everything found
|
|
104
|
+
in ``lua_source_path``:
|
|
105
|
+
|
|
106
|
+
.. code-block:: rst
|
|
107
|
+
|
|
108
|
+
.. lua:automodule:: .*
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
``@alias`` tags are rendered as ``lua:alias`` directives (either standalone via
|
|
112
|
+
``autoalias``, or automatically as part of ``automodule``'s output), and any
|
|
113
|
+
``@param``/``@return``/``@field`` referencing an alias or class by name is
|
|
114
|
+
turned into a link to its definition:
|
|
115
|
+
|
|
116
|
+
.. code-block:: lua
|
|
117
|
+
|
|
118
|
+
---@alias SourceFn fun():string|nil,string|nil
|
|
119
|
+
|
|
120
|
+
---@param callback SourceFn
|
|
121
|
+
local function some_function(callback)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
A method whose name is a known Lua metamethod (``__index``, ``__eq``,
|
|
126
|
+
``__call``, etc., per the Lua 5.4 manual) is automatically rendered with
|
|
127
|
+
``lua:metamethod`` instead of ``lua:method``:
|
|
128
|
+
|
|
129
|
+
.. code-block:: lua
|
|
130
|
+
|
|
131
|
+
---Compare two instances for equality.
|
|
132
|
+
---@param self Class
|
|
133
|
+
---@param other Class
|
|
134
|
+
---@return boolean
|
|
135
|
+
function cls.__eq(self, other)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
Markdown-style fenced code blocks (as commonly used in EmmyLua doc comments)
|
|
140
|
+
in descriptions are rendered as proper, syntax-highlighted code blocks:
|
|
141
|
+
|
|
142
|
+
.. code-block:: lua
|
|
143
|
+
|
|
144
|
+
---Returns 16-bit color.
|
|
145
|
+
---
|
|
146
|
+
---Example:
|
|
147
|
+
---```lua
|
|
148
|
+
---local color = display.color565(255, 0, 0)
|
|
149
|
+
---```
|
|
150
|
+
function display.color565(r, g, b) end
|
|
151
|
+
|
|
99
152
|
|
|
100
153
|
You can also use directive provided by ``sphinxcontrib.luadomain``:
|
|
101
154
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
# setuptools>=70 emits Metadata-Version 2.4, which the pypa/gh-action-pypi-publish
|
|
3
|
+
# release action (pinned in .github/workflows/python-publish.yml) fails to parse
|
|
4
|
+
# ("Metadata is missing required fields: Name, Version") even though it is
|
|
5
|
+
# present -- it's a parser mismatch, not actually missing metadata.
|
|
6
|
+
requires = ["setuptools>=61,<70", "wheel"]
|
|
7
|
+
build-backend = "setuptools.build_meta"
|
|
@@ -27,14 +27,15 @@ setup(
|
|
|
27
27
|
license='MIT',
|
|
28
28
|
license_files=('LICENSE.txt',),
|
|
29
29
|
packages=find_packages(exclude=['ez_setup']),
|
|
30
|
-
test_suite='nose.collector',
|
|
31
30
|
include_package_data=True,
|
|
32
31
|
install_requires=[
|
|
33
|
-
'six',
|
|
34
32
|
'Jinja2>3.0',
|
|
35
|
-
'luadoc>=1.
|
|
36
|
-
'sphinxcontrib-luadomain>=1.
|
|
33
|
+
'luadoc>=1.4.1',
|
|
34
|
+
'sphinxcontrib-luadomain>=1.2.0'
|
|
37
35
|
],
|
|
36
|
+
extras_require={
|
|
37
|
+
'test': ['pytest', 'Sphinx'],
|
|
38
|
+
},
|
|
38
39
|
classifiers=[
|
|
39
40
|
'Intended Audience :: Developers',
|
|
40
41
|
'Natural Language :: English',
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from .directives import (auto_class_directive_bound_to_app,
|
|
2
2
|
auto_function_directive_bound_to_app,
|
|
3
3
|
auto_module_directive_bound_to_app,
|
|
4
|
-
auto_class_summary_directive_bound_to_app
|
|
4
|
+
auto_class_summary_directive_bound_to_app,
|
|
5
|
+
auto_alias_directive_bound_to_app)
|
|
5
6
|
from .luadoc import run_luadoc
|
|
7
|
+
from . import version
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
def setup(app):
|
|
@@ -25,6 +27,9 @@ def setup(app):
|
|
|
25
27
|
app.add_directive_to_domain('lua',
|
|
26
28
|
'autoclasssummary',
|
|
27
29
|
auto_class_summary_directive_bound_to_app(app))
|
|
30
|
+
app.add_directive_to_domain('lua',
|
|
31
|
+
'autoalias',
|
|
32
|
+
auto_alias_directive_bound_to_app(app))
|
|
28
33
|
# TODO: We could add a lua:module with app.add_directive_to_domain().
|
|
29
34
|
|
|
30
35
|
app.add_config_value('lua_source_path', ['./'], 'env')
|
|
@@ -34,6 +39,12 @@ def setup(app):
|
|
|
34
39
|
app.add_config_value('lua_source_private_prefix', '_', 'env')
|
|
35
40
|
app.add_config_value('luadoc_config_path', None, 'env')
|
|
36
41
|
|
|
42
|
+
return {
|
|
43
|
+
'version': version.__version__,
|
|
44
|
+
'parallel_read_safe': True,
|
|
45
|
+
'parallel_write_safe': True,
|
|
46
|
+
}
|
|
47
|
+
|
|
37
48
|
|
|
38
49
|
def read_all_docs(app, env, doc_names):
|
|
39
50
|
"""Add all found docs to the to-be-read list, because we have no way of
|
|
@@ -10,7 +10,8 @@ can access each other and collaborate.
|
|
|
10
10
|
from docutils.parsers.rst import Directive
|
|
11
11
|
from docutils.parsers.rst.directives import flag
|
|
12
12
|
|
|
13
|
-
from .renderers import AutoFunctionRenderer, AutoClassRenderer, AutoModuleRenderer, AutoClassSummaryRenderer
|
|
13
|
+
from .renderers import (AutoFunctionRenderer, AutoClassRenderer, AutoModuleRenderer, AutoClassSummaryRenderer,
|
|
14
|
+
AutoAliasRenderer)
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class LuaDirective(Directive):
|
|
@@ -103,6 +104,21 @@ def auto_class_summary_directive_bound_to_app(app):
|
|
|
103
104
|
return AutoClassSummaryDirective
|
|
104
105
|
|
|
105
106
|
|
|
107
|
+
def auto_alias_directive_bound_to_app(app):
|
|
108
|
+
class AutoAliasDirective(LuaDirective):
|
|
109
|
+
"""lua:autoalias directive, which spits out a lua:alias directive
|
|
110
|
+
|
|
111
|
+
Takes a single argument which is the name of an ``@alias``-declared
|
|
112
|
+
type.
|
|
113
|
+
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
def run(self):
|
|
117
|
+
return AutoAliasRenderer.from_directive(self, app).rst_nodes()
|
|
118
|
+
|
|
119
|
+
return AutoAliasDirective
|
|
120
|
+
|
|
121
|
+
|
|
106
122
|
def _members_to_exclude(arg):
|
|
107
123
|
"""Return a set of members to exclude given a comma-delim list them.
|
|
108
124
|
|
|
@@ -10,6 +10,10 @@ def run_luadoc(app):
|
|
|
10
10
|
|
|
11
11
|
modules = []
|
|
12
12
|
for source_dir in app.config.lua_source_path:
|
|
13
|
+
# Resolve relative to confdir, not the process cwd: the build can be
|
|
14
|
+
# invoked from anywhere (e.g. `sphinx-build docs docs/_build` from a
|
|
15
|
+
# repo root, or programmatically), not just from inside confdir.
|
|
16
|
+
source_dir = os.path.join(app.confdir, source_dir)
|
|
13
17
|
logger.debug('building lua documentation model for source dir: ' + source_dir)
|
|
14
18
|
|
|
15
19
|
filenames = []
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from collections import OrderedDict
|
|
2
|
-
from json import dumps
|
|
3
1
|
import re
|
|
4
2
|
import os
|
|
5
3
|
|
|
@@ -7,14 +5,23 @@ from docutils.parsers.rst import Parser as RstParser
|
|
|
7
5
|
from docutils.statemachine import StringList
|
|
8
6
|
from docutils.utils import new_document
|
|
9
7
|
from jinja2 import Environment, PackageLoader
|
|
10
|
-
from six import iteritems, string_types
|
|
11
8
|
from sphinx.errors import SphinxError
|
|
12
|
-
from sphinx.util import rst
|
|
13
9
|
|
|
14
10
|
from sphinx.util import logging
|
|
15
11
|
|
|
16
12
|
logger = logging.getLogger(__name__)
|
|
17
13
|
|
|
14
|
+
# Mirrors sphinxcontrib.luadomain.KNOWN_LUA_METAMETHODS (Lua 5.4 manual,
|
|
15
|
+
# section 2.4). Must stay in sync: luadomain's lua:metamethod directive warns
|
|
16
|
+
# (an error under -W) on any name outside this list.
|
|
17
|
+
KNOWN_LUA_METAMETHODS = frozenset([
|
|
18
|
+
'__add', '__sub', '__mul', '__div', '__mod', '__pow', '__unm', '__idiv',
|
|
19
|
+
'__band', '__bor', '__bxor', '__bnot', '__shl', '__shr',
|
|
20
|
+
'__concat', '__len', '__eq', '__lt', '__le',
|
|
21
|
+
'__index', '__newindex', '__call',
|
|
22
|
+
'__gc', '__close', '__mode', '__name',
|
|
23
|
+
])
|
|
24
|
+
|
|
18
25
|
|
|
19
26
|
class LuaRenderer(object):
|
|
20
27
|
"""Abstract superclass for renderers of various sphinx-lua directives
|
|
@@ -77,6 +84,37 @@ class LuaRenderer(object):
|
|
|
77
84
|
"""A non-optimal implementation of a regex filter"""
|
|
78
85
|
return re.sub(r'@{\s*([\w.]*)\s*}', r':lua:class:`\1`', s)
|
|
79
86
|
|
|
87
|
+
def render_code_fences(s):
|
|
88
|
+
"""Turn Markdown fenced code blocks (```lang\\ncode\\n```), as
|
|
89
|
+
commonly found in EmmyLua doc comments, into RST code-block
|
|
90
|
+
directives so they render instead of showing up as literal text.
|
|
91
|
+
|
|
92
|
+
"""
|
|
93
|
+
def repl(match):
|
|
94
|
+
language = match.group(1) or 'lua'
|
|
95
|
+
code = match.group(2)
|
|
96
|
+
indented = '\n'.join(' ' + line if line.strip() else ''
|
|
97
|
+
for line in code.splitlines())
|
|
98
|
+
return '\n\n.. code-block:: %s\n\n%s\n\n' % (language, indented)
|
|
99
|
+
|
|
100
|
+
return re.sub(r'```(\w*)\n(.*?)```', repl, s, flags=re.DOTALL)
|
|
101
|
+
|
|
102
|
+
def link_custom_type(name):
|
|
103
|
+
"""Turn a custom type name into a cross-reference if it matches a
|
|
104
|
+
known class or alias, so params/returns using ``@alias``-defined
|
|
105
|
+
types link to their definition. Falls back to plain text for
|
|
106
|
+
unknown names to avoid emitting dangling cross-references.
|
|
107
|
+
|
|
108
|
+
"""
|
|
109
|
+
for module in getattr(self._app, '_sphinxlua_modules', []):
|
|
110
|
+
for alias in getattr(module, 'aliases', []):
|
|
111
|
+
if alias.name == name:
|
|
112
|
+
return ':lua:alias:`%s`' % name
|
|
113
|
+
for cls in module.classes:
|
|
114
|
+
if cls.name == name:
|
|
115
|
+
return ':lua:class:`%s`' % name
|
|
116
|
+
return name
|
|
117
|
+
|
|
80
118
|
def start_stop_line(doc_node, file_path):
|
|
81
119
|
""" Return start stop line in the form '1-5' """
|
|
82
120
|
file_path = os.path.join(self._app.confdir, file_path)
|
|
@@ -92,36 +130,35 @@ class LuaRenderer(object):
|
|
|
92
130
|
# Render to RST using Jinja:
|
|
93
131
|
env = Environment(loader=PackageLoader('sphinx_lua', 'templates'))
|
|
94
132
|
env.filters['process_link'] = process_link
|
|
133
|
+
env.filters['link_custom_type'] = link_custom_type
|
|
134
|
+
env.filters['render_code_fences'] = render_code_fences
|
|
95
135
|
env.filters['start_stop_line'] = start_stop_line
|
|
136
|
+
env.tests['metamethod'] = lambda name: name in KNOWN_LUA_METAMETHODS
|
|
96
137
|
template = env.get_template(self._template)
|
|
97
138
|
return template.render(**args_dict)
|
|
98
139
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return self._arguments[0].split('(')[0]
|
|
140
|
+
class AutoFunctionRenderer(LuaRenderer):
|
|
141
|
+
_template = 'function.rst'
|
|
102
142
|
|
|
103
|
-
def
|
|
104
|
-
"""
|
|
105
|
-
|
|
143
|
+
def rst_nodes(self):
|
|
144
|
+
"""Render a global (non-method, non-static) LUA function."""
|
|
145
|
+
lua_function = None
|
|
106
146
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
147
|
+
for module in self._app._sphinxlua_modules:
|
|
148
|
+
for func in module.functions:
|
|
149
|
+
if func.name == self._partial_path:
|
|
150
|
+
lua_function = func
|
|
151
|
+
break
|
|
110
152
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
('exceptions', _exceptions_formatter),
|
|
115
|
-
('returns', _returns_formatter)])
|
|
116
|
-
for field_name, callback in iteritems(FIELD_TYPES):
|
|
117
|
-
for field in doclet.get(field_name, []):
|
|
118
|
-
description = field.get('description', '')
|
|
119
|
-
unwrapped = re.sub(r'[ \t]*[\r\n]+[ \t]*', ' ', description)
|
|
120
|
-
yield callback(field, unwrapped)
|
|
153
|
+
if not lua_function:
|
|
154
|
+
raise SphinxError('No LUADoc documentation was found for object "%s" or any path ending with that.'
|
|
155
|
+
% self._partial_path)
|
|
121
156
|
|
|
157
|
+
rst = self.rst(dict(function=lua_function))
|
|
158
|
+
doc = new_document('%s' % self._partial_path, settings=self._directive.state.document.settings)
|
|
122
159
|
|
|
123
|
-
|
|
124
|
-
|
|
160
|
+
RstParser().parse(rst, doc)
|
|
161
|
+
return doc.children
|
|
125
162
|
|
|
126
163
|
|
|
127
164
|
class AutoClassRenderer(LuaRenderer):
|
|
@@ -161,6 +198,30 @@ class AutoClassRenderer(LuaRenderer):
|
|
|
161
198
|
return doc.children
|
|
162
199
|
|
|
163
200
|
|
|
201
|
+
class AutoAliasRenderer(LuaRenderer):
|
|
202
|
+
_template = 'alias.rst'
|
|
203
|
+
|
|
204
|
+
def rst_nodes(self):
|
|
205
|
+
"""Render an ``@alias``-declared type as a ``lua:alias`` directive."""
|
|
206
|
+
lua_alias = None
|
|
207
|
+
|
|
208
|
+
for module in self._app._sphinxlua_modules:
|
|
209
|
+
for alias in getattr(module, 'aliases', []):
|
|
210
|
+
if alias.name == self._partial_path:
|
|
211
|
+
lua_alias = alias
|
|
212
|
+
break
|
|
213
|
+
|
|
214
|
+
if not lua_alias:
|
|
215
|
+
raise SphinxError('No LUADoc documentation was found for object "%s" or any path ending with that.'
|
|
216
|
+
% self._partial_path)
|
|
217
|
+
|
|
218
|
+
rst = self.rst(dict(model=lua_alias))
|
|
219
|
+
doc = new_document('%s' % self._partial_path, settings=self._directive.state.document.settings)
|
|
220
|
+
|
|
221
|
+
RstParser().parse(rst, doc)
|
|
222
|
+
return doc.children
|
|
223
|
+
|
|
224
|
+
|
|
164
225
|
class AutoModuleRenderer(LuaRenderer):
|
|
165
226
|
_template = 'module.rst'
|
|
166
227
|
|
|
@@ -170,25 +231,29 @@ class AutoModuleRenderer(LuaRenderer):
|
|
|
170
231
|
|
|
171
232
|
Fill in args, docstrings, and info fields from stored LUADoc output.
|
|
172
233
|
|
|
234
|
+
An exact module name is looked up first. If none matches, the argument
|
|
235
|
+
is treated as a regex pattern and every module whose name matches it is
|
|
236
|
+
rendered, allowing e.g. ``.. lua:automodule:: .*`` to document every
|
|
237
|
+
module found in ``lua_source_path`` in one shot.
|
|
238
|
+
|
|
173
239
|
"""
|
|
174
|
-
|
|
240
|
+
all_modules = self._app._sphinxlua_modules
|
|
175
241
|
|
|
176
|
-
|
|
177
|
-
for module in self._app._sphinxlua_modules:
|
|
178
|
-
if module.name == self._partial_path:
|
|
179
|
-
lua_module = module
|
|
180
|
-
break
|
|
242
|
+
lua_modules = [m for m in all_modules if m.name == self._partial_path]
|
|
181
243
|
|
|
182
|
-
if not
|
|
244
|
+
if not lua_modules:
|
|
245
|
+
pattern = re.compile(self._partial_path)
|
|
246
|
+
lua_modules = [m for m in all_modules if pattern.match(m.name)]
|
|
247
|
+
|
|
248
|
+
if not lua_modules:
|
|
183
249
|
raise SphinxError('No LUADoc documentation was found for object "%s" or any path ending with that.'
|
|
184
250
|
% self._partial_path)
|
|
185
251
|
|
|
186
|
-
rst =
|
|
187
|
-
name=
|
|
188
|
-
|
|
189
|
-
))
|
|
190
|
-
doc = new_document('%s' % self._partial_path, settings=self._directive.state.document.settings)
|
|
252
|
+
rst = '\n\n'.join(
|
|
253
|
+
self.rst(dict(name=lua_module.name, module=lua_module))
|
|
254
|
+
for lua_module in sorted(lua_modules, key=lambda m: m.name))
|
|
191
255
|
|
|
256
|
+
doc = new_document('%s' % self._partial_path, settings=self._directive.state.document.settings)
|
|
192
257
|
RstParser().parse(rst, doc)
|
|
193
258
|
return doc.children
|
|
194
259
|
|
|
@@ -222,50 +287,3 @@ class AutoClassSummaryRenderer(LuaRenderer):
|
|
|
222
287
|
|
|
223
288
|
RstParser().parse(rst, doc)
|
|
224
289
|
return doc.children
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
def _returns_formatter(field, description):
|
|
228
|
-
"""Derive heads and tail from ``@returns`` blocks."""
|
|
229
|
-
types = _or_types(field)
|
|
230
|
-
tail = ('**%s** -- ' % types) if types else ''
|
|
231
|
-
tail += description
|
|
232
|
-
return ['returns'], tail
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
def _params_formatter(field, description):
|
|
236
|
-
"""Derive heads and tail from ``@param`` blocks."""
|
|
237
|
-
heads = ['param']
|
|
238
|
-
types = _or_types(field)
|
|
239
|
-
if types:
|
|
240
|
-
heads.append(types)
|
|
241
|
-
heads.append(rst.escape(field['name']))
|
|
242
|
-
tail = description
|
|
243
|
-
return heads, tail
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
def _exceptions_formatter(field, description):
|
|
247
|
-
"""Derive heads and tail from ``@throws`` blocks."""
|
|
248
|
-
heads = ['throws']
|
|
249
|
-
types = _or_types(field)
|
|
250
|
-
if types:
|
|
251
|
-
heads.append(types)
|
|
252
|
-
tail = description
|
|
253
|
-
return heads, tail
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
def _or_types(field):
|
|
257
|
-
"""Return all the types in a doclet subfield like "params" or "returns"
|
|
258
|
-
with vertical bars between them, like "number|string".
|
|
259
|
-
|
|
260
|
-
ReST-escape the types.
|
|
261
|
-
|
|
262
|
-
"""
|
|
263
|
-
return rst.escape('|'.join(field.get('type', {}).get('names', [])))
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
def _dotted_path(segments):
|
|
267
|
-
"""Convert a LUA object path (``['dir/', 'file/', 'class#',
|
|
268
|
-
'instanceMethod']``) to a dotted style that Sphinx will better index."""
|
|
269
|
-
segments_without_separators = [s[:-1] for s in segments[:-1]]
|
|
270
|
-
segments_without_separators.append(segments[-1])
|
|
271
|
-
return '.'.join(segments_without_separators)
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
{%- filter indent(width=4) %}
|
|
11
11
|
|
|
12
12
|
{% if model.short_desc -%}
|
|
13
|
-
{{ model.short_desc | process_link }}
|
|
13
|
+
{{ model.short_desc | render_code_fences | process_link }}
|
|
14
14
|
{% endif %}
|
|
15
15
|
{% if model.desc -%}
|
|
16
|
-
{{ model.desc | process_link }}
|
|
16
|
+
{{ model.desc | render_code_fences | process_link }}
|
|
17
17
|
{%- endif %}
|
|
18
18
|
{% if model.usage %}
|
|
19
19
|
**Usage:**
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
.. lua:function::
|
|
2
2
|
{{- " " + function.name }}({%- include "param_list.rst" %})
|
|
3
|
+
{# reset stale module context when rendered outside automodule -#}
|
|
4
|
+
{% if not module %}:module:{%- endif %}
|
|
3
5
|
{%- filter indent(width=4) %}
|
|
4
6
|
|
|
5
7
|
{% if function.short_desc -%}
|
|
6
|
-
{{ function.short_desc | process_link }}
|
|
8
|
+
{{ function.short_desc | render_code_fences | process_link }}
|
|
7
9
|
{% endif %}
|
|
8
10
|
{% if function.desc -%}
|
|
9
|
-
{{ function.desc | process_link }}
|
|
11
|
+
{{ function.desc | render_code_fences | process_link }}
|
|
10
12
|
{%- endif %}
|
|
11
13
|
|
|
12
14
|
{% for param in function.params -%}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
{%- if method.
|
|
1
|
+
{%- if method.name is metamethod -%}
|
|
2
|
+
.. lua:metamethod::
|
|
3
|
+
{%- elif method.is_static -%}
|
|
2
4
|
.. lua:staticmethod::
|
|
3
5
|
{%- else -%}
|
|
4
6
|
.. lua:method::
|
|
@@ -19,10 +21,10 @@
|
|
|
19
21
|
{%- endif %}
|
|
20
22
|
|
|
21
23
|
{% if method.short_desc -%}
|
|
22
|
-
{{ method.short_desc | process_link }}
|
|
24
|
+
{{ method.short_desc | render_code_fences | process_link }}
|
|
23
25
|
{% endif %}
|
|
24
26
|
{% if method.desc -%}
|
|
25
|
-
{{ method.desc | process_link }}
|
|
27
|
+
{{ method.desc | render_code_fences | process_link }}
|
|
26
28
|
{%- endif %}
|
|
27
29
|
|
|
28
30
|
{% for param in method.params -%}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
.. lua:module:: {{ module.name }}
|
|
2
2
|
|
|
3
|
-
{{ module.short_desc|process_link if module.short_desc }}
|
|
3
|
+
{{ module.short_desc|render_code_fences|process_link if module.short_desc }}
|
|
4
4
|
|
|
5
|
-
{{ module.desc|process_link if module.desc }}
|
|
5
|
+
{{ module.desc|render_code_fences|process_link if module.desc }}
|
|
6
6
|
|
|
7
7
|
{% if module.usage -%}
|
|
8
8
|
**Usage:**
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
{{ module.usage|indent(4) }}
|
|
14
14
|
{%- endif %}
|
|
15
15
|
|
|
16
|
+
{% for alias in module.aliases %}
|
|
17
|
+
{% with model=alias %}
|
|
18
|
+
{% include "alias.rst" %}
|
|
19
|
+
{% endwith %}
|
|
20
|
+
{% endfor %}
|
|
21
|
+
|
|
16
22
|
{% for function in module.functions %}
|
|
17
23
|
{% include "function.rst" %}
|
|
18
24
|
{% endfor %}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '1.2.1'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: sphinx-lua
|
|
3
|
-
Version: 1.1
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: Support for using Sphinx on Luadoc-documented Lua code
|
|
5
5
|
Author: Eliott Dumeix
|
|
6
6
|
Author-email: eliott.dumeix@gmail.com
|
|
@@ -17,20 +17,12 @@ Classifier: Topic :: Documentation :: Sphinx
|
|
|
17
17
|
Classifier: Topic :: Software Development :: Documentation
|
|
18
18
|
Requires-Python: >=3.9
|
|
19
19
|
License-File: LICENSE.txt
|
|
20
|
-
Requires-Dist: six
|
|
21
20
|
Requires-Dist: Jinja2>3.0
|
|
22
|
-
Requires-Dist: luadoc>=1.
|
|
23
|
-
Requires-Dist: sphinxcontrib-luadomain>=1.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Dynamic: description
|
|
28
|
-
Dynamic: keywords
|
|
29
|
-
Dynamic: license
|
|
30
|
-
Dynamic: license-file
|
|
31
|
-
Dynamic: requires-dist
|
|
32
|
-
Dynamic: requires-python
|
|
33
|
-
Dynamic: summary
|
|
21
|
+
Requires-Dist: luadoc>=1.4.1
|
|
22
|
+
Requires-Dist: sphinxcontrib-luadomain>=1.2.0
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest; extra == "test"
|
|
25
|
+
Requires-Dist: Sphinx; extra == "test"
|
|
34
26
|
|
|
35
27
|
###############################################################################
|
|
36
28
|
sphinx-lua
|
|
@@ -130,6 +122,59 @@ The following directives are available:
|
|
|
130
122
|
|
|
131
123
|
.. lua:autoclasssummary:: ^pl.
|
|
132
124
|
|
|
125
|
+
.. lua:autoalias:: SourceFn
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
``automodule`` also accepts a regex, documenting every matching module in one
|
|
129
|
+
call, which is handy to generate the whole documentation for everything found
|
|
130
|
+
in ``lua_source_path``:
|
|
131
|
+
|
|
132
|
+
.. code-block:: rst
|
|
133
|
+
|
|
134
|
+
.. lua:automodule:: .*
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
``@alias`` tags are rendered as ``lua:alias`` directives (either standalone via
|
|
138
|
+
``autoalias``, or automatically as part of ``automodule``'s output), and any
|
|
139
|
+
``@param``/``@return``/``@field`` referencing an alias or class by name is
|
|
140
|
+
turned into a link to its definition:
|
|
141
|
+
|
|
142
|
+
.. code-block:: lua
|
|
143
|
+
|
|
144
|
+
---@alias SourceFn fun():string|nil,string|nil
|
|
145
|
+
|
|
146
|
+
---@param callback SourceFn
|
|
147
|
+
local function some_function(callback)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
A method whose name is a known Lua metamethod (``__index``, ``__eq``,
|
|
152
|
+
``__call``, etc., per the Lua 5.4 manual) is automatically rendered with
|
|
153
|
+
``lua:metamethod`` instead of ``lua:method``:
|
|
154
|
+
|
|
155
|
+
.. code-block:: lua
|
|
156
|
+
|
|
157
|
+
---Compare two instances for equality.
|
|
158
|
+
---@param self Class
|
|
159
|
+
---@param other Class
|
|
160
|
+
---@return boolean
|
|
161
|
+
function cls.__eq(self, other)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
Markdown-style fenced code blocks (as commonly used in EmmyLua doc comments)
|
|
166
|
+
in descriptions are rendered as proper, syntax-highlighted code blocks:
|
|
167
|
+
|
|
168
|
+
.. code-block:: lua
|
|
169
|
+
|
|
170
|
+
---Returns 16-bit color.
|
|
171
|
+
---
|
|
172
|
+
---Example:
|
|
173
|
+
---```lua
|
|
174
|
+
---local color = display.color565(255, 0, 0)
|
|
175
|
+
---```
|
|
176
|
+
function display.color565(r, g, b) end
|
|
177
|
+
|
|
133
178
|
|
|
134
179
|
You can also use directive provided by ``sphinxcontrib.luadomain``:
|
|
135
180
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
LICENSE.txt
|
|
2
2
|
MANIFEST.in
|
|
3
3
|
README.rst
|
|
4
|
+
pyproject.toml
|
|
4
5
|
setup.cfg
|
|
5
6
|
setup.py
|
|
6
7
|
sphinx_lua/__init__.py
|
|
@@ -13,6 +14,7 @@ sphinx_lua.egg-info/SOURCES.txt
|
|
|
13
14
|
sphinx_lua.egg-info/dependency_links.txt
|
|
14
15
|
sphinx_lua.egg-info/requires.txt
|
|
15
16
|
sphinx_lua.egg-info/top_level.txt
|
|
17
|
+
sphinx_lua/templates/alias.rst
|
|
16
18
|
sphinx_lua/templates/attribute.rst
|
|
17
19
|
sphinx_lua/templates/class.rst
|
|
18
20
|
sphinx_lua/templates/classsummary.rst
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '1.1.6'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|