3tears-agent-knowledge 0.14.0__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.
- 3tears_agent_knowledge-0.14.0/.gitignore +216 -0
- 3tears_agent_knowledge-0.14.0/LICENSE +21 -0
- 3tears_agent_knowledge-0.14.0/PKG-INFO +36 -0
- 3tears_agent_knowledge-0.14.0/README.md +9 -0
- 3tears_agent_knowledge-0.14.0/pyproject.toml +47 -0
- 3tears_agent_knowledge-0.14.0/src/threetears/agent/knowledge/__init__.py +105 -0
- 3tears_agent_knowledge-0.14.0/src/threetears/agent/knowledge/collections.py +676 -0
- 3tears_agent_knowledge-0.14.0/src/threetears/agent/knowledge/entities.py +46 -0
- 3tears_agent_knowledge-0.14.0/src/threetears/agent/knowledge/integration.py +426 -0
- 3tears_agent_knowledge-0.14.0/src/threetears/agent/knowledge/middleware.py +1096 -0
- 3tears_agent_knowledge-0.14.0/src/threetears/agent/knowledge/py.typed +0 -0
- 3tears_agent_knowledge-0.14.0/tests/test_collections.py +251 -0
- 3tears_agent_knowledge-0.14.0/tests/test_integration.py +198 -0
- 3tears_agent_knowledge-0.14.0/tests/test_knowledge_injection_middleware.py +549 -0
- 3tears_agent_knowledge-0.14.0/tests/test_lazy_init.py +81 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
|
|
209
|
+
# Claude Code local state
|
|
210
|
+
.claude/
|
|
211
|
+
|
|
212
|
+
# prawduct session evidence (local governance artifacts, never shipped)
|
|
213
|
+
.prawduct/
|
|
214
|
+
|
|
215
|
+
# macOS folder metadata
|
|
216
|
+
.DS_Store
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark Pace
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: 3tears-agent-knowledge
|
|
3
|
+
Version: 0.14.0
|
|
4
|
+
Summary: Governed-knowledge retrieval + injection for LLM agents -- concepts, playbook entries, three-scope shadow merge, and before_model middleware
|
|
5
|
+
Project-URL: Repository, https://github.com/pacepace/3tears
|
|
6
|
+
Author: pace
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Framework :: AsyncIO
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.14
|
|
18
|
+
Requires-Dist: 3tears
|
|
19
|
+
Requires-Dist: 3tears-agent-acl
|
|
20
|
+
Requires-Dist: 3tears-agent-memory
|
|
21
|
+
Requires-Dist: 3tears-langgraph
|
|
22
|
+
Requires-Dist: 3tears-nats
|
|
23
|
+
Requires-Dist: 3tears-observe
|
|
24
|
+
Requires-Dist: langchain-core
|
|
25
|
+
Requires-Dist: pgvector
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# 3tears-agent-knowledge
|
|
29
|
+
|
|
30
|
+
Agent-side governed-knowledge read stack for LangGraph agents.
|
|
31
|
+
|
|
32
|
+
Homes the playbook-entry / concept collections (over the platform RBAC proxy), the
|
|
33
|
+
`KnowledgeIntegration` wiring, and the `create_agent` `before_model` injection
|
|
34
|
+
middleware, on top of the shared three-scope shadow-merge authority in
|
|
35
|
+
`threetears.knowledge` (core). It lives in its own package because the collections
|
|
36
|
+
depend on `threetears.agent.acl`, which core cannot depend on.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# 3tears-agent-knowledge
|
|
2
|
+
|
|
3
|
+
Agent-side governed-knowledge read stack for LangGraph agents.
|
|
4
|
+
|
|
5
|
+
Homes the playbook-entry / concept collections (over the platform RBAC proxy), the
|
|
6
|
+
`KnowledgeIntegration` wiring, and the `create_agent` `before_model` injection
|
|
7
|
+
middleware, on top of the shared three-scope shadow-merge authority in
|
|
8
|
+
`threetears.knowledge` (core). It lives in its own package because the collections
|
|
9
|
+
depend on `threetears.agent.acl`, which core cannot depend on.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "3tears-agent-knowledge"
|
|
7
|
+
version = "0.14.0"
|
|
8
|
+
description = "Governed-knowledge retrieval + injection for LLM agents -- concepts, playbook entries, three-scope shadow merge, and before_model middleware"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.14"
|
|
11
|
+
authors = [{name = "pace"}]
|
|
12
|
+
license = "MIT"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Framework :: AsyncIO",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
21
|
+
"Topic :: Software Development :: Libraries",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"3tears",
|
|
26
|
+
"3tears-agent-acl",
|
|
27
|
+
"3tears-agent-memory",
|
|
28
|
+
"3tears-langgraph",
|
|
29
|
+
"3tears-nats",
|
|
30
|
+
"3tears-observe",
|
|
31
|
+
"pgvector",
|
|
32
|
+
"langchain-core",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Repository = "https://github.com/pacepace/3tears"
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.wheel]
|
|
39
|
+
packages = ["src/threetears"]
|
|
40
|
+
|
|
41
|
+
[tool.uv.sources]
|
|
42
|
+
3tears = { workspace = true }
|
|
43
|
+
3tears-agent-acl = { workspace = true }
|
|
44
|
+
3tears-agent-memory = { workspace = true }
|
|
45
|
+
3tears-langgraph = { workspace = true }
|
|
46
|
+
3tears-nats = { workspace = true }
|
|
47
|
+
3tears-observe = { workspace = true }
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""3tears-agent-knowledge: governed-knowledge retrieval + injection for LangGraph agents.
|
|
2
|
+
|
|
3
|
+
Homes the agent-side knowledge read stack -- the playbook-entry / concept
|
|
4
|
+
collections over the platform RBAC proxy, the ``KnowledgeIntegration`` wiring, and
|
|
5
|
+
the ``create_agent`` ``wrap_model_call`` injection middleware -- on top of the shared
|
|
6
|
+
three-scope merge authority in :mod:`threetears.knowledge` (core). This package
|
|
7
|
+
exists because the collections need :mod:`threetears.agent.acl`, which core (where
|
|
8
|
+
``threetears.knowledge`` lives) cannot depend on.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
# Version derived from pyproject.toml so the metadata is the single source of
|
|
14
|
+
# truth -- a future release that bumps pyproject without updating ``__init__.py``
|
|
15
|
+
# can't drift the runtime ``__version__``. The except guard handles the rare case
|
|
16
|
+
# where the package isn't installed via importlib.metadata (e.g. running directly
|
|
17
|
+
# from a checked-out source tree without ``uv sync``); the fallback keeps imports
|
|
18
|
+
# working but reports ``unknown`` rather than crashing.
|
|
19
|
+
from importlib.metadata import PackageNotFoundError as _PackageNotFoundError
|
|
20
|
+
from importlib.metadata import version as _version
|
|
21
|
+
from typing import TYPE_CHECKING
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
__version__ = _version("3tears-agent-knowledge")
|
|
25
|
+
except _PackageNotFoundError: # pragma: no cover - dev fallback
|
|
26
|
+
__version__ = "unknown"
|
|
27
|
+
|
|
28
|
+
# lazy public API (PEP 562). the package namespace no longer imports its
|
|
29
|
+
# implementation modules eagerly: importing this package (or any of its
|
|
30
|
+
# submodules) costs only this file, and each public attribute resolves its
|
|
31
|
+
# defining module on first access. the TYPE_CHECKING block carries the real
|
|
32
|
+
# imports so mypy and IDEs see the full statically-typed API; the _LAZY map is the
|
|
33
|
+
# runtime equivalent. the three-way agreement between __all__, _LAZY, and the
|
|
34
|
+
# TYPE_CHECKING block is pinned by the package's lazy-surface consistency test.
|
|
35
|
+
if TYPE_CHECKING:
|
|
36
|
+
from threetears.agent.knowledge.collections import (
|
|
37
|
+
ConceptCollection,
|
|
38
|
+
PlaybookEntryCollection,
|
|
39
|
+
)
|
|
40
|
+
from threetears.agent.knowledge.entities import ConceptEntity, PlaybookEntryEntity
|
|
41
|
+
from threetears.agent.knowledge.integration import (
|
|
42
|
+
DraftView,
|
|
43
|
+
KnowledgeIntegration,
|
|
44
|
+
retrieve_concepts,
|
|
45
|
+
retrieve_entries,
|
|
46
|
+
scope_context_admitted_scopes,
|
|
47
|
+
)
|
|
48
|
+
from threetears.agent.knowledge.middleware import KnowledgeInjectionMiddleware
|
|
49
|
+
|
|
50
|
+
# public attribute -> (defining module, attribute name in that module)
|
|
51
|
+
_LAZY: dict[str, tuple[str, str]] = {
|
|
52
|
+
"ConceptCollection": ("threetears.agent.knowledge.collections", "ConceptCollection"),
|
|
53
|
+
"ConceptEntity": ("threetears.agent.knowledge.entities", "ConceptEntity"),
|
|
54
|
+
"DraftView": ("threetears.agent.knowledge.integration", "DraftView"),
|
|
55
|
+
"KnowledgeInjectionMiddleware": ("threetears.agent.knowledge.middleware", "KnowledgeInjectionMiddleware"),
|
|
56
|
+
"KnowledgeIntegration": ("threetears.agent.knowledge.integration", "KnowledgeIntegration"),
|
|
57
|
+
"PlaybookEntryCollection": ("threetears.agent.knowledge.collections", "PlaybookEntryCollection"),
|
|
58
|
+
"PlaybookEntryEntity": ("threetears.agent.knowledge.entities", "PlaybookEntryEntity"),
|
|
59
|
+
"retrieve_concepts": ("threetears.agent.knowledge.integration", "retrieve_concepts"),
|
|
60
|
+
"retrieve_entries": ("threetears.agent.knowledge.integration", "retrieve_entries"),
|
|
61
|
+
"scope_context_admitted_scopes": ("threetears.agent.knowledge.integration", "scope_context_admitted_scopes"),
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
__all__ = [
|
|
65
|
+
"ConceptCollection",
|
|
66
|
+
"ConceptEntity",
|
|
67
|
+
"DraftView",
|
|
68
|
+
"KnowledgeInjectionMiddleware",
|
|
69
|
+
"KnowledgeIntegration",
|
|
70
|
+
"PlaybookEntryCollection",
|
|
71
|
+
"PlaybookEntryEntity",
|
|
72
|
+
"retrieve_concepts",
|
|
73
|
+
"retrieve_entries",
|
|
74
|
+
"scope_context_admitted_scopes",
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def __getattr__(name: str) -> object:
|
|
79
|
+
"""resolve a public attribute from its defining module on first access.
|
|
80
|
+
|
|
81
|
+
:param name: attribute name being resolved
|
|
82
|
+
:ptype name: str
|
|
83
|
+
:return: the resolved attribute (also cached in module globals so
|
|
84
|
+
``__getattr__`` fires at most once per name)
|
|
85
|
+
:rtype: object
|
|
86
|
+
:raises AttributeError: when ``name`` is not part of the public API
|
|
87
|
+
"""
|
|
88
|
+
entry = _LAZY.get(name)
|
|
89
|
+
if entry is None:
|
|
90
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
91
|
+
from importlib import import_module
|
|
92
|
+
|
|
93
|
+
module_name, attr = entry
|
|
94
|
+
value: object = getattr(import_module(module_name), attr)
|
|
95
|
+
globals()[name] = value
|
|
96
|
+
return value
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def __dir__() -> list[str]:
|
|
100
|
+
"""include lazy attributes in ``dir()`` output.
|
|
101
|
+
|
|
102
|
+
:return: sorted union of materialized globals and lazy names
|
|
103
|
+
:rtype: list[str]
|
|
104
|
+
"""
|
|
105
|
+
return sorted(set(globals()) | set(_LAZY))
|