sphinx-lua 1.1.5__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.5 → sphinx_lua-1.2.1}/PKG-INFO +65 -4
- sphinx-lua-1.1.5/sphinx_lua.egg-info/PKG-INFO → sphinx_lua-1.2.1/README.rst +54 -19
- sphinx_lua-1.2.1/pyproject.toml +7 -0
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/setup.py +10 -7
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/__init__.py +12 -1
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/directives.py +17 -1
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/luadoc.py +5 -1
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/renderers.py +110 -88
- sphinx_lua-1.2.1/sphinx_lua/templates/alias.rst +3 -0
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/templates/class.rst +2 -2
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/templates/function.rst +4 -2
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/templates/method.rst +5 -3
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/templates/module.rst +8 -2
- {sphinx-lua-1.1.5 → 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.5/README.rst → sphinx_lua-1.2.1/sphinx_lua.egg-info/PKG-INFO +80 -1
- {sphinx-lua-1.1.5 → 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.5/sphinx_lua/version.py +0 -1
- sphinx-lua-1.1.5/sphinx_lua.egg-info/requires.txt +0 -4
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/LICENSE.txt +0 -0
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/MANIFEST.in +0 -0
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/setup.cfg +0 -0
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/templates/attribute.rst +0 -0
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/templates/classsummary.rst +0 -0
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua/templates/param_list.rst +0 -0
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua.egg-info/dependency_links.txt +0 -0
- {sphinx-lua-1.1.5 → sphinx_lua-1.2.1}/sphinx_lua.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
|
@@ -9,12 +9,20 @@ Keywords: sphinx,documentation,docs,lua,luadoc,restructured
|
|
|
9
9
|
Classifier: Intended Audience :: Developers
|
|
10
10
|
Classifier: Natural Language :: English
|
|
11
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
16
|
Classifier: Topic :: Documentation :: Sphinx
|
|
16
17
|
Classifier: Topic :: Software Development :: Documentation
|
|
18
|
+
Requires-Python: >=3.9
|
|
17
19
|
License-File: LICENSE.txt
|
|
20
|
+
Requires-Dist: Jinja2>3.0
|
|
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"
|
|
18
26
|
|
|
19
27
|
###############################################################################
|
|
20
28
|
sphinx-lua
|
|
@@ -114,6 +122,59 @@ The following directives are available:
|
|
|
114
122
|
|
|
115
123
|
.. lua:autoclasssummary:: ^pl.
|
|
116
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
|
+
|
|
117
178
|
|
|
118
179
|
You can also use directive provided by ``sphinxcontrib.luadomain``:
|
|
119
180
|
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: sphinx-lua
|
|
3
|
-
Version: 1.1.5
|
|
4
|
-
Summary: Support for using Sphinx on Luadoc-documented Lua code
|
|
5
|
-
Author: Eliott Dumeix
|
|
6
|
-
Author-email: eliott.dumeix@gmail.com
|
|
7
|
-
License: MIT
|
|
8
|
-
Keywords: sphinx,documentation,docs,lua,luadoc,restructured
|
|
9
|
-
Classifier: Intended Audience :: Developers
|
|
10
|
-
Classifier: Natural Language :: English
|
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.5
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
15
|
-
Classifier: Topic :: Documentation :: Sphinx
|
|
16
|
-
Classifier: Topic :: Software Development :: Documentation
|
|
17
|
-
License-File: LICENSE.txt
|
|
18
|
-
|
|
19
1
|
###############################################################################
|
|
20
2
|
sphinx-lua
|
|
21
3
|
###############################################################################
|
|
@@ -114,6 +96,59 @@ The following directives are available:
|
|
|
114
96
|
|
|
115
97
|
.. lua:autoclasssummary:: ^pl.
|
|
116
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
|
+
|
|
117
152
|
|
|
118
153
|
You can also use directive provided by ``sphinxcontrib.luadomain``:
|
|
119
154
|
|
|
@@ -139,4 +174,4 @@ By default, private members are hidden. You can display them by using the flag `
|
|
|
139
174
|
.. code-block:: rst
|
|
140
175
|
|
|
141
176
|
.. lua:autoclass:: pl.List
|
|
142
|
-
:private-members:
|
|
177
|
+
:private-members:
|
|
@@ -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,23 +27,26 @@ 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',
|
|
41
42
|
'License :: OSI Approved :: MIT License',
|
|
42
|
-
'Programming Language :: Python :: 3.
|
|
43
|
-
'Programming Language :: Python :: 3.
|
|
44
|
-
'Programming Language :: Python :: 3.
|
|
43
|
+
'Programming Language :: Python :: 3.9',
|
|
44
|
+
'Programming Language :: Python :: 3.10',
|
|
45
|
+
'Programming Language :: Python :: 3.11',
|
|
46
|
+
'Programming Language :: Python :: 3.12',
|
|
45
47
|
'Topic :: Documentation :: Sphinx',
|
|
46
48
|
'Topic :: Software Development :: Documentation'
|
|
47
49
|
],
|
|
50
|
+
python_requires='>=3.9',
|
|
48
51
|
keywords=['sphinx', 'documentation', 'docs', 'lua', 'luadoc', 'restructured'],
|
|
49
52
|
)
|
|
@@ -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 = []
|
|
@@ -19,7 +23,7 @@ def run_luadoc(app):
|
|
|
19
23
|
else:
|
|
20
24
|
for root, subdirs, files in os.walk(source_dir):
|
|
21
25
|
for filename in files:
|
|
22
|
-
if filename.endswith('lua'):
|
|
26
|
+
if filename.endswith(('lua', 'luadoc')):
|
|
23
27
|
filepath = os.path.join(root, filename)
|
|
24
28
|
filenames.append(filepath)
|
|
25
29
|
|
|
@@ -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,47 +84,81 @@ 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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
120
|
+
file_path = os.path.join(self._app.confdir, file_path)
|
|
121
|
+
with open(file_path, "r") as f:
|
|
122
|
+
content = f.read()
|
|
123
|
+
total_lines = content.count('\n') + 1
|
|
124
|
+
start_line = content[:doc_node.start_char].count('\n') + 1
|
|
125
|
+
stop_line = content[:doc_node.stop_char].count('\n') + 1
|
|
126
|
+
# Clamp to actual file line count (avoid "out of range" with Sphinx -W)
|
|
127
|
+
stop_line = min(stop_line, total_lines)
|
|
86
128
|
return str(start_line) + "-" + str(stop_line)
|
|
87
129
|
|
|
88
130
|
# Render to RST using Jinja:
|
|
89
131
|
env = Environment(loader=PackageLoader('sphinx_lua', 'templates'))
|
|
90
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
|
|
91
135
|
env.filters['start_stop_line'] = start_stop_line
|
|
136
|
+
env.tests['metamethod'] = lambda name: name in KNOWN_LUA_METAMETHODS
|
|
92
137
|
template = env.get_template(self._template)
|
|
93
138
|
return template.render(**args_dict)
|
|
94
139
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return self._arguments[0].split('(')[0]
|
|
140
|
+
class AutoFunctionRenderer(LuaRenderer):
|
|
141
|
+
_template = 'function.rst'
|
|
98
142
|
|
|
99
|
-
def
|
|
100
|
-
"""
|
|
101
|
-
|
|
143
|
+
def rst_nodes(self):
|
|
144
|
+
"""Render a global (non-method, non-static) LUA function."""
|
|
145
|
+
lua_function = None
|
|
102
146
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
|
106
152
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
('exceptions', _exceptions_formatter),
|
|
111
|
-
('returns', _returns_formatter)])
|
|
112
|
-
for field_name, callback in iteritems(FIELD_TYPES):
|
|
113
|
-
for field in doclet.get(field_name, []):
|
|
114
|
-
description = field.get('description', '')
|
|
115
|
-
unwrapped = re.sub(r'[ \t]*[\r\n]+[ \t]*', ' ', description)
|
|
116
|
-
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)
|
|
117
156
|
|
|
157
|
+
rst = self.rst(dict(function=lua_function))
|
|
158
|
+
doc = new_document('%s' % self._partial_path, settings=self._directive.state.document.settings)
|
|
118
159
|
|
|
119
|
-
|
|
120
|
-
|
|
160
|
+
RstParser().parse(rst, doc)
|
|
161
|
+
return doc.children
|
|
121
162
|
|
|
122
163
|
|
|
123
164
|
class AutoClassRenderer(LuaRenderer):
|
|
@@ -157,6 +198,30 @@ class AutoClassRenderer(LuaRenderer):
|
|
|
157
198
|
return doc.children
|
|
158
199
|
|
|
159
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
|
+
|
|
160
225
|
class AutoModuleRenderer(LuaRenderer):
|
|
161
226
|
_template = 'module.rst'
|
|
162
227
|
|
|
@@ -166,25 +231,29 @@ class AutoModuleRenderer(LuaRenderer):
|
|
|
166
231
|
|
|
167
232
|
Fill in args, docstrings, and info fields from stored LUADoc output.
|
|
168
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
|
+
|
|
169
239
|
"""
|
|
170
|
-
|
|
240
|
+
all_modules = self._app._sphinxlua_modules
|
|
171
241
|
|
|
172
|
-
|
|
173
|
-
for module in self._app._sphinxlua_modules:
|
|
174
|
-
if module.name == self._partial_path:
|
|
175
|
-
lua_module = module
|
|
176
|
-
break
|
|
242
|
+
lua_modules = [m for m in all_modules if m.name == self._partial_path]
|
|
177
243
|
|
|
178
|
-
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:
|
|
179
249
|
raise SphinxError('No LUADoc documentation was found for object "%s" or any path ending with that.'
|
|
180
250
|
% self._partial_path)
|
|
181
251
|
|
|
182
|
-
rst =
|
|
183
|
-
name=
|
|
184
|
-
|
|
185
|
-
))
|
|
186
|
-
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))
|
|
187
255
|
|
|
256
|
+
doc = new_document('%s' % self._partial_path, settings=self._directive.state.document.settings)
|
|
188
257
|
RstParser().parse(rst, doc)
|
|
189
258
|
return doc.children
|
|
190
259
|
|
|
@@ -218,50 +287,3 @@ class AutoClassSummaryRenderer(LuaRenderer):
|
|
|
218
287
|
|
|
219
288
|
RstParser().parse(rst, doc)
|
|
220
289
|
return doc.children
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
def _returns_formatter(field, description):
|
|
224
|
-
"""Derive heads and tail from ``@returns`` blocks."""
|
|
225
|
-
types = _or_types(field)
|
|
226
|
-
tail = ('**%s** -- ' % types) if types else ''
|
|
227
|
-
tail += description
|
|
228
|
-
return ['returns'], tail
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
def _params_formatter(field, description):
|
|
232
|
-
"""Derive heads and tail from ``@param`` blocks."""
|
|
233
|
-
heads = ['param']
|
|
234
|
-
types = _or_types(field)
|
|
235
|
-
if types:
|
|
236
|
-
heads.append(types)
|
|
237
|
-
heads.append(rst.escape(field['name']))
|
|
238
|
-
tail = description
|
|
239
|
-
return heads, tail
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def _exceptions_formatter(field, description):
|
|
243
|
-
"""Derive heads and tail from ``@throws`` blocks."""
|
|
244
|
-
heads = ['throws']
|
|
245
|
-
types = _or_types(field)
|
|
246
|
-
if types:
|
|
247
|
-
heads.append(types)
|
|
248
|
-
tail = description
|
|
249
|
-
return heads, tail
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
def _or_types(field):
|
|
253
|
-
"""Return all the types in a doclet subfield like "params" or "returns"
|
|
254
|
-
with vertical bars between them, like "number|string".
|
|
255
|
-
|
|
256
|
-
ReST-escape the types.
|
|
257
|
-
|
|
258
|
-
"""
|
|
259
|
-
return rst.escape('|'.join(field.get('type', {}).get('names', [])))
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
def _dotted_path(segments):
|
|
263
|
-
"""Convert a LUA object path (``['dir/', 'file/', 'class#',
|
|
264
|
-
'instanceMethod']``) to a dotted style that Sphinx will better index."""
|
|
265
|
-
segments_without_separators = [s[:-1] for s in segments[:-1]]
|
|
266
|
-
segments_without_separators.append(segments[-1])
|
|
267
|
-
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,3 +1,29 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: sphinx-lua
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Support for using Sphinx on Luadoc-documented Lua code
|
|
5
|
+
Author: Eliott Dumeix
|
|
6
|
+
Author-email: eliott.dumeix@gmail.com
|
|
7
|
+
License: MIT
|
|
8
|
+
Keywords: sphinx,documentation,docs,lua,luadoc,restructured
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Natural Language :: English
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Documentation :: Sphinx
|
|
17
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
License-File: LICENSE.txt
|
|
20
|
+
Requires-Dist: Jinja2>3.0
|
|
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"
|
|
26
|
+
|
|
1
27
|
###############################################################################
|
|
2
28
|
sphinx-lua
|
|
3
29
|
###############################################################################
|
|
@@ -96,6 +122,59 @@ The following directives are available:
|
|
|
96
122
|
|
|
97
123
|
.. lua:autoclasssummary:: ^pl.
|
|
98
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
|
+
|
|
99
178
|
|
|
100
179
|
You can also use directive provided by ``sphinxcontrib.luadomain``:
|
|
101
180
|
|
|
@@ -121,4 +200,4 @@ By default, private members are hidden. You can display them by using the flag `
|
|
|
121
200
|
.. code-block:: rst
|
|
122
201
|
|
|
123
202
|
.. lua:autoclass:: pl.List
|
|
124
|
-
:private-members:
|
|
203
|
+
:private-members:
|
|
@@ -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.5'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|