tealet 0.1.0rc1__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 (32) hide show
  1. tealet-0.1.0rc1/LICENSE +19 -0
  2. tealet-0.1.0rc1/PKG-INFO +192 -0
  3. tealet-0.1.0rc1/README.md +167 -0
  4. tealet-0.1.0rc1/pyproject.toml +62 -0
  5. tealet-0.1.0rc1/setup.cfg +4 -0
  6. tealet-0.1.0rc1/setup.py +296 -0
  7. tealet-0.1.0rc1/src/_tealet/frame_info.c +256 -0
  8. tealet-0.1.0rc1/src/_tealet/libtealet/stackman/tools/strip-lib.py +311 -0
  9. tealet-0.1.0rc1/src/_tealet/pytealet.c +2824 -0
  10. tealet-0.1.0rc1/src/_tealet/pytealet_lineage.c +540 -0
  11. tealet-0.1.0rc1/src/_tealet/pytealet_module.c +830 -0
  12. tealet-0.1.0rc1/src/_tealet/pytealet_throw.c +322 -0
  13. tealet-0.1.0rc1/src/_tealet/tstate_state.c +545 -0
  14. tealet-0.1.0rc1/src/capi_client/tealet_capi_client.c +800 -0
  15. tealet-0.1.0rc1/src/tealet/__init__.py +9 -0
  16. tealet-0.1.0rc1/src/tealet/greenlet/__init__.py +796 -0
  17. tealet-0.1.0rc1/src/tealet/greenlet/_greenlet.py +77 -0
  18. tealet-0.1.0rc1/src/tealet/include/pytealet_capi.h +126 -0
  19. tealet-0.1.0rc1/src/tealet.egg-info/PKG-INFO +192 -0
  20. tealet-0.1.0rc1/src/tealet.egg-info/SOURCES.txt +30 -0
  21. tealet-0.1.0rc1/src/tealet.egg-info/dependency_links.txt +1 -0
  22. tealet-0.1.0rc1/src/tealet.egg-info/requires.txt +6 -0
  23. tealet-0.1.0rc1/src/tealet.egg-info/top_level.txt +4 -0
  24. tealet-0.1.0rc1/tests/test_examples.py +74 -0
  25. tealet-0.1.0rc1/tests/test_greenlet_legacy.py +295 -0
  26. tealet-0.1.0rc1/tests/test_public_capi_headers.py +19 -0
  27. tealet-0.1.0rc1/tests/test_tealet_capi_client.py +266 -0
  28. tealet-0.1.0rc1/tests/test_tealet_context.py +274 -0
  29. tealet-0.1.0rc1/tests/test_tealet_frames_random.py +237 -0
  30. tealet-0.1.0rc1/tests/test_tealet_runtime.py +326 -0
  31. tealet-0.1.0rc1/tests/test_tealet_switching.py +416 -0
  32. tealet-0.1.0rc1/tests/test_tealet_threading.py +540 -0
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2025 Kristján Valur Jónsson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,192 @@
1
+ Metadata-Version: 2.4
2
+ Name: tealet
3
+ Version: 0.1.0rc1
4
+ Summary: Tealet - A greenlet-like library using tealets
5
+ Author-email: Kristján Valur Jónsson <sweskman@gmail.com>
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=7.0; extra == "dev"
21
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
22
+ Requires-Dist: psutil>=5.9; extra == "dev"
23
+ Requires-Dist: objgraph>=3.6; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # Tealet
27
+
28
+ A Python wrapper for the [libtealet](https://github.com/kristjanvalur/libtealet) library, providing efficient coroutine and stack-slicing capabilities to Python. This project brings the power of cooperative multitasking through stack-slicing to Python, similar to greenlet but built on the modern libtealet foundation.
29
+
30
+ ## About
31
+
32
+ Tealet provides low-level stack-switching primitives for cooperative multitasking in Python. Unlike traditional coroutines that require `async`/`await` keywords throughout your code, tealet lets you suspend and resume entire execution stacks.
33
+
34
+ Tealet is intentionally a building-block library, not a full scheduler/runtime framework. It provides primitives (`switch`, `run`, `throw`, thread ownership/state checks, etc.) that higher-level schedulers and runtimes can build on.
35
+
36
+ Built on vendored libtealet release archives (currently v0.7.5), this library offers:
37
+ - **Stack-slicing**: Efficient context switching without kernel involvement
38
+ - **Low memory overhead**: ~2-16 KB per coroutine vs 1-8 MB for OS threads
39
+ - **Fast context switches**: ~100-500 CPU cycles
40
+ - **Composable primitives**: Intended to support custom schedulers and runtime policies
41
+
42
+ The `tealet.greenlet` compatibility layer should be viewed as a proof-of-concept showing how richer APIs can be built on top of these primitives.
43
+
44
+ ## Project Structure
45
+
46
+ ```
47
+ pytealet/
48
+ ├── docs/
49
+ │ ├── ARCHITECTURE.md
50
+ │ ├── PYTHON_API.md
51
+ │ ├── C_API.md
52
+ │ └── ISSUES.md
53
+ ├── scripts/
54
+ │ └── fast_build.sh
55
+ ├── src/
56
+ │ ├── greenlet_legacy.py # Legacy greenlet compatibility shim (dev/test helper)
57
+ │ ├── tealet_examples.py # Development examples (generator/scheduler/event/future)
58
+ │ ├── tealet/ # Pure Python package
59
+ │ │ ├── __init__.py
60
+ │ │ └── greenlet/
61
+ │ └── _tealet/ # C extension module
62
+ │ ├── pytealet.c # Core runtime for tealet objects
63
+ │ ├── pytealet_module.c # CPython module lifecycle
64
+ │ ├── frame_info.c # Frame capture/restore helpers
65
+ │ ├── tstate_state.c # Thread-state transfer helpers
66
+ │ ├── libtealet/ # Vendored libtealet release archive (primary)
67
+ │ └── libtealet-src/ # Optional local libtealet source checkout (gitignored)
68
+ ├── tests/
69
+ │ ├── test_tealet.py
70
+ │ ├── test_greenlet_legacy.py
71
+ │ └── compat_greenlet/
72
+ ├── pyproject.toml
73
+ └── README.md
74
+ ```
75
+
76
+ ## Development
77
+
78
+ ### Development Setup
79
+
80
+ This project uses uv for dependency and environment management.
81
+
82
+ ```bash
83
+ # Create and activate a local virtual environment
84
+ uv venv --python 3.13
85
+ source .venv/bin/activate
86
+
87
+ # Install project and development dependencies
88
+ uv sync --dev --active
89
+ ```
90
+
91
+ If you are using a custom debug CPython build, install via uv pip with an explicit interpreter:
92
+
93
+ ```bash
94
+ uv venv --python /path/to/cpython-debug/python .venv-cpython313-debug
95
+ uv pip install --python .venv-cpython313-debug/bin/python -e .[dev]
96
+ ```
97
+
98
+ ### Running Tests
99
+
100
+ ```bash
101
+ uv run --active python -m pytest tests/
102
+ ```
103
+
104
+ ### Example Code
105
+
106
+ The repository includes runnable development examples in `src/tealet_examples.py`.
107
+ These show:
108
+ - a simple tealet-backed generator
109
+ - a minimal cooperative scheduler and event primitive
110
+ - a minimal future implementation built on top of the scheduler/event model
111
+
112
+ The scheduler example is intentionally simple and demonstrates how application- or framework-level scheduling can be implemented on top of tealet's core primitives.
113
+
114
+ Run the module from a source checkout:
115
+
116
+ ```bash
117
+ uv run --active python -m tealet_examples
118
+ ```
119
+
120
+ ### Runtime Frame Introspection Toggle
121
+
122
+ The extension exposes a module-level runtime switch for dormant-tealet frame exposure:
123
+
124
+ ```python
125
+ import _tealet
126
+
127
+ enabled = _tealet.frame_introspection() # get current setting
128
+ _tealet.frame_introspection(False) # disable dormant-frame capture
129
+ ```
130
+
131
+ Compile-time capability is exposed as `_tealet.PYTEALET_WITH_PENDING_FRAME_INTROSPECTION`.
132
+
133
+ ### Building Third-Party Extensions Against Tealet C API
134
+
135
+ The package installs a public C API header and exposes an include-path helper:
136
+
137
+ ```python
138
+ import tealet
139
+
140
+ include_dir = tealet.get_include()
141
+ ```
142
+
143
+ The public header is:
144
+
145
+ - `pytealet_capi.h`
146
+
147
+ Client extensions should include this header at build time and import the
148
+ runtime capsule using `PyTealetApi_Import()`.
149
+
150
+ ## API Documentation
151
+
152
+ Detailed API references live in the `docs/` folder:
153
+
154
+ - [docs/PYTHON_API.md](docs/PYTHON_API.md) for the Python-level API (`tealet`, `_tealet`, and compatibility shim notes)
155
+ - [docs/C_API.md](docs/C_API.md) for the capsule-based C API (`pytealet_capi.h`)
156
+
157
+ ### Building the C Extension
158
+
159
+ The C extension (`_tealet`) links against pre-built libtealet libraries from the vendored release archive. It depends on:
160
+ - **[libtealet](https://github.com/kristjanvalur/libtealet) v0.7.5** - Core stack-slicing library (pre-built binaries in `src/_tealet/libtealet/lib/`)
161
+ - **[stackman](https://github.com/stackless-dev/stackman)** - Platform-specific stack operations (bundled with libtealet)
162
+
163
+ Default build mode is release-archive based. To use a local source checkout for debugging instead, place it at `src/_tealet/libtealet-src/` and enable source mode:
164
+
165
+ ```bash
166
+ BUILD_LIBTEALET_FROM_SOURCE=1 uv sync --active --reinstall-package tealet
167
+ ```
168
+
169
+ **Build Requirements:**
170
+ - Python development headers (`python3.10-dev` or similar)
171
+ - C compiler (gcc, clang, or MSVC)
172
+ - Make (for ABI detection)
173
+
174
+ **Current Status:** The build infrastructure and Python 3 modernization are in place; active work is focused on runtime stability and stress-test robustness.
175
+
176
+ ## Contributing
177
+
178
+ Contributions are welcome! Please feel free to submit issues or pull requests.
179
+
180
+ ## Related Projects
181
+
182
+ - [libtealet](https://github.com/kristjanvalur/libtealet) - The underlying C library for stack-slicing
183
+ - [greenlet](https://github.com/python-greenlet/greenlet) - Original Python greenlet implementation
184
+ - [Stackless Python](http://www.stackless.com/) - Python with built-in microthreads
185
+
186
+ ## Changelog
187
+
188
+ See [CHANGELOG.md](CHANGELOG.md) for version history and release notes.
189
+
190
+ ## License
191
+
192
+ MIT License - See [LICENSE](LICENSE) file for details
@@ -0,0 +1,167 @@
1
+ # Tealet
2
+
3
+ A Python wrapper for the [libtealet](https://github.com/kristjanvalur/libtealet) library, providing efficient coroutine and stack-slicing capabilities to Python. This project brings the power of cooperative multitasking through stack-slicing to Python, similar to greenlet but built on the modern libtealet foundation.
4
+
5
+ ## About
6
+
7
+ Tealet provides low-level stack-switching primitives for cooperative multitasking in Python. Unlike traditional coroutines that require `async`/`await` keywords throughout your code, tealet lets you suspend and resume entire execution stacks.
8
+
9
+ Tealet is intentionally a building-block library, not a full scheduler/runtime framework. It provides primitives (`switch`, `run`, `throw`, thread ownership/state checks, etc.) that higher-level schedulers and runtimes can build on.
10
+
11
+ Built on vendored libtealet release archives (currently v0.7.5), this library offers:
12
+ - **Stack-slicing**: Efficient context switching without kernel involvement
13
+ - **Low memory overhead**: ~2-16 KB per coroutine vs 1-8 MB for OS threads
14
+ - **Fast context switches**: ~100-500 CPU cycles
15
+ - **Composable primitives**: Intended to support custom schedulers and runtime policies
16
+
17
+ The `tealet.greenlet` compatibility layer should be viewed as a proof-of-concept showing how richer APIs can be built on top of these primitives.
18
+
19
+ ## Project Structure
20
+
21
+ ```
22
+ pytealet/
23
+ ├── docs/
24
+ │ ├── ARCHITECTURE.md
25
+ │ ├── PYTHON_API.md
26
+ │ ├── C_API.md
27
+ │ └── ISSUES.md
28
+ ├── scripts/
29
+ │ └── fast_build.sh
30
+ ├── src/
31
+ │ ├── greenlet_legacy.py # Legacy greenlet compatibility shim (dev/test helper)
32
+ │ ├── tealet_examples.py # Development examples (generator/scheduler/event/future)
33
+ │ ├── tealet/ # Pure Python package
34
+ │ │ ├── __init__.py
35
+ │ │ └── greenlet/
36
+ │ └── _tealet/ # C extension module
37
+ │ ├── pytealet.c # Core runtime for tealet objects
38
+ │ ├── pytealet_module.c # CPython module lifecycle
39
+ │ ├── frame_info.c # Frame capture/restore helpers
40
+ │ ├── tstate_state.c # Thread-state transfer helpers
41
+ │ ├── libtealet/ # Vendored libtealet release archive (primary)
42
+ │ └── libtealet-src/ # Optional local libtealet source checkout (gitignored)
43
+ ├── tests/
44
+ │ ├── test_tealet.py
45
+ │ ├── test_greenlet_legacy.py
46
+ │ └── compat_greenlet/
47
+ ├── pyproject.toml
48
+ └── README.md
49
+ ```
50
+
51
+ ## Development
52
+
53
+ ### Development Setup
54
+
55
+ This project uses uv for dependency and environment management.
56
+
57
+ ```bash
58
+ # Create and activate a local virtual environment
59
+ uv venv --python 3.13
60
+ source .venv/bin/activate
61
+
62
+ # Install project and development dependencies
63
+ uv sync --dev --active
64
+ ```
65
+
66
+ If you are using a custom debug CPython build, install via uv pip with an explicit interpreter:
67
+
68
+ ```bash
69
+ uv venv --python /path/to/cpython-debug/python .venv-cpython313-debug
70
+ uv pip install --python .venv-cpython313-debug/bin/python -e .[dev]
71
+ ```
72
+
73
+ ### Running Tests
74
+
75
+ ```bash
76
+ uv run --active python -m pytest tests/
77
+ ```
78
+
79
+ ### Example Code
80
+
81
+ The repository includes runnable development examples in `src/tealet_examples.py`.
82
+ These show:
83
+ - a simple tealet-backed generator
84
+ - a minimal cooperative scheduler and event primitive
85
+ - a minimal future implementation built on top of the scheduler/event model
86
+
87
+ The scheduler example is intentionally simple and demonstrates how application- or framework-level scheduling can be implemented on top of tealet's core primitives.
88
+
89
+ Run the module from a source checkout:
90
+
91
+ ```bash
92
+ uv run --active python -m tealet_examples
93
+ ```
94
+
95
+ ### Runtime Frame Introspection Toggle
96
+
97
+ The extension exposes a module-level runtime switch for dormant-tealet frame exposure:
98
+
99
+ ```python
100
+ import _tealet
101
+
102
+ enabled = _tealet.frame_introspection() # get current setting
103
+ _tealet.frame_introspection(False) # disable dormant-frame capture
104
+ ```
105
+
106
+ Compile-time capability is exposed as `_tealet.PYTEALET_WITH_PENDING_FRAME_INTROSPECTION`.
107
+
108
+ ### Building Third-Party Extensions Against Tealet C API
109
+
110
+ The package installs a public C API header and exposes an include-path helper:
111
+
112
+ ```python
113
+ import tealet
114
+
115
+ include_dir = tealet.get_include()
116
+ ```
117
+
118
+ The public header is:
119
+
120
+ - `pytealet_capi.h`
121
+
122
+ Client extensions should include this header at build time and import the
123
+ runtime capsule using `PyTealetApi_Import()`.
124
+
125
+ ## API Documentation
126
+
127
+ Detailed API references live in the `docs/` folder:
128
+
129
+ - [docs/PYTHON_API.md](docs/PYTHON_API.md) for the Python-level API (`tealet`, `_tealet`, and compatibility shim notes)
130
+ - [docs/C_API.md](docs/C_API.md) for the capsule-based C API (`pytealet_capi.h`)
131
+
132
+ ### Building the C Extension
133
+
134
+ The C extension (`_tealet`) links against pre-built libtealet libraries from the vendored release archive. It depends on:
135
+ - **[libtealet](https://github.com/kristjanvalur/libtealet) v0.7.5** - Core stack-slicing library (pre-built binaries in `src/_tealet/libtealet/lib/`)
136
+ - **[stackman](https://github.com/stackless-dev/stackman)** - Platform-specific stack operations (bundled with libtealet)
137
+
138
+ Default build mode is release-archive based. To use a local source checkout for debugging instead, place it at `src/_tealet/libtealet-src/` and enable source mode:
139
+
140
+ ```bash
141
+ BUILD_LIBTEALET_FROM_SOURCE=1 uv sync --active --reinstall-package tealet
142
+ ```
143
+
144
+ **Build Requirements:**
145
+ - Python development headers (`python3.10-dev` or similar)
146
+ - C compiler (gcc, clang, or MSVC)
147
+ - Make (for ABI detection)
148
+
149
+ **Current Status:** The build infrastructure and Python 3 modernization are in place; active work is focused on runtime stability and stress-test robustness.
150
+
151
+ ## Contributing
152
+
153
+ Contributions are welcome! Please feel free to submit issues or pull requests.
154
+
155
+ ## Related Projects
156
+
157
+ - [libtealet](https://github.com/kristjanvalur/libtealet) - The underlying C library for stack-slicing
158
+ - [greenlet](https://github.com/python-greenlet/greenlet) - Original Python greenlet implementation
159
+ - [Stackless Python](http://www.stackless.com/) - Python with built-in microthreads
160
+
161
+ ## Changelog
162
+
163
+ See [CHANGELOG.md](CHANGELOG.md) for version history and release notes.
164
+
165
+ ## License
166
+
167
+ MIT License - See [LICENSE](LICENSE) file for details
@@ -0,0 +1,62 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tealet"
7
+ version = "0.1.0rc1"
8
+ description = "Tealet - A greenlet-like library using tealets"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ authors = [
12
+ {name = "Kristján Valur Jónsson", email = "sweskman@gmail.com"}
13
+ ]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Programming Language :: Python :: 3.15",
25
+ ]
26
+
27
+ [project.optional-dependencies]
28
+ dev = [
29
+ "pytest>=7.0",
30
+ "pytest-cov>=4.0",
31
+ "psutil>=5.9",
32
+ "objgraph>=3.6",
33
+ ]
34
+
35
+ [tool.setuptools]
36
+ package-dir = {"" = "src"}
37
+
38
+ [tool.setuptools.packages.find]
39
+ where = ["src"]
40
+
41
+ [tool.setuptools.package-data]
42
+ tealet = ["include/*.h"]
43
+
44
+ [tool.ruff]
45
+ line-length = 120
46
+
47
+ [tool.ruff.format]
48
+ exclude = ["tests/compat_greenlet/**"]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
52
+ python_files = ["test_*.py"]
53
+ python_classes = ["Test*"]
54
+ python_functions = ["test_*"]
55
+
56
+ [dependency-groups]
57
+ dev = [
58
+ "pytest>=7.0",
59
+ "pytest-cov>=4.0",
60
+ "psutil>=5.9",
61
+ "objgraph>=3.6",
62
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+