unit-jit 0.1.0__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.
- unit_jit/__init__.py +271 -0
- unit_jit/py.typed +0 -0
- unit_jit-0.1.0.dist-info/METADATA +127 -0
- unit_jit-0.1.0.dist-info/RECORD +6 -0
- unit_jit-0.1.0.dist-info/WHEEL +4 -0
- unit_jit-0.1.0.dist-info/licenses/LICENSE +201 -0
unit_jit/__init__.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"""JIT unit-stripping decorator for Pint-annotated Python.
|
|
2
|
+
|
|
3
|
+
All @unit_jit functions in the same module are rewritten together on the
|
|
4
|
+
first call to any of them. Pint Quantities are converted to SI floats at
|
|
5
|
+
the outermost boundary; inner @unit_jit calls within the fast zone skip
|
|
6
|
+
conversion entirely.
|
|
7
|
+
|
|
8
|
+
The first call per entry point runs the original (Pint) function to infer
|
|
9
|
+
return units; all subsequent calls use the rewritten float version.
|
|
10
|
+
|
|
11
|
+
Rewrites applied inside the fast zone:
|
|
12
|
+
- x.magnitude → x
|
|
13
|
+
- x.to_base_units() → x
|
|
14
|
+
- cast("Quantity", x) → x
|
|
15
|
+
- ureg.UNIT → SI float (e.g. ureg.s → 1.0, ureg.cm → 0.01)
|
|
16
|
+
- arithmetic unchanged (works identically for floats)
|
|
17
|
+
|
|
18
|
+
Quantity attributes on objects (e.g. self.params.alpha) are handled via an
|
|
19
|
+
eager snapshot: all Quantity attrs are converted to SI floats once at
|
|
20
|
+
boundary entry, so attribute access inside the loop is a plain dict lookup.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import inspect
|
|
24
|
+
import textwrap
|
|
25
|
+
import threading
|
|
26
|
+
from collections import defaultdict
|
|
27
|
+
from collections.abc import Callable
|
|
28
|
+
from typing import Any
|
|
29
|
+
|
|
30
|
+
import libcst as cst
|
|
31
|
+
from pint import Quantity, UnitRegistry
|
|
32
|
+
|
|
33
|
+
ureg = UnitRegistry()
|
|
34
|
+
|
|
35
|
+
_fast_zone = threading.local()
|
|
36
|
+
_registry: dict[str, list[Callable[..., Any]]] = defaultdict(list)
|
|
37
|
+
_compiled: dict[str, dict[str, Callable[..., Any]]] = {}
|
|
38
|
+
_return_units: dict[str, Any] = {}
|
|
39
|
+
_arg_dims: dict[str, tuple[list[Any], dict[str, Any]]] = {} # qualname → (positional, keyword)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _in_fast_zone() -> bool:
|
|
43
|
+
return getattr(_fast_zone, "active", False)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ── CST transformer ────────────────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class _QuantityStripper(cst.CSTTransformer):
|
|
50
|
+
"""Strip .magnitude, .to_base_units(), cast("Quantity", x), and ureg.UNIT → SI float."""
|
|
51
|
+
|
|
52
|
+
def __init__(self, ureg_vars: dict[str, UnitRegistry]) -> None:
|
|
53
|
+
super().__init__()
|
|
54
|
+
self._ureg_vars = ureg_vars
|
|
55
|
+
|
|
56
|
+
def leave_Attribute(
|
|
57
|
+
self, _original_node: cst.Attribute, updated_node: cst.Attribute
|
|
58
|
+
) -> cst.BaseExpression:
|
|
59
|
+
if updated_node.attr.value == "magnitude":
|
|
60
|
+
return updated_node.value
|
|
61
|
+
# ureg.UNIT → SI float (e.g. ureg.s → 1.0, ureg.cm → 0.01)
|
|
62
|
+
if isinstance(updated_node.value, cst.Name):
|
|
63
|
+
ureg_instance = self._ureg_vars.get(updated_node.value.value)
|
|
64
|
+
if ureg_instance is not None:
|
|
65
|
+
try:
|
|
66
|
+
si_val = (
|
|
67
|
+
(1 * getattr(ureg_instance, updated_node.attr.value))
|
|
68
|
+
.to_base_units()
|
|
69
|
+
.magnitude
|
|
70
|
+
)
|
|
71
|
+
return cst.Float(repr(float(si_val)))
|
|
72
|
+
except Exception:
|
|
73
|
+
pass
|
|
74
|
+
return updated_node
|
|
75
|
+
|
|
76
|
+
def leave_Call(self, _original_node: cst.Call, updated_node: cst.Call) -> cst.BaseExpression:
|
|
77
|
+
# x.to_base_units() → x
|
|
78
|
+
if (
|
|
79
|
+
isinstance(updated_node.func, cst.Attribute)
|
|
80
|
+
and updated_node.func.attr.value == "to_base_units"
|
|
81
|
+
and not updated_node.args
|
|
82
|
+
):
|
|
83
|
+
return updated_node.func.value
|
|
84
|
+
|
|
85
|
+
# cast("Quantity", x) → x
|
|
86
|
+
if (
|
|
87
|
+
isinstance(updated_node.func, cst.Name)
|
|
88
|
+
and updated_node.func.value == "cast"
|
|
89
|
+
and len(updated_node.args) == 2
|
|
90
|
+
and isinstance(updated_node.args[0].value, cst.SimpleString)
|
|
91
|
+
and "Quantity" in updated_node.args[0].value.value
|
|
92
|
+
):
|
|
93
|
+
return updated_node.args[1].value
|
|
94
|
+
|
|
95
|
+
return updated_node
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# ── Boundary helpers ───────────────────────────────────────────────────────────
|
|
99
|
+
|
|
100
|
+
_SNAP_KEY = "__unit_jit_snap__"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _snapshot(obj: Any) -> Any:
|
|
104
|
+
"""Eagerly convert all Quantity attrs to SI floats, once at boundary entry.
|
|
105
|
+
|
|
106
|
+
Returns an instance of the same class (so method lookup still works) but
|
|
107
|
+
with a float-valued __dict__. Subsequent attribute access inside the fast
|
|
108
|
+
zone is a plain dict lookup — no Pint calls.
|
|
109
|
+
"""
|
|
110
|
+
try:
|
|
111
|
+
snap = object.__new__(type(obj))
|
|
112
|
+
snap_dict: dict[str, Any] = {_SNAP_KEY: True}
|
|
113
|
+
for name, val in getattr(obj, "__dict__", {}).items():
|
|
114
|
+
if isinstance(val, Quantity):
|
|
115
|
+
snap_dict[name] = val.to_base_units().magnitude
|
|
116
|
+
elif (
|
|
117
|
+
hasattr(val, "__dict__")
|
|
118
|
+
and not callable(val)
|
|
119
|
+
and not hasattr(val, "__array_interface__")
|
|
120
|
+
):
|
|
121
|
+
snap_dict[name] = _snapshot(val)
|
|
122
|
+
else:
|
|
123
|
+
snap_dict[name] = val
|
|
124
|
+
snap.__dict__.update(snap_dict)
|
|
125
|
+
return snap
|
|
126
|
+
except Exception:
|
|
127
|
+
return obj # fallback: use original object as-is
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _to_fast(arg: Any) -> Any:
|
|
131
|
+
"""Convert Quantity → SI float; snapshot complex objects; leave the rest."""
|
|
132
|
+
if isinstance(arg, Quantity):
|
|
133
|
+
return arg.to_base_units().magnitude
|
|
134
|
+
if isinstance(arg, (int, float, bool, str, bytes, type(None))):
|
|
135
|
+
return arg
|
|
136
|
+
if hasattr(arg, "__array_interface__"): # numpy arrays
|
|
137
|
+
return arg
|
|
138
|
+
if _SNAP_KEY in getattr(arg, "__dict__", {}):
|
|
139
|
+
return arg # already snapshotted
|
|
140
|
+
return _snapshot(arg)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _infer_units(result: Any) -> Any:
|
|
144
|
+
"""Extract SI unit structure from a Pint result (for later wrapping)."""
|
|
145
|
+
if isinstance(result, Quantity):
|
|
146
|
+
return result.to_base_units().units
|
|
147
|
+
if isinstance(result, (list, tuple)):
|
|
148
|
+
units = [r.to_base_units().units if isinstance(r, Quantity) else None for r in result]
|
|
149
|
+
return (type(result), units)
|
|
150
|
+
return None
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _wrap(result: Any, unit_info: Any) -> Any:
|
|
154
|
+
"""Wrap a float/array result back into Quantity using cached SI units."""
|
|
155
|
+
if unit_info is None:
|
|
156
|
+
return result
|
|
157
|
+
if isinstance(unit_info, tuple):
|
|
158
|
+
cls, units = unit_info
|
|
159
|
+
return cls(ureg.Quantity(r, u) if u is not None else r for r, u in zip(result, units))
|
|
160
|
+
return ureg.Quantity(result, unit_info)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
# ── Compilation ────────────────────────────────────────────────────────────────
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _strip_decorators(src: str) -> str:
|
|
167
|
+
lines = src.splitlines()
|
|
168
|
+
while lines and lines[0].lstrip().startswith("@"):
|
|
169
|
+
lines.pop(0)
|
|
170
|
+
return "\n".join(lines)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _compile_module(module_name: str) -> None:
|
|
174
|
+
"""Rewrite all @unit_jit functions from a module at once."""
|
|
175
|
+
funcs = _registry[module_name]
|
|
176
|
+
module_globals = funcs[0].__globals__
|
|
177
|
+
ureg_vars = {k: v for k, v in module_globals.items() if isinstance(v, UnitRegistry)}
|
|
178
|
+
stripper = _QuantityStripper(ureg_vars)
|
|
179
|
+
fast: dict[str, Callable[..., Any]] = {}
|
|
180
|
+
|
|
181
|
+
for func in funcs:
|
|
182
|
+
try:
|
|
183
|
+
src = inspect.getsource(func)
|
|
184
|
+
src = textwrap.dedent(src)
|
|
185
|
+
src = _strip_decorators(src)
|
|
186
|
+
tree = cst.parse_module(src)
|
|
187
|
+
new_src = tree.visit(stripper).code
|
|
188
|
+
namespace: dict[str, Any] = {}
|
|
189
|
+
exec(new_src, module_globals, namespace)
|
|
190
|
+
fast[func.__name__] = namespace[func.__name__]
|
|
191
|
+
tag = "rewrote" if new_src != src else "no changes"
|
|
192
|
+
print(f"[unit_jit] {tag}: '{func.__name__}'")
|
|
193
|
+
except Exception as exc:
|
|
194
|
+
print(f"[unit_jit] could not rewrite '{func.__name__}': {exc}")
|
|
195
|
+
fast[func.__name__] = func
|
|
196
|
+
|
|
197
|
+
_compiled[module_name] = fast
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# ── Decorator ──────────────────────────────────────────────────────────────────
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def unit_jit[**P, R](func: Callable[P, R]) -> Callable[P, R]:
|
|
204
|
+
"""JIT decorator: strips Pint overhead, runs fast after first call.
|
|
205
|
+
|
|
206
|
+
- First call: runs original function (Pint), infers return units, caches them.
|
|
207
|
+
- Subsequent calls: converts args to SI floats, runs rewritten version,
|
|
208
|
+
wraps result back into Quantity with cached units.
|
|
209
|
+
- If called from within the fast zone (inner call): skips boundary
|
|
210
|
+
conversion, calls rewritten version directly.
|
|
211
|
+
"""
|
|
212
|
+
module_name = func.__module__
|
|
213
|
+
_registry[module_name].append(func)
|
|
214
|
+
|
|
215
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
216
|
+
if module_name not in _compiled:
|
|
217
|
+
_compile_module(module_name)
|
|
218
|
+
|
|
219
|
+
fast_func = _compiled[module_name].get(func.__name__, func)
|
|
220
|
+
qualname = func.__qualname__
|
|
221
|
+
|
|
222
|
+
if _in_fast_zone():
|
|
223
|
+
# Already in float world: snapshot any objects still carrying
|
|
224
|
+
# Quantities (e.g. original self via Python's descriptor protocol).
|
|
225
|
+
fast_args = tuple(_to_fast(a) for a in args)
|
|
226
|
+
fast_kwargs = {k: _to_fast(v) for k, v in kwargs.items()}
|
|
227
|
+
return fast_func(*fast_args, **fast_kwargs)
|
|
228
|
+
|
|
229
|
+
# Entry point. First call: run original to infer return units + cache arg dimensions.
|
|
230
|
+
if qualname not in _return_units:
|
|
231
|
+
result = func(*args, **kwargs)
|
|
232
|
+
_return_units[qualname] = _infer_units(result)
|
|
233
|
+
_arg_dims[qualname] = (
|
|
234
|
+
[a.dimensionality if isinstance(a, Quantity) else None for a in args],
|
|
235
|
+
{
|
|
236
|
+
k: v.dimensionality if isinstance(v, Quantity) else None
|
|
237
|
+
for k, v in kwargs.items()
|
|
238
|
+
},
|
|
239
|
+
)
|
|
240
|
+
return result
|
|
241
|
+
|
|
242
|
+
# Subsequent calls: check dimensions, convert → fast → wrap.
|
|
243
|
+
pos_dims, kw_dims = _arg_dims[qualname]
|
|
244
|
+
for i, (arg, dim) in enumerate(zip(args, pos_dims)):
|
|
245
|
+
if dim is not None and isinstance(arg, Quantity) and arg.dimensionality != dim:
|
|
246
|
+
raise TypeError(
|
|
247
|
+
f"{func.__qualname__}: argument {i} has dimensions "
|
|
248
|
+
f"{dict(arg.dimensionality)}, expected {dict(dim)}"
|
|
249
|
+
)
|
|
250
|
+
for key, dim in kw_dims.items():
|
|
251
|
+
arg = kwargs.get(key)
|
|
252
|
+
if dim is not None and isinstance(arg, Quantity) and arg.dimensionality != dim: # type: ignore[union-attr]
|
|
253
|
+
raise TypeError(
|
|
254
|
+
f"{func.__qualname__}: argument '{key}' has dimensions "
|
|
255
|
+
f"{dict(arg.dimensionality)}, expected {dict(dim)}" # type: ignore[union-attr]
|
|
256
|
+
)
|
|
257
|
+
fast_args = tuple(_to_fast(a) for a in args)
|
|
258
|
+
fast_kwargs = {k: _to_fast(v) for k, v in kwargs.items()}
|
|
259
|
+
_fast_zone.active = True
|
|
260
|
+
try:
|
|
261
|
+
raw = fast_func(*fast_args, **fast_kwargs)
|
|
262
|
+
finally:
|
|
263
|
+
_fast_zone.active = False
|
|
264
|
+
return _wrap(raw, _return_units[qualname])
|
|
265
|
+
|
|
266
|
+
wrapper.__name__ = func.__name__
|
|
267
|
+
wrapper.__qualname__ = func.__qualname__
|
|
268
|
+
wrapper.__module__ = func.__module__
|
|
269
|
+
wrapper.__doc__ = func.__doc__
|
|
270
|
+
wrapper.__annotations__ = func.__annotations__
|
|
271
|
+
return wrapper # type: ignore[return-value]
|
unit_jit/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unit-jit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: JIT unit-stripping decorator: write Pint-annotated code, run at float speed
|
|
5
|
+
Author: Matthias Függer
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: libcst>=1.4
|
|
10
|
+
Requires-Dist: pint>=0.24
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: numpy>=1.26; extra == 'dev'
|
|
13
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# unit-jit
|
|
18
|
+
|
|
19
|
+
JIT unit-stripping decorator for [Pint](https://pint.readthedocs.io)-annotated Python. Write clean, unit-safe code; pay no Pint overhead in hot loops.
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from unit_jit import unit_jit, ureg
|
|
23
|
+
|
|
24
|
+
@unit_jit
|
|
25
|
+
def simulate(n: int) -> np.ndarray:
|
|
26
|
+
mrna = 10.0 * ureg.mol / ureg.L
|
|
27
|
+
dt = 0.1 * ureg.s
|
|
28
|
+
delta = 0.01 / ureg.s
|
|
29
|
+
out = np.empty(n)
|
|
30
|
+
for i in range(n):
|
|
31
|
+
mrna = mrna - delta * mrna * dt
|
|
32
|
+
out[i] = mrna.to_base_units().magnitude
|
|
33
|
+
return out
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
First call runs the original Pint function (warm-up). All subsequent calls run a rewritten, pure-float version — **~10× faster** for tight loops.
|
|
37
|
+
|
|
38
|
+
## How it works
|
|
39
|
+
|
|
40
|
+
1. **Module-level compilation** — on first call, all `@unit_jit` functions in the same module are rewritten together: `.magnitude`, `.to_base_units()`, and `cast("Quantity", x)` are stripped from the source.
|
|
41
|
+
2. **Eager snapshot** — Quantity attributes on objects (e.g. `self.params.alpha`) are pre-converted to SI floats once at boundary entry. Attribute access inside the loop is a plain dict lookup.
|
|
42
|
+
3. **Fast zone** — a thread-local flag marks the outermost `@unit_jit` frame. Inner `@unit_jit` calls skip boundary conversion entirely.
|
|
43
|
+
4. **Return wrapping** — the SI unit of the return value is inferred from the first call and used to wrap subsequent results back into `Quantity`.
|
|
44
|
+
5. **Dimension guard** — argument dimensions are cached from the first call; any later call with a different dimension raises `TypeError` immediately.
|
|
45
|
+
|
|
46
|
+
The right entry point is the **outermost function that owns the hot loop** — not the leaf functions it calls.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# uv (recommended)
|
|
52
|
+
uv add unit-jit
|
|
53
|
+
|
|
54
|
+
# pip
|
|
55
|
+
pip install unit-jit
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
From source:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
git clone ...
|
|
62
|
+
cd unit-jit
|
|
63
|
+
|
|
64
|
+
# uv
|
|
65
|
+
uv sync --extra dev
|
|
66
|
+
|
|
67
|
+
# pip
|
|
68
|
+
pip install -e ".[dev]"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
### Simple function
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from unit_jit import unit_jit, ureg
|
|
77
|
+
|
|
78
|
+
@unit_jit
|
|
79
|
+
def velocity(d, t):
|
|
80
|
+
return d / t
|
|
81
|
+
|
|
82
|
+
velocity(10 * ureg.m, 2 * ureg.s) # warm-up (runs Pint)
|
|
83
|
+
velocity(10 * ureg.m, 2 * ureg.s) # fast (pure float internally)
|
|
84
|
+
velocity(10 * ureg.cm, 2 * ureg.s) # fine — same dimension, different unit
|
|
85
|
+
velocity(10 * ureg.m, 2 * ureg.m) # TypeError — wrong dimension for arg 1
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Class with Quantity attributes
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from dataclasses import dataclass
|
|
92
|
+
from unit_jit import unit_jit, ureg
|
|
93
|
+
|
|
94
|
+
@dataclass
|
|
95
|
+
class Params:
|
|
96
|
+
alpha: Quantity # [mol/L/s]
|
|
97
|
+
delta: Quantity # [1/s]
|
|
98
|
+
|
|
99
|
+
class Model:
|
|
100
|
+
def __init__(self, params):
|
|
101
|
+
self.params = params
|
|
102
|
+
|
|
103
|
+
@unit_jit
|
|
104
|
+
def rate(self, mrna):
|
|
105
|
+
return self.params.alpha - self.params.delta * mrna
|
|
106
|
+
|
|
107
|
+
@unit_jit # ← entry point: owns the hot loop
|
|
108
|
+
def simulate(self, n):
|
|
109
|
+
mrna = self.params.alpha / self.params.delta
|
|
110
|
+
out = np.empty(n)
|
|
111
|
+
for i in range(n):
|
|
112
|
+
mrna = mrna + self.rate(mrna) * (0.1 * ureg.s) # rate() in fast zone
|
|
113
|
+
out[i] = mrna.to_base_units().magnitude
|
|
114
|
+
return out
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`self.params.alpha` and all other Quantity attributes are converted to SI floats once when `simulate` is first called fast; `self.rate()` is called from inside the fast zone, so it skips boundary conversion entirely.
|
|
118
|
+
|
|
119
|
+
## Running tests
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pytest
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
Apache-2.0
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
unit_jit/__init__.py,sha256=OgVmvAkPViPyh8T5kHYnz-biJcdRf3INJEoFpgWdg1Q,11026
|
|
2
|
+
unit_jit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
unit_jit-0.1.0.dist-info/METADATA,sha256=dk69UPb6uJ_9aqbyP43m3YO3oMqcQM_8MRuP_ueCdv4,3739
|
|
4
|
+
unit_jit-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
5
|
+
unit_jit-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
6
|
+
unit_jit-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|