native-jit 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.
- native_jit-0.1.0/PKG-INFO +162 -0
- native_jit-0.1.0/README.md +125 -0
- native_jit-0.1.0/native_jit/__init__.py +32 -0
- native_jit-0.1.0/native_jit/_compiler.py +866 -0
- native_jit-0.1.0/native_jit.egg-info/PKG-INFO +162 -0
- native_jit-0.1.0/native_jit.egg-info/SOURCES.txt +11 -0
- native_jit-0.1.0/native_jit.egg-info/dependency_links.txt +1 -0
- native_jit-0.1.0/native_jit.egg-info/not-zip-safe +1 -0
- native_jit-0.1.0/native_jit.egg-info/requires.txt +7 -0
- native_jit-0.1.0/native_jit.egg-info/top_level.txt +1 -0
- native_jit-0.1.0/pyproject.toml +6 -0
- native_jit-0.1.0/setup.cfg +4 -0
- native_jit-0.1.0/setup.py +43 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: native-jit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Cython-powered JIT decorator for Python functions and classes
|
|
5
|
+
Home-page: https://github.com/fanbozhou/native_jit
|
|
6
|
+
Author: Fanbo Zhou
|
|
7
|
+
Keywords: jit cython performance decorator
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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: Programming Language :: C
|
|
17
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
Requires-Dist: Cython>=3.0
|
|
22
|
+
Requires-Dist: setuptools>=65
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
25
|
+
Requires-Dist: twine>=5.1; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: description
|
|
30
|
+
Dynamic: description-content-type
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: keywords
|
|
33
|
+
Dynamic: provides-extra
|
|
34
|
+
Dynamic: requires-dist
|
|
35
|
+
Dynamic: requires-python
|
|
36
|
+
Dynamic: summary
|
|
37
|
+
|
|
38
|
+
# native_jit
|
|
39
|
+
|
|
40
|
+
`native_jit` is a Cython-powered JIT decorator for Python functions and classes.
|
|
41
|
+
|
|
42
|
+
It tries to compile decorated objects for speed and automatically falls back to the original Python object if compilation is not available in the current environment.
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- `@jit` for functions and classes
|
|
47
|
+
- Cython compilation pipeline (`.pyx -> .c -> extension module`)
|
|
48
|
+
- In-memory and disk cache for compiled modules
|
|
49
|
+
- Concurrent compilation deduplication
|
|
50
|
+
- Cross-platform compiler detection (`CC` / system compiler fallback)
|
|
51
|
+
- Safe fallback mode: no hard failure when compilation is unavailable
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install native-jit
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
For local development:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install -e .[dev]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Quick Start
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from native_jit import jit
|
|
69
|
+
|
|
70
|
+
@jit
|
|
71
|
+
def add(a: int, b: int) -> int:
|
|
72
|
+
return a + b
|
|
73
|
+
|
|
74
|
+
print(add(1, 2))
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Advanced usage:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from native_jit import jit
|
|
81
|
+
|
|
82
|
+
@jit(nopython=True)
|
|
83
|
+
def fast_sum(n: int) -> int:
|
|
84
|
+
s = 0
|
|
85
|
+
for i in range(n):
|
|
86
|
+
s += i
|
|
87
|
+
return s
|
|
88
|
+
|
|
89
|
+
print(fast_sum(1000000))
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## API
|
|
93
|
+
|
|
94
|
+
- `jit(...)`: decorate function/class/method
|
|
95
|
+
- `jit.from_pyx(func_name, pyx_code, **kwargs)`: compile raw Cython source
|
|
96
|
+
- `jit.warmup()`: warm up compiler flag probing
|
|
97
|
+
- `jit.cache_info()`: inspect cache and compiler flags
|
|
98
|
+
- `jit.clear_cache(disk=False)`: clear in-memory/disk cache
|
|
99
|
+
|
|
100
|
+
## Notes on Compilers
|
|
101
|
+
|
|
102
|
+
Cython does not bundle a C compiler. A system C toolchain is still required for native compilation.
|
|
103
|
+
|
|
104
|
+
`native_jit` detects compiler command from:
|
|
105
|
+
|
|
106
|
+
1. `CC` environment variable
|
|
107
|
+
2. Python build configuration (`sysconfig`)
|
|
108
|
+
3. common fallback commands (`cc`, `clang`, `gcc`, `cl`)
|
|
109
|
+
|
|
110
|
+
If no compiler is available, decorated code still runs with Python fallback mode.
|
|
111
|
+
|
|
112
|
+
## Publish to GitHub
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
git init
|
|
116
|
+
git add .
|
|
117
|
+
git commit -m "chore: prepare package for release"
|
|
118
|
+
git branch -M main
|
|
119
|
+
git remote add origin https://github.com/<your-user>/<your-repo>.git
|
|
120
|
+
git push -u origin main
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Build and Publish to PyPI
|
|
124
|
+
|
|
125
|
+
1. Create PyPI account and API token.
|
|
126
|
+
2. Export token:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
export TWINE_USERNAME=__token__
|
|
130
|
+
export TWINE_PASSWORD=<pypi-token>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
3. Build package:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
python -m build
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
4. Verify artifacts:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
python -m twine check dist/*
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
5. Upload to TestPyPI (recommended first):
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
python -m twine upload --repository testpypi dist/*
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
6. Upload to PyPI:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
python -m twine upload dist/*
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Verify Install
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pip install native-jit
|
|
161
|
+
python -c "from native_jit import jit; print(callable(jit))"
|
|
162
|
+
```
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# native_jit
|
|
2
|
+
|
|
3
|
+
`native_jit` is a Cython-powered JIT decorator for Python functions and classes.
|
|
4
|
+
|
|
5
|
+
It tries to compile decorated objects for speed and automatically falls back to the original Python object if compilation is not available in the current environment.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- `@jit` for functions and classes
|
|
10
|
+
- Cython compilation pipeline (`.pyx -> .c -> extension module`)
|
|
11
|
+
- In-memory and disk cache for compiled modules
|
|
12
|
+
- Concurrent compilation deduplication
|
|
13
|
+
- Cross-platform compiler detection (`CC` / system compiler fallback)
|
|
14
|
+
- Safe fallback mode: no hard failure when compilation is unavailable
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install native-jit
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For local development:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e .[dev]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from native_jit import jit
|
|
32
|
+
|
|
33
|
+
@jit
|
|
34
|
+
def add(a: int, b: int) -> int:
|
|
35
|
+
return a + b
|
|
36
|
+
|
|
37
|
+
print(add(1, 2))
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Advanced usage:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from native_jit import jit
|
|
44
|
+
|
|
45
|
+
@jit(nopython=True)
|
|
46
|
+
def fast_sum(n: int) -> int:
|
|
47
|
+
s = 0
|
|
48
|
+
for i in range(n):
|
|
49
|
+
s += i
|
|
50
|
+
return s
|
|
51
|
+
|
|
52
|
+
print(fast_sum(1000000))
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
- `jit(...)`: decorate function/class/method
|
|
58
|
+
- `jit.from_pyx(func_name, pyx_code, **kwargs)`: compile raw Cython source
|
|
59
|
+
- `jit.warmup()`: warm up compiler flag probing
|
|
60
|
+
- `jit.cache_info()`: inspect cache and compiler flags
|
|
61
|
+
- `jit.clear_cache(disk=False)`: clear in-memory/disk cache
|
|
62
|
+
|
|
63
|
+
## Notes on Compilers
|
|
64
|
+
|
|
65
|
+
Cython does not bundle a C compiler. A system C toolchain is still required for native compilation.
|
|
66
|
+
|
|
67
|
+
`native_jit` detects compiler command from:
|
|
68
|
+
|
|
69
|
+
1. `CC` environment variable
|
|
70
|
+
2. Python build configuration (`sysconfig`)
|
|
71
|
+
3. common fallback commands (`cc`, `clang`, `gcc`, `cl`)
|
|
72
|
+
|
|
73
|
+
If no compiler is available, decorated code still runs with Python fallback mode.
|
|
74
|
+
|
|
75
|
+
## Publish to GitHub
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
git init
|
|
79
|
+
git add .
|
|
80
|
+
git commit -m "chore: prepare package for release"
|
|
81
|
+
git branch -M main
|
|
82
|
+
git remote add origin https://github.com/<your-user>/<your-repo>.git
|
|
83
|
+
git push -u origin main
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Build and Publish to PyPI
|
|
87
|
+
|
|
88
|
+
1. Create PyPI account and API token.
|
|
89
|
+
2. Export token:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
export TWINE_USERNAME=__token__
|
|
93
|
+
export TWINE_PASSWORD=<pypi-token>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
3. Build package:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
python -m build
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
4. Verify artifacts:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
python -m twine check dist/*
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
5. Upload to TestPyPI (recommended first):
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
python -m twine upload --repository testpypi dist/*
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
6. Upload to PyPI:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
python -m twine upload dist/*
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Verify Install
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pip install native-jit
|
|
124
|
+
python -c "from native_jit import jit; print(callable(jit))"
|
|
125
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
native_jit — Cython-powered JIT decorator for Python functions and classes.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
from native_jit import jit
|
|
6
|
+
|
|
7
|
+
@jit
|
|
8
|
+
def add(a: int, b: int) -> int:
|
|
9
|
+
return a + b
|
|
10
|
+
|
|
11
|
+
@jit(boundscheck=False, cdivision=True)
|
|
12
|
+
def fast_sum(n: int) -> float:
|
|
13
|
+
cdef double s = 0
|
|
14
|
+
cdef int i
|
|
15
|
+
for i in range(n):
|
|
16
|
+
s += i
|
|
17
|
+
return s
|
|
18
|
+
|
|
19
|
+
@jit
|
|
20
|
+
class Point:
|
|
21
|
+
def __init__(self, x: float, y: float):
|
|
22
|
+
self.x = x
|
|
23
|
+
self.y = y
|
|
24
|
+
|
|
25
|
+
def distance(self) -> float:
|
|
26
|
+
return (self.x ** 2 + self.y ** 2) ** 0.5
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from ._compiler import jit
|
|
30
|
+
|
|
31
|
+
__all__ = ["jit"]
|
|
32
|
+
__version__ = "0.1.0"
|