checkpointer 1.1.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.
@@ -6,12 +6,12 @@ from .utils import unwrap_func
6
6
 
7
7
  cwd = Path.cwd()
8
8
 
9
- def get_func_path(func):
10
- return Path(inspect.getfile(func)).absolute()
9
+ def get_fn_path(fn):
10
+ return Path(inspect.getfile(fn)).absolute()
11
11
 
12
- def get_function_body(func):
12
+ def get_function_body(fn):
13
13
  # TODO: Strip comments
14
- lines = inspect.getsourcelines(func)[0]
14
+ lines = inspect.getsourcelines(fn)[0]
15
15
  lines = [line.rstrip() for line in lines]
16
16
  lines = [line for line in lines if line]
17
17
  return '\n'.join(lines)
@@ -21,32 +21,29 @@ def get_code_children(__code__):
21
21
  children = [child for const in consts for child in get_code_children(const)]
22
22
  return list(__code__.co_names) + children
23
23
 
24
- def get_func_children(func, neighbor_funcs=[]):
25
- def get_candidate_func(co_name):
26
- candidate_func = func.__globals__.get(co_name, None)
27
- return unwrap_func(candidate_func)
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
28
 
29
- def clear_candidate(candidate_func):
30
- return isinstance(candidate_func, FunctionType) \
31
- and candidate_func not in neighbor_funcs \
32
- and cwd in get_func_path(candidate_func).parents
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
33
 
34
- code_children = get_code_children(func.__code__)
34
+ for fn in fn_children:
35
+ cleared_fns.add(fn)
35
36
 
36
- func_children = [get_candidate_func(child) for child in code_children]
37
- func_children = [child for child in func_children if clear_candidate(child)]
37
+ for child_fn in fn_children:
38
+ append_fn_children(child_fn, cleared_fns)
38
39
 
39
- funcs = [func] + [
40
- deep_child
41
- for child_func in func_children
42
- for deep_child in get_func_children(child_func, func_children)
43
- ]
44
- funcs = sorted(set(funcs), key=lambda func: func.__name__)
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__)
45
44
 
46
- return funcs
47
-
48
- def get_function_hash(func):
49
- funcs = [func] + get_func_children(func)
50
- function_bodies = list(map(get_function_body, funcs))
51
- function_bodies_hash = hashing.hash(function_bodies)
52
- return function_bodies_hash
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,10 +1,9 @@
1
1
  import types
2
2
 
3
3
  def unwrap_func(func):
4
- if hasattr(func, '__wrapped__'):
5
- return unwrap_func(func.__wrapped__)
6
- else:
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):
@@ -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,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -1,4 +1,4 @@
1
- Copyright 2018 Hampus Hallman
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,12 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: checkpointer
3
- Version: 1.1.0
4
- Home-page: https://github.com/Reddan/checkpointer
5
- Author: Hampus Hallman
6
- Author-email: me@hampushallman.com
7
- License: MIT
8
- Requires-Python: ~=3.5
9
- License-File: LICENSE.txt
10
- Requires-Dist: relib
11
- Requires-Dist: termcolor
12
-
@@ -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=aitzBFoEIo_E-aL2oe4Nr_T_Oy8ehKInGb1XYjeLzX8,1703
4
- checkpointer/storage.py,sha256=Ofuh0dKF5vk4_B4djt3Q6qyZhIO5f59uCNCZjMrto0U,1782
5
- checkpointer/utils.py,sha256=Kzh2qXxq2Lgjiqfv6KcOwXdw7sh70uCn4a_uXYwLhiM,377
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.1.0.dist-info/LICENSE.txt,sha256=2c7g4mni-RUemFGkk6GnoFwknh-leF04BF_J_3gp4sg,1054
10
- checkpointer-1.1.0.dist-info/METADATA,sha256=_isCKu9zdEI1Z-umSB6mr-X7lEVBVjlU_QvRNYolUNQ,273
11
- checkpointer-1.1.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
12
- checkpointer-1.1.0.dist-info/top_level.txt,sha256=uF0eyHpShnsHI3sobErnhQ8LWCT8DPViqAznKeTaZlw,13
13
- checkpointer-1.1.0.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- checkpointer