checkpointer 1.0.0__py3-none-any.whl → 1.2.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.
- checkpointer/function_body.py +34 -43
- checkpointer/utils.py +5 -6
- checkpointer-1.2.0.dist-info/METADATA +16 -0
- checkpointer-1.2.0.dist-info/RECORD +12 -0
- {checkpointer-1.0.0.dist-info → checkpointer-1.2.0.dist-info}/WHEEL +1 -2
- checkpointer-1.0.0.dist-info/LICENSE.txt → checkpointer-1.2.0.dist-info/licenses/LICENSE +1 -1
- checkpointer-1.0.0.dist-info/METADATA +0 -16
- checkpointer-1.0.0.dist-info/RECORD +0 -13
- checkpointer-1.0.0.dist-info/top_level.txt +0 -1
checkpointer/function_body.py
CHANGED
@@ -1,58 +1,49 @@
|
|
1
1
|
import inspect
|
2
2
|
from types import FunctionType, CodeType
|
3
|
-
from relib.raypipe import raypipe
|
4
3
|
import relib.hashing as hashing
|
5
4
|
from pathlib import Path
|
6
5
|
from .utils import unwrap_func
|
7
6
|
|
8
7
|
cwd = Path.cwd()
|
9
8
|
|
10
|
-
def
|
11
|
-
return Path(inspect.getfile(
|
9
|
+
def get_fn_path(fn):
|
10
|
+
return Path(inspect.getfile(fn)).absolute()
|
12
11
|
|
13
|
-
def get_function_body(
|
12
|
+
def get_function_body(fn):
|
14
13
|
# TODO: Strip comments
|
15
|
-
lines = inspect.getsourcelines(
|
14
|
+
lines = inspect.getsourcelines(fn)[0]
|
16
15
|
lines = [line.rstrip() for line in lines]
|
17
16
|
lines = [line for line in lines if line]
|
18
17
|
return '\n'.join(lines)
|
19
18
|
|
20
19
|
def get_code_children(__code__):
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
return funcs
|
53
|
-
|
54
|
-
def get_function_hash(func):
|
55
|
-
funcs = [func] + get_func_children(func)
|
56
|
-
function_bodies = raypipe.map(get_function_body).compute(funcs)
|
57
|
-
function_bodies_hash = hashing.hash(function_bodies)
|
58
|
-
return function_bodies_hash
|
20
|
+
consts = [const for const in __code__.co_consts if isinstance(const, CodeType)]
|
21
|
+
children = [child for const in consts for child in get_code_children(const)]
|
22
|
+
return list(__code__.co_names) + children
|
23
|
+
|
24
|
+
def is_user_fn(candidate_fn, cleared_fns):
|
25
|
+
return isinstance(candidate_fn, FunctionType) \
|
26
|
+
and candidate_fn not in cleared_fns \
|
27
|
+
and cwd in get_fn_path(candidate_fn).parents
|
28
|
+
|
29
|
+
def append_fn_children(fn, cleared_fns):
|
30
|
+
code_children = get_code_children(fn.__code__)
|
31
|
+
fn_children = [unwrap_func(fn.__globals__.get(co_name, None)) for co_name in code_children]
|
32
|
+
fn_children = [child for child in fn_children if is_user_fn(child, cleared_fns)]
|
33
|
+
|
34
|
+
for fn in fn_children:
|
35
|
+
cleared_fns.add(fn)
|
36
|
+
|
37
|
+
for child_fn in fn_children:
|
38
|
+
append_fn_children(child_fn, cleared_fns)
|
39
|
+
|
40
|
+
def get_fn_children(fn):
|
41
|
+
cleared_fns = set()
|
42
|
+
append_fn_children(fn, cleared_fns)
|
43
|
+
return sorted(cleared_fns, key=lambda fn: fn.__name__)
|
44
|
+
|
45
|
+
def get_function_hash(fn):
|
46
|
+
fns = [fn] + get_fn_children(fn)
|
47
|
+
fn_bodies = list(map(get_function_body, fns))
|
48
|
+
fn_bodies_hash = hashing.hash(fn_bodies)
|
49
|
+
return fn_bodies_hash
|
checkpointer/utils.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
import
|
1
|
+
import types
|
2
2
|
|
3
3
|
def unwrap_func(func):
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
return func
|
4
|
+
while hasattr(func, '__wrapped__'):
|
5
|
+
func = func.__wrapped__
|
6
|
+
return func
|
8
7
|
|
9
|
-
@
|
8
|
+
@types.coroutine
|
10
9
|
def coroutine_as_generator(coroutine):
|
11
10
|
val = yield from coroutine
|
12
11
|
return val
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: checkpointer
|
3
|
+
Version: 1.2.0
|
4
|
+
Project-URL: Repository, https://github.com/Reddan/checkpointer.git
|
5
|
+
Author: Hampus Hallman
|
6
|
+
License: Copyright 2024 Hampus Hallman
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
13
|
+
License-File: LICENSE
|
14
|
+
Requires-Python: >=3.8
|
15
|
+
Requires-Dist: relib
|
16
|
+
Requires-Dist: termcolor
|
@@ -0,0 +1,12 @@
|
|
1
|
+
checkpointer/__init__.py,sha256=_RYcKsZbeUf08KZ-DcXlNn4eAMWh2LN9o-KvchYVmmk,380
|
2
|
+
checkpointer/checkpoint.py,sha256=FyL78HvAvPtgl-esiAkt-CdekT18J2Sh0SriMtX4QLc,2367
|
3
|
+
checkpointer/function_body.py,sha256=vBZNdPuF8gp11Z_NvjoClmMToHR8ynY7tPykE2u25oE,1577
|
4
|
+
checkpointer/storage.py,sha256=Ofuh0dKF5vk4_B4djt3Q6qyZhIO5f59uCNCZjMrto0U,1782
|
5
|
+
checkpointer/utils.py,sha256=CC3-W0RgHEP92zt9atAM2gP0fDrxANOdyMH8F5xaIdU,357
|
6
|
+
checkpointer/storages/bcolz_storage.py,sha256=Yk7FI75noe9hZBWVFIRetiFSR7tkzbryYlBmxX-lVlw,2728
|
7
|
+
checkpointer/storages/memory_storage.py,sha256=S4SgKSApbQE-pxxKRWLNJqyZMRQwaw5-N0DOIsZM7mE,364
|
8
|
+
checkpointer/storages/pickle_storage.py,sha256=zcnX1GG6XPHvVxi7gCab5oFxKoz5E7LZHYH74VL1hkY,1542
|
9
|
+
checkpointer-1.2.0.dist-info/METADATA,sha256=9oGYe0jvzZfuMtleqqpGOBlJspbxxJTynXv7vuA2G6o,1349
|
10
|
+
checkpointer-1.2.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
11
|
+
checkpointer-1.2.0.dist-info/licenses/LICENSE,sha256=0cmUKqBotzbBcysIexd52AhjwbphhlGYiWbvg5l2QAU,1054
|
12
|
+
checkpointer-1.2.0.dist-info/RECORD,,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright
|
1
|
+
Copyright 2024 Hampus Hallman
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
4
|
|
@@ -1,16 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: checkpointer
|
3
|
-
Version: 1.0.0
|
4
|
-
Summary: UNKNOWN
|
5
|
-
Home-page: https://github.com/Reddan/checkpointer
|
6
|
-
Author: Hampus Hallman
|
7
|
-
Author-email: me@hampushallman.com
|
8
|
-
License: MIT
|
9
|
-
Platform: UNKNOWN
|
10
|
-
Requires-Python: ~=3.5
|
11
|
-
License-File: LICENSE.txt
|
12
|
-
Requires-Dist: relib
|
13
|
-
Requires-Dist: termcolor
|
14
|
-
|
15
|
-
UNKNOWN
|
16
|
-
|
@@ -1,13 +0,0 @@
|
|
1
|
-
checkpointer/__init__.py,sha256=_RYcKsZbeUf08KZ-DcXlNn4eAMWh2LN9o-KvchYVmmk,380
|
2
|
-
checkpointer/checkpoint.py,sha256=FyL78HvAvPtgl-esiAkt-CdekT18J2Sh0SriMtX4QLc,2367
|
3
|
-
checkpointer/function_body.py,sha256=kBsgCPeNgQzgXFToTuqQYYvAQicetXtv-UGwyd5b4Ew,1760
|
4
|
-
checkpointer/storage.py,sha256=Ofuh0dKF5vk4_B4djt3Q6qyZhIO5f59uCNCZjMrto0U,1782
|
5
|
-
checkpointer/utils.py,sha256=5CFQHUAlrORFpcg-TGuvAUQDeCEXvvx6yPl8mor5jh8,381
|
6
|
-
checkpointer/storages/bcolz_storage.py,sha256=Yk7FI75noe9hZBWVFIRetiFSR7tkzbryYlBmxX-lVlw,2728
|
7
|
-
checkpointer/storages/memory_storage.py,sha256=S4SgKSApbQE-pxxKRWLNJqyZMRQwaw5-N0DOIsZM7mE,364
|
8
|
-
checkpointer/storages/pickle_storage.py,sha256=zcnX1GG6XPHvVxi7gCab5oFxKoz5E7LZHYH74VL1hkY,1542
|
9
|
-
checkpointer-1.0.0.dist-info/LICENSE.txt,sha256=2c7g4mni-RUemFGkk6GnoFwknh-leF04BF_J_3gp4sg,1054
|
10
|
-
checkpointer-1.0.0.dist-info/METADATA,sha256=kmuSQOTbRa5KaFBlr48K-Fin7bRD3L7aIZiC0Lx8v6o,317
|
11
|
-
checkpointer-1.0.0.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
|
12
|
-
checkpointer-1.0.0.dist-info/top_level.txt,sha256=uF0eyHpShnsHI3sobErnhQ8LWCT8DPViqAznKeTaZlw,13
|
13
|
-
checkpointer-1.0.0.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
checkpointer
|