zee 0.0.3__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 +4 -3
- zee/{dicts.py → dictils.py} +30 -7
- zee/modules.py +16 -3
- {zee-0.0.3.dist-info → zee-0.1.0.dist-info}/METADATA +10 -9
- zee-0.1.0.dist-info/RECORD +8 -0
- {zee-0.0.3.dist-info → zee-0.1.0.dist-info}/WHEEL +1 -1
- zee-0.0.3.dist-info/RECORD +0 -8
- {zee-0.0.3.dist-info → zee-0.1.0.dist-info/licenses}/LICENSE +0 -0
- {zee-0.0.3.dist-info → zee-0.1.0.dist-info}/top_level.txt +0 -0
zee/__init__.py
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# of this software and associated documentation files(the "Software"), to deal
|
|
5
5
|
# in the Software without restriction, including without limitation the rights
|
|
6
6
|
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
8
|
# furnished to do so, subject to the following conditions:
|
|
9
9
|
|
|
10
10
|
# The above copyright notice and this permission notice shall be included in
|
|
@@ -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 .
|
|
22
|
-
|
|
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
|
zee/{dicts.py → dictils.py}
RENAMED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# of this software and associated documentation files(the "Software"), to deal
|
|
5
5
|
# in the Software without restriction, including without limitation the rights
|
|
6
6
|
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
8
|
# furnished to do so, subject to the following conditions:
|
|
9
9
|
|
|
10
10
|
# The above copyright notice and this permission notice shall be included in
|
|
@@ -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
|
|
|
@@ -64,6 +78,17 @@ def string_to_dict(path: str, value: Any = None):
|
|
|
64
78
|
return d
|
|
65
79
|
|
|
66
80
|
|
|
81
|
+
def flatten_dict(d: dict, parent: str = '', sep: str = '.'):
|
|
82
|
+
items = {}
|
|
83
|
+
for k, v in d.items():
|
|
84
|
+
nkey = f"{parent}{sep}{k}" if parent else k
|
|
85
|
+
if isinstance(v, dict):
|
|
86
|
+
items.update(flatten_dict(v, nkey, sep=sep))
|
|
87
|
+
else:
|
|
88
|
+
items[nkey] = v
|
|
89
|
+
return items
|
|
90
|
+
|
|
91
|
+
|
|
67
92
|
def merge_dict(target: dict, source: dict):
|
|
68
93
|
"""Merge source to target
|
|
69
94
|
|
|
@@ -78,7 +103,7 @@ def merge_dict(target: dict, source: dict):
|
|
|
78
103
|
tuple: a tuple contains the key and value
|
|
79
104
|
"""
|
|
80
105
|
for k in set(target.keys()) | set(source.keys()):
|
|
81
|
-
|
|
106
|
+
# for k in sorted(set(target.keys()) | set(source.keys())):
|
|
82
107
|
if k in target and k in source:
|
|
83
108
|
if isinstance(target[k], dict) and isinstance(source[k], dict):
|
|
84
109
|
yield (k, dict(merge_dict(target[k], source[k])))
|
|
@@ -112,9 +137,7 @@ def query_dict_from_string(path: str, source: dict = {}):
|
|
|
112
137
|
source = source[key]
|
|
113
138
|
except KeyError as e:
|
|
114
139
|
raise KeyError(f'{path} not found!')
|
|
115
|
-
|
|
116
|
-
return source
|
|
117
|
-
# if not isinstance(source, dict):
|
|
118
|
-
# return source
|
|
119
140
|
|
|
120
|
-
|
|
141
|
+
return source
|
|
142
|
+
# if not isinstance(source, dict):
|
|
143
|
+
# return source
|
zee/modules.py
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# of this software and associated documentation files(the "Software"), to deal
|
|
5
5
|
# in the Software without restriction, including without limitation the rights
|
|
6
6
|
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
8
|
# furnished to do so, subject to the following conditions:
|
|
9
9
|
|
|
10
10
|
# The above copyright notice and this permission notice shall be included in
|
|
@@ -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)
|
|
@@ -54,3 +55,15 @@ def load_module(modname: str, location: str = '', verbose: bool = True) -> Modul
|
|
|
54
55
|
module = import_module(name)
|
|
55
56
|
return module
|
|
56
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
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: zee
|
|
3
|
-
Version: 0.0
|
|
4
|
-
Summary:
|
|
5
|
-
Author-email: YL <fengyl@pku.
|
|
6
|
-
|
|
7
|
-
Project-URL:
|
|
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.
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
18
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
19
|
-
Requires-Python: >=3.
|
|
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,,
|
zee-0.0.3.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
zee/__init__.py,sha256=YpyYkeK8s_tMGoGxsmquFVEKoCA-BFFCZ7SKd2U4gaA,1205
|
|
2
|
-
zee/dicts.py,sha256=KFZ51DI09sJN9MtD5Bw5EC40w-AQ9SurtIXOkEhPVwE,3862
|
|
3
|
-
zee/modules.py,sha256=TEjDoVFKt7z6Hr2J5_AS0gmGhmEb-avBt4GRFraNtE4,2438
|
|
4
|
-
zee-0.0.3.dist-info/LICENSE,sha256=x3_XlAxJv8eKBMOwlOY6BuAG9rGlqXiVG7PsFJb7nf8,1080
|
|
5
|
-
zee-0.0.3.dist-info/METADATA,sha256=bkbR2JaZTH_jphiIiqSJ5295TvIiD2xvLMeQ-oraqE0,859
|
|
6
|
-
zee-0.0.3.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
7
|
-
zee-0.0.3.dist-info/top_level.txt,sha256=dd8XvBYxs9R92Nb3XbtQNIVj1TBR3v3iKHmQrc9Nkhs,4
|
|
8
|
-
zee-0.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|