wt-registry 0.1.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.
Files changed (39) hide show
  1. wt_registry-0.1.0/PKG-INFO +152 -0
  2. wt_registry-0.1.0/README.md +133 -0
  3. wt_registry-0.1.0/docs/cli-implementation.md +225 -0
  4. wt_registry-0.1.0/docs/examples-plan.md +286 -0
  5. wt_registry-0.1.0/docs/plan.md +429 -0
  6. wt_registry-0.1.0/examples/README.md +50 -0
  7. wt_registry-0.1.0/examples/basic_registration.py +54 -0
  8. wt_registry-0.1.0/examples/cli_json_output.py +59 -0
  9. wt_registry-0.1.0/examples/cli_pretty_output.py +64 -0
  10. wt_registry-0.1.0/examples/deprecated_functions.py +96 -0
  11. wt_registry-0.1.0/examples/filtering_functions.py +96 -0
  12. wt_registry-0.1.0/examples/multiple_modules.py +102 -0
  13. wt_registry-0.1.0/pyproject.toml +121 -0
  14. wt_registry-0.1.0/setup.cfg +4 -0
  15. wt_registry-0.1.0/src/wt_registry/__init__.py +6 -0
  16. wt_registry-0.1.0/src/wt_registry/_version.py +34 -0
  17. wt_registry-0.1.0/src/wt_registry/cli.py +363 -0
  18. wt_registry-0.1.0/src/wt_registry/decorator.py +151 -0
  19. wt_registry-0.1.0/src/wt_registry/exceptions.py +72 -0
  20. wt_registry-0.1.0/src/wt_registry/jsonschema.py +91 -0
  21. wt_registry-0.1.0/src/wt_registry/models.py +180 -0
  22. wt_registry-0.1.0/src/wt_registry/py.typed +0 -0
  23. wt_registry-0.1.0/src/wt_registry/registry.py +188 -0
  24. wt_registry-0.1.0/src/wt_registry/validation.py +98 -0
  25. wt_registry-0.1.0/src/wt_registry.egg-info/PKG-INFO +152 -0
  26. wt_registry-0.1.0/src/wt_registry.egg-info/SOURCES.txt +37 -0
  27. wt_registry-0.1.0/src/wt_registry.egg-info/dependency_links.txt +1 -0
  28. wt_registry-0.1.0/src/wt_registry.egg-info/entry_points.txt +2 -0
  29. wt_registry-0.1.0/src/wt_registry.egg-info/requires.txt +2 -0
  30. wt_registry-0.1.0/src/wt_registry.egg-info/top_level.txt +1 -0
  31. wt_registry-0.1.0/tests/__init__.py +1 -0
  32. wt_registry-0.1.0/tests/test_cli.py +762 -0
  33. wt_registry-0.1.0/tests/test_decorator.py +390 -0
  34. wt_registry-0.1.0/tests/test_exceptions.py +75 -0
  35. wt_registry-0.1.0/tests/test_jsonschema.py +142 -0
  36. wt_registry-0.1.0/tests/test_models.py +271 -0
  37. wt_registry-0.1.0/tests/test_registry.py +327 -0
  38. wt_registry-0.1.0/tests/test_validation.py +161 -0
  39. wt_registry-0.1.0/uv.lock +770 -0
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.4
2
+ Name: wt-registry
3
+ Version: 0.1.0
4
+ Summary: Explicit function registry with JSON schema generation
5
+ Author-email: Charles Stern <charles@example.com>
6
+ License: BSD-3-Clause
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: BSD License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ Requires-Dist: wt-contracts<1.0.0,>=0.1.0
18
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
19
+
20
+ # wt-registry
21
+
22
+ [![codecov](https://codecov.io/gh/USERNAME/wt-registry/branch/main/graph/badge.svg)](https://codecov.io/gh/USERNAME/wt-registry)
23
+
24
+ Explicit function registry with JSON schema generation for Python.
25
+
26
+ ## Overview
27
+
28
+ `wt-registry` provides a simple, explicit decorator-based approach to registering functions with rich metadata and automatic JSON schema generation using Pydantic.
29
+
30
+ ## Features
31
+
32
+ - **Explicit Registration**: Use `@register` decorator with metadata (title, description, tags)
33
+ - **Type Safety**: Requires complete type annotations for all registered functions
34
+ - **JSON Schema Generation**: Automatically generates JSON schemas using Pydantic TypeAdapter
35
+ - **Minimal Dependencies**: Only requires Python 3.10+ and Pydantic
36
+ - **CLI Tool**: Export registry contents as JSON via command-line interface
37
+ - **Fully Serializable**: Registry stores metadata and schemas, not function objects
38
+
39
+ ## Quick Start with Examples
40
+
41
+ The fastest way to see wt-registry in action:
42
+
43
+ ```bash
44
+ # Clone the repository
45
+ git clone https://github.com/USERNAME/wt-registry.git
46
+ cd wt-registry
47
+
48
+ # One-time setup
49
+ uv sync
50
+
51
+ # Run an example
52
+ uv run python examples/basic_registration.py
53
+ ```
54
+
55
+ See [examples/README.md](examples/README.md) for more examples demonstrating:
56
+ - Basic function registration
57
+ - JSON and pretty output formats
58
+ - Function filtering
59
+ - Deprecated function handling
60
+ - Multi-module scenarios
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ uv pip install wt-registry
66
+ ```
67
+
68
+ ## Quick Start
69
+
70
+ ```python
71
+ from wt_registry import register, get_registry
72
+
73
+ @register(
74
+ title="Calculate Statistics",
75
+ description="Calculate mean, median, and stdev of numeric values",
76
+ tags=["statistics", "analysis"]
77
+ )
78
+ def calculate_statistics(
79
+ values: list[float],
80
+ precision: int = 2
81
+ ) -> dict[str, float]:
82
+ import statistics
83
+ return {
84
+ "mean": round(statistics.mean(values), precision),
85
+ "median": round(statistics.median(values), precision),
86
+ "stdev": round(statistics.stdev(values), precision) if len(values) > 1 else 0.0,
87
+ }
88
+
89
+ # Access the registry
90
+ registry = get_registry()
91
+ for fqn, entry in registry.items():
92
+ print(f"{entry.metadata.title}: {fqn}")
93
+ print(f" Schema: {entry.json_schema}")
94
+ ```
95
+
96
+ ## CLI Usage
97
+
98
+ Export the entire registry as JSON:
99
+
100
+ ```bash
101
+ wt-registry > registry.json
102
+ ```
103
+
104
+ Filter by tags:
105
+
106
+ ```bash
107
+ wt-registry --filter-tag statistics --format pretty
108
+ ```
109
+
110
+ Filter by module:
111
+
112
+ ```bash
113
+ wt-registry --module "myapp.tasks.*"
114
+ ```
115
+
116
+ ## Requirements
117
+
118
+ - Python 3.10+
119
+ - Pydantic 2.0+
120
+
121
+ ## Development
122
+
123
+ Install development dependencies:
124
+
125
+ ```bash
126
+ # IMPORTANT: Use --group dev (not --extra dev) with dependency-groups
127
+ uv sync --group dev
128
+ ```
129
+
130
+ **Note**: This project uses `[dependency-groups]` instead of `[project.optional-dependencies]`. You **must** use `--group dev` to install dev dependencies (pytest, mypy, ruff, etc.). Running `uv sync` alone will not install dev dependencies.
131
+
132
+ Set up pre-commit hooks (automatically runs ruff linting and formatting on every commit):
133
+
134
+ ```bash
135
+ uv run pre-commit install
136
+ ```
137
+
138
+ Run tests:
139
+
140
+ ```bash
141
+ uv run pytest
142
+ ```
143
+
144
+ Run type checking:
145
+
146
+ ```bash
147
+ uv run mypy src/wt_registry
148
+ ```
149
+
150
+ ## License
151
+
152
+ BSD-3-Clause
@@ -0,0 +1,133 @@
1
+ # wt-registry
2
+
3
+ [![codecov](https://codecov.io/gh/USERNAME/wt-registry/branch/main/graph/badge.svg)](https://codecov.io/gh/USERNAME/wt-registry)
4
+
5
+ Explicit function registry with JSON schema generation for Python.
6
+
7
+ ## Overview
8
+
9
+ `wt-registry` provides a simple, explicit decorator-based approach to registering functions with rich metadata and automatic JSON schema generation using Pydantic.
10
+
11
+ ## Features
12
+
13
+ - **Explicit Registration**: Use `@register` decorator with metadata (title, description, tags)
14
+ - **Type Safety**: Requires complete type annotations for all registered functions
15
+ - **JSON Schema Generation**: Automatically generates JSON schemas using Pydantic TypeAdapter
16
+ - **Minimal Dependencies**: Only requires Python 3.10+ and Pydantic
17
+ - **CLI Tool**: Export registry contents as JSON via command-line interface
18
+ - **Fully Serializable**: Registry stores metadata and schemas, not function objects
19
+
20
+ ## Quick Start with Examples
21
+
22
+ The fastest way to see wt-registry in action:
23
+
24
+ ```bash
25
+ # Clone the repository
26
+ git clone https://github.com/USERNAME/wt-registry.git
27
+ cd wt-registry
28
+
29
+ # One-time setup
30
+ uv sync
31
+
32
+ # Run an example
33
+ uv run python examples/basic_registration.py
34
+ ```
35
+
36
+ See [examples/README.md](examples/README.md) for more examples demonstrating:
37
+ - Basic function registration
38
+ - JSON and pretty output formats
39
+ - Function filtering
40
+ - Deprecated function handling
41
+ - Multi-module scenarios
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ uv pip install wt-registry
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ```python
52
+ from wt_registry import register, get_registry
53
+
54
+ @register(
55
+ title="Calculate Statistics",
56
+ description="Calculate mean, median, and stdev of numeric values",
57
+ tags=["statistics", "analysis"]
58
+ )
59
+ def calculate_statistics(
60
+ values: list[float],
61
+ precision: int = 2
62
+ ) -> dict[str, float]:
63
+ import statistics
64
+ return {
65
+ "mean": round(statistics.mean(values), precision),
66
+ "median": round(statistics.median(values), precision),
67
+ "stdev": round(statistics.stdev(values), precision) if len(values) > 1 else 0.0,
68
+ }
69
+
70
+ # Access the registry
71
+ registry = get_registry()
72
+ for fqn, entry in registry.items():
73
+ print(f"{entry.metadata.title}: {fqn}")
74
+ print(f" Schema: {entry.json_schema}")
75
+ ```
76
+
77
+ ## CLI Usage
78
+
79
+ Export the entire registry as JSON:
80
+
81
+ ```bash
82
+ wt-registry > registry.json
83
+ ```
84
+
85
+ Filter by tags:
86
+
87
+ ```bash
88
+ wt-registry --filter-tag statistics --format pretty
89
+ ```
90
+
91
+ Filter by module:
92
+
93
+ ```bash
94
+ wt-registry --module "myapp.tasks.*"
95
+ ```
96
+
97
+ ## Requirements
98
+
99
+ - Python 3.10+
100
+ - Pydantic 2.0+
101
+
102
+ ## Development
103
+
104
+ Install development dependencies:
105
+
106
+ ```bash
107
+ # IMPORTANT: Use --group dev (not --extra dev) with dependency-groups
108
+ uv sync --group dev
109
+ ```
110
+
111
+ **Note**: This project uses `[dependency-groups]` instead of `[project.optional-dependencies]`. You **must** use `--group dev` to install dev dependencies (pytest, mypy, ruff, etc.). Running `uv sync` alone will not install dev dependencies.
112
+
113
+ Set up pre-commit hooks (automatically runs ruff linting and formatting on every commit):
114
+
115
+ ```bash
116
+ uv run pre-commit install
117
+ ```
118
+
119
+ Run tests:
120
+
121
+ ```bash
122
+ uv run pytest
123
+ ```
124
+
125
+ Run type checking:
126
+
127
+ ```bash
128
+ uv run mypy src/wt_registry
129
+ ```
130
+
131
+ ## License
132
+
133
+ BSD-3-Clause
@@ -0,0 +1,225 @@
1
+ # CLI Implementation Plan
2
+
3
+ ## Overview
4
+ Implement a command-line interface (CLI) for the wt-registry package that allows users to export the registry to JSON or a human-readable format, with optional filtering by function names.
5
+
6
+ ## Requirements
7
+
8
+ ### Command Syntax
9
+ ```bash
10
+ wt-registry [--format json|pretty] [--function NAME]...
11
+ ```
12
+
13
+ ### Features
14
+ 1. **Output Formats**:
15
+ - `json` (default): Machine-readable JSON output to stdout
16
+ - `pretty`: Human-readable multi-line text format
17
+
18
+ 2. **Filtering**:
19
+ - `--function NAME`: Filter by function name (multiple allowed)
20
+ - Filters by function name only (not fully qualified name)
21
+ - Silently skips function names that don't exist (no error)
22
+ - **Performance optimization**: Only resolves JSON schema for selected functions
23
+
24
+ 3. **Implementation Requirements**:
25
+ - Use builtin `argparse` (no additional dependencies)
26
+ - Use `get_registry()` for registry access
27
+ - **Don't use `to_json()`** - manually serialize to avoid computing schemas for filtered-out functions
28
+ - Follow existing code patterns and testing conventions
29
+ - Complete type hints and comprehensive docstrings
30
+
31
+ ## Critical Files
32
+
33
+ ### New Files
34
+ - **`src/wt_registry/cli.py`** - CLI implementation
35
+ - **`tests/test_cli.py`** - CLI tests
36
+
37
+ ### Reference Files
38
+ - `src/wt_registry/registry.py` - Use `get_registry()`
39
+ - `src/wt_registry/models.py` - Access RegistryEntry structure
40
+ - `pyproject.toml` - CLI entry point already configured at line 30
41
+
42
+ ## Implementation Details
43
+
44
+ ### 1. CLI Module Structure (`src/wt_registry/cli.py`)
45
+
46
+ ```python
47
+ """Command-line interface for wt-registry."""
48
+
49
+ import argparse
50
+ import json
51
+ import sys
52
+ from typing import Any
53
+ from types import MappingProxyType
54
+
55
+ from wt_registry.models import RegistryEntry
56
+ from wt_registry.registry import get_registry
57
+
58
+
59
+ def filter_by_function_names(
60
+ registry: MappingProxyType[str, RegistryEntry],
61
+ function_names: list[str] | None = None,
62
+ ) -> dict[str, RegistryEntry]:
63
+ """Filter registry entries by function names."""
64
+ # Implementation
65
+
66
+
67
+ def serialize_entries(
68
+ entries: dict[str, RegistryEntry],
69
+ ) -> dict[str, dict[str, Any]]:
70
+ """
71
+ Serialize registry entries to JSON-compatible dict.
72
+
73
+ Only generates JSON schema for entries being serialized (performance optimization).
74
+ """
75
+ # Implementation
76
+
77
+
78
+ def format_pretty(entries: dict[str, RegistryEntry]) -> str:
79
+ """Format registry entries as human-readable text."""
80
+ # Implementation
81
+
82
+
83
+ def main() -> None:
84
+ """Main CLI entry point."""
85
+ # Implementation
86
+ ```
87
+
88
+ ### 2. Filtering Logic
89
+
90
+ #### Function Name Filtering
91
+ ```python
92
+ # If function_names filter is specified, only include entries with matching function names
93
+ if function_names:
94
+ filtered = {}
95
+ for fqn, entry in registry.items():
96
+ if entry.function_name in function_names:
97
+ filtered[fqn] = entry
98
+ return filtered
99
+ else:
100
+ # No filter, return all entries as dict
101
+ return dict(registry)
102
+ ```
103
+
104
+ **Key points:**
105
+ - Filter by `entry.function_name` (just the function name, not the FQN)
106
+ - Silently skip function names that don't exist in registry (no error)
107
+ - If no filter specified, include all entries
108
+
109
+ ### 3. Output Formats
110
+
111
+ #### JSON Format
112
+ - **Don't use `to_json()`** - manually serialize to optimize performance
113
+ - Call `entry.model_dump(mode='json')` for each selected entry
114
+ - Manually add `entry.json_schema` (lazy generation only for selected functions)
115
+ - Output with `json.dumps(data, indent=2)` for readability
116
+
117
+ **Performance optimization:**
118
+ ```python
119
+ # Only generate JSON schema for selected functions
120
+ registry_data = {}
121
+ for fqn, entry in filtered_entries.items():
122
+ data = entry.model_dump(mode="json")
123
+ data["json_schema"] = entry.json_schema # Lazy generation here
124
+ registry_data[fqn] = data
125
+ ```
126
+
127
+ #### Pretty Format
128
+ Multi-line text with sections for each entry:
129
+ ```
130
+ === module.function ===
131
+ Title: Calculate Statistics
132
+ Description: Calculate mean, median, and stdev of numeric values
133
+ Tags: statistics, analysis
134
+ Deprecated: No
135
+ Import: from module import function
136
+
137
+ === another.module.function ===
138
+ Title: ...
139
+ ...
140
+ ```
141
+
142
+ For deprecated functions:
143
+ ```
144
+ Deprecated: Yes (Use new_function instead)
145
+ ```
146
+
147
+ **Note:** Pretty format doesn't include JSON schema for readability
148
+
149
+ ### 4. Integration with Existing Code
150
+
151
+ The CLI will:
152
+ 1. Import `get_registry()` from `wt_registry.registry`
153
+ 2. Call `get_registry()` to get MappingProxyType of entries
154
+ 3. Apply function name filter to get subset of entries
155
+ 4. For JSON format: manually serialize selected entries (triggering lazy schema generation only for selected functions)
156
+ 5. For pretty format: format selected entries without generating schemas
157
+ 6. Output to stdout
158
+
159
+ **Why not use `to_json()`?**
160
+ The existing `to_json()` function generates JSON schemas for ALL functions in the registry. When filtering is applied, we want to avoid this unnecessary computation. By manually serializing only the filtered entries, we only trigger `entry.json_schema` property for selected functions.
161
+
162
+ ## Testing Strategy (`tests/test_cli.py`)
163
+
164
+ ### Test Cases
165
+
166
+ **Basic Functionality:**
167
+ 1. `test_cli_json_format_default()` - Default JSON output (no filtering)
168
+ 2. `test_cli_json_format_explicit()` - Explicit `--format json`
169
+ 3. `test_cli_pretty_format()` - `--format pretty` output
170
+ 4. `test_cli_empty_registry()` - Handle empty registry gracefully
171
+
172
+ **Function Name Filtering:**
173
+ 5. `test_cli_filter_single_function()` - Filter by one function name
174
+ 6. `test_cli_filter_multiple_functions()` - Multiple function names
175
+ 7. `test_cli_filter_function_not_found()` - Function name doesn't exist (should not error, just skip)
176
+ 8. `test_cli_filter_function_partial_match()` - Some functions exist, some don't
177
+ 9. `test_cli_filter_no_functions_match()` - All specified functions don't exist (empty output)
178
+
179
+ **Performance/Schema Generation:**
180
+ 10. `test_cli_filter_only_generates_schema_for_selected()` - Verify JSON schema only generated for selected functions
181
+
182
+ **Edge Cases:**
183
+ 11. `test_cli_deprecated_function_json()` - Deprecated function in JSON output
184
+ 12. `test_cli_deprecated_function_pretty()` - Deprecated function in pretty format
185
+ 13. `test_cli_function_with_no_tags()` - Function with empty tags list
186
+ 14. `test_cli_duplicate_function_names_different_modules()` - Two functions with same name but different modules (both should be included)
187
+
188
+ ## Key Design Decisions
189
+
190
+ 1. **Don't use `to_json()`**: Manually serialize to avoid generating JSON schemas for filtered-out functions (performance optimization)
191
+ 2. **Filter by function name only**: Simple, focused filtering by `entry.function_name`
192
+ 3. **Silently skip missing functions**: If a function name doesn't exist, just skip it (no error)
193
+ 4. **Lazy schema generation optimization**: Only call `entry.json_schema` for selected functions when outputting JSON
194
+ 5. **Multiple function names**: Allow multiple `--function` arguments to select multiple functions
195
+ 6. **Pretty format without JSON schema**: For readability, don't include full JSON schema in pretty output
196
+ 7. **Empty registry handling**: Output valid JSON `{}` for machine-readable format
197
+
198
+ ## Example Usage
199
+
200
+ ```bash
201
+ # Export entire registry as JSON
202
+ wt-registry > registry.json
203
+
204
+ # Export in human-readable format
205
+ wt-registry --format pretty
206
+
207
+ # Filter by function names
208
+ wt-registry --function calculate_mean
209
+ wt-registry --function func1 --function func2
210
+
211
+ # Filter in pretty format
212
+ wt-registry --format pretty --function calculate_statistics
213
+
214
+ # Non-existent function names are silently skipped
215
+ wt-registry --function real_func --function fake_func # Only outputs real_func
216
+ ```
217
+
218
+ ## Notes
219
+
220
+ - Entry point is already configured in `pyproject.toml` line 30
221
+ - CLI doesn't need to modify registry, only read and display
222
+ - **Performance optimization**: By not using `to_json()`, we avoid generating schemas for all functions
223
+ - JSON schema generation is expensive (uses Pydantic TypeAdapter), so only do it for selected functions
224
+ - All filtering is done in-memory after loading full registry
225
+ - Function name filter matches on `entry.function_name` (not FQN), so functions from different modules with same name will both be included