markwork 0.1.0.dev0__py3-none-any.whl
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.
- markwork/__init__.py +48 -0
- markwork/engine/__init__.py +65 -0
- markwork/engine/_abs_module.py +44 -0
- markwork/engine/_add_alias_site.py +31 -0
- markwork/engine/_bound_anywhere.py +42 -0
- markwork/engine/_builtin_links.py +67 -0
- markwork/engine/_css_class.py +32 -0
- markwork/engine/_detect_package.py +47 -0
- markwork/engine/_generate.py +35 -0
- markwork/engine/_highlight.py +71 -0
- markwork/engine/_is_stdlib.py +36 -0
- markwork/engine/_line_starts.py +35 -0
- markwork/engine/_merge_tokens.py +36 -0
- markwork/engine/_module_definitions.py +42 -0
- markwork/engine/_nested_bound.py +53 -0
- markwork/engine/_parse_init.py +52 -0
- markwork/engine/_pydocs.py +10 -0
- markwork/engine/_source_docs.py +620 -0
- markwork/engine/_title.py +26 -0
- markwork/engine/_token_html.py +58 -0
- markwork/engine/_top_level_def_lines.py +34 -0
- markwork/engine/_top_level_defs.py +33 -0
- markwork/etc/markwork.css +42 -0
- markwork-0.1.0.dev0.dist-info/METADATA +259 -0
- markwork-0.1.0.dev0.dist-info/RECORD +28 -0
- markwork-0.1.0.dev0.dist-info/WHEEL +5 -0
- markwork-0.1.0.dev0.dist-info/licenses/LICENSE +202 -0
- markwork-0.1.0.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The 'nestedBound' function collects names bound inside a nested scope.
|
|
3
|
+
"""
|
|
4
|
+
# Apache-2.0 license
|
|
5
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
6
|
+
|
|
7
|
+
import ast
|
|
8
|
+
|
|
9
|
+
_SCOPE_NODES = (
|
|
10
|
+
ast.FunctionDef, ast.AsyncFunctionDef, ast.Lambda, ast.ClassDef,
|
|
11
|
+
ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def nestedBound(tree: ast.AST) -> set:
|
|
16
|
+
"""Return the names bound inside a nested scope rather than at module
|
|
17
|
+
scope.
|
|
18
|
+
|
|
19
|
+
A nested scope is a function, lambda, comprehension or class body. A
|
|
20
|
+
module-level name that also turns up here is shadowed somewhere in the
|
|
21
|
+
file, so its uses are left unlinked rather than risk pointing at the
|
|
22
|
+
wrong line.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
tree : ast.AST
|
|
27
|
+
The parsed module.
|
|
28
|
+
|
|
29
|
+
Returns
|
|
30
|
+
-------
|
|
31
|
+
set of str
|
|
32
|
+
Every name bound in a nested scope.
|
|
33
|
+
"""
|
|
34
|
+
names = set()
|
|
35
|
+
|
|
36
|
+
def walk(node: ast.AST, nested: bool) -> None:
|
|
37
|
+
for child in ast.iter_child_nodes(node):
|
|
38
|
+
if nested:
|
|
39
|
+
if isinstance(child, ast.Name) and isinstance(child.ctx, ast.Store):
|
|
40
|
+
names.add(child.id)
|
|
41
|
+
elif isinstance(child, ast.arg):
|
|
42
|
+
names.add(child.arg)
|
|
43
|
+
elif isinstance(
|
|
44
|
+
child, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)
|
|
45
|
+
):
|
|
46
|
+
names.add(child.name)
|
|
47
|
+
elif isinstance(child, (ast.Import, ast.ImportFrom)):
|
|
48
|
+
for alias in child.names:
|
|
49
|
+
names.add(alias.asname or alias.name.split(".")[0])
|
|
50
|
+
walk(child, nested or isinstance(child, _SCOPE_NODES))
|
|
51
|
+
|
|
52
|
+
walk(tree, False)
|
|
53
|
+
return names
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The 'parseInit' function reads a package __init__.py into its public
|
|
3
|
+
re-export mapping.
|
|
4
|
+
"""
|
|
5
|
+
# Apache-2.0 license
|
|
6
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
7
|
+
|
|
8
|
+
import ast
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parseInit(initPath: Path):
|
|
13
|
+
"""Read a package __init__.py into its public names and their sources.
|
|
14
|
+
|
|
15
|
+
Two relative import shapes are understood: 'from . import submodule'
|
|
16
|
+
binds a public name to a child, and 'from .module import Name' binds it
|
|
17
|
+
to a documented symbol. Non-constant __all__ entries and absolute
|
|
18
|
+
imports are passed over.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
initPath : Path
|
|
23
|
+
The __init__.py to read and parse.
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
tuple
|
|
28
|
+
A pair '(allNames, sourceMap)'. 'allNames' is the list of public
|
|
29
|
+
names in __all__. 'sourceMap' maps a public name to either
|
|
30
|
+
'("child", childName)' or '("from", module, origName)'.
|
|
31
|
+
"""
|
|
32
|
+
tree = ast.parse(initPath.read_text(encoding="utf-8"))
|
|
33
|
+
allNames = []
|
|
34
|
+
sourceMap = {}
|
|
35
|
+
for node in tree.body:
|
|
36
|
+
if isinstance(node, ast.Assign):
|
|
37
|
+
isAll = any(
|
|
38
|
+
isinstance(t, ast.Name) and t.id == "__all__"
|
|
39
|
+
for t in node.targets
|
|
40
|
+
)
|
|
41
|
+
if isAll and isinstance(node.value, (ast.List, ast.Tuple)):
|
|
42
|
+
allNames = [e.value for e in node.value.elts
|
|
43
|
+
if isinstance(e, ast.Constant)]
|
|
44
|
+
elif isinstance(node, ast.ImportFrom) and node.level >= 1:
|
|
45
|
+
if node.module is None:
|
|
46
|
+
for alias in node.names:
|
|
47
|
+
sourceMap[alias.asname or alias.name] = ("child", alias.name)
|
|
48
|
+
else:
|
|
49
|
+
for alias in node.names:
|
|
50
|
+
key = alias.asname or alias.name
|
|
51
|
+
sourceMap[key] = ("from", node.module, alias.name)
|
|
52
|
+
return allNames, sourceMap
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The 'PYDOCS' constant is the base URL of the Python documentation that
|
|
3
|
+
every standard-library and builtin link is built against.
|
|
4
|
+
"""
|
|
5
|
+
# Apache-2.0 license
|
|
6
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
7
|
+
|
|
8
|
+
# Pinned to the '3' series so the anchor tables in '_builtin_links' stay
|
|
9
|
+
# valid. The live-anchor test guards against drift on this version.
|
|
10
|
+
PYDOCS = "https://docs.python.org/3/"
|