zee 0.0.4__py3-none-any.whl → 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.
zee/__init__.py CHANGED
@@ -18,5 +18,6 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
19
 
20
20
 
21
- from .dicts import flatten_dict, query_dict_from_string, update_dict_by_string
22
- from .modules import load_module
21
+ from .dictils import (FixedDict, flatten_dict, query_dict_from_string,
22
+ update_dict_by_string)
23
+ from .modules import create_module_from_string, load_module
@@ -18,9 +18,23 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
19
 
20
20
 
21
+ from collections import OrderedDict
21
22
  from typing import Any
22
23
 
23
24
 
25
+ class FixedDict(OrderedDict):
26
+ def __init__(self, maxlen: int = 1024):
27
+ super().__init__()
28
+ self.maxlen = maxlen
29
+
30
+ def __setitem__(self, key, value):
31
+ if key in self:
32
+ del self[key]
33
+ super().__setitem__(key, value)
34
+ if len(self) > self.maxlen:
35
+ self.popitem(last=False) # FIFO
36
+
37
+
24
38
  def update_dict_by_string(target: dict, path: str, value: Any = None):
25
39
  """Update a target dict by a path separated by dot
26
40
 
zee/modules.py CHANGED
@@ -18,6 +18,7 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
19
 
20
20
 
21
+ import sys
21
22
  from importlib import import_module
22
23
  from importlib.util import module_from_spec, spec_from_file_location
23
24
  from pathlib import Path
@@ -39,9 +40,9 @@ def load_module(modname: str, location: str = '', verbose: bool = True) -> Modul
39
40
  # from file location
40
41
  name = modname.removeprefix('./').removesuffix('.py').replace('/', '.')
41
42
  if not location:
42
- path = Path.cwd()/modname
43
+ path = Path.cwd() / modname
43
44
  else:
44
- path = Path(location)/modname
45
+ path = Path(location) / modname
45
46
  if verbose:
46
47
  print('loading', path)
47
48
  spec = spec_from_file_location(name, path)
@@ -53,3 +54,16 @@ def load_module(modname: str, location: str = '', verbose: bool = True) -> Modul
53
54
  # package, name = name.rsplit('.', 1)
54
55
  module = import_module(name)
55
56
  return module
57
+
58
+
59
+ def create_module_from_string(name: str, code: str, ns={}) -> ModuleType:
60
+ # code = Path(file_path).read_text(encoding="utf-8")
61
+
62
+ module = ModuleType(name)
63
+ module.__file__ = f'quark/{name}'
64
+ module.__package__ = name.rpartition('.')[0]
65
+ module.__loader__ = None
66
+
67
+ sys.modules[name] = module
68
+ exec(code, module.__dict__ | ns)
69
+ return module
@@ -1,24 +1,25 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: zee
3
- Version: 0.0.4
4
- Summary: for python
5
- Author-email: YL <fengyl@pku.edu.cn>
6
- Project-URL: homepage, https://github.com
7
- Project-URL: bugs, https://github.com
3
+ Version: 0.1.0
4
+ Summary: common utils
5
+ Author-email: YL <fengyl@pku.org.cn>
6
+ License-Expression: MIT
7
+ Project-URL: homepage, https://gitee.com
8
+ Project-URL: bugs, https://gitee.com
8
9
  Classifier: Development Status :: 5 - Production/Stable
9
10
  Classifier: Intended Audience :: Developers
10
11
  Classifier: Intended Audience :: Science/Research
11
- Classifier: License :: OSI Approved :: MIT License
12
12
  Classifier: Natural Language :: Chinese (Simplified)
13
13
  Classifier: Natural Language :: English
14
14
  Classifier: Operating System :: Microsoft :: Windows
15
15
  Classifier: Operating System :: POSIX :: Linux
16
16
  Classifier: Operating System :: MacOS :: MacOS X
17
- Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Topic :: Scientific/Engineering :: Physics
19
- Requires-Python: >=3.10
19
+ Requires-Python: >=3.12
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
+ Dynamic: license-file
22
23
 
23
24
  dicts
24
25
 
@@ -0,0 +1,8 @@
1
+ zee/__init__.py,sha256=-Akx3D5dvfpTbp-ebchm1IFBC4mJXgDbStjCqL0VuZM,1283
2
+ zee/dictils.py,sha256=goMDHHYRD-l0oHmKgvyt514hnEbvK3eNa1qX7Z6rxt4,4552
3
+ zee/modules.py,sha256=qEKhKanLk2IysE2WlUjrAsZHZ7KJZMcWJKws-bGrcGI,2831
4
+ zee-0.1.0.dist-info/licenses/LICENSE,sha256=x3_XlAxJv8eKBMOwlOY6BuAG9rGlqXiVG7PsFJb7nf8,1080
5
+ zee-0.1.0.dist-info/METADATA,sha256=lyE6tPXixpMzYQLMQy64FW3QYfqErRhEb3p1es-MZjA,855
6
+ zee-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ zee-0.1.0.dist-info/top_level.txt,sha256=dd8XvBYxs9R92Nb3XbtQNIVj1TBR3v3iKHmQrc9Nkhs,4
8
+ zee-0.1.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.2.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- zee/__init__.py,sha256=daAON9WVwYf7vKJ_87v69ZuVxortr1bKB1yuLsigGd0,1218
2
- zee/dicts.py,sha256=_FCLdne7rxIjU7b1LvFjKxl8Njx55eD3D3UT4qpdWPY,4159
3
- zee/modules.py,sha256=ZarDpqQGUjAGfFYT3q2TQcrMosNW3CEkyG_MfWWaO7U,2435
4
- zee-0.0.4.dist-info/LICENSE,sha256=x3_XlAxJv8eKBMOwlOY6BuAG9rGlqXiVG7PsFJb7nf8,1080
5
- zee-0.0.4.dist-info/METADATA,sha256=tfufSfUsyLgtA5GV5Z_hA2_ewVXziYHelW--4kTso9I,859
6
- zee-0.0.4.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
7
- zee-0.0.4.dist-info/top_level.txt,sha256=dd8XvBYxs9R92Nb3XbtQNIVj1TBR3v3iKHmQrc9Nkhs,4
8
- zee-0.0.4.dist-info/RECORD,,