vardict 1.0.0.post1__tar.gz
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.
- vardict-1.0.0.post1/PKG-INFO +18 -0
- vardict-1.0.0.post1/README.md +4 -0
- vardict-1.0.0.post1/pyproject.toml +31 -0
- vardict-1.0.0.post1/setup.cfg +4 -0
- vardict-1.0.0.post1/tests/test_vardict.py +22 -0
- vardict-1.0.0.post1/vardict/LICENSE.txt +20 -0
- vardict-1.0.0.post1/vardict/__init__.py +2 -0
- vardict-1.0.0.post1/vardict/vardict.py +34 -0
- vardict-1.0.0.post1/vardict.egg-info/PKG-INFO +18 -0
- vardict-1.0.0.post1/vardict.egg-info/SOURCES.txt +11 -0
- vardict-1.0.0.post1/vardict.egg-info/dependency_links.txt +1 -0
- vardict-1.0.0.post1/vardict.egg-info/requires.txt +1 -0
- vardict-1.0.0.post1/vardict.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vardict
|
|
3
|
+
Version: 1.0.0.post1
|
|
4
|
+
Summary: vardict - dict with variables
|
|
5
|
+
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/salabim/vardict
|
|
7
|
+
Project-URL: Repository, https://github.com/salabim/vardict
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: executing>=2.2.0
|
|
14
|
+
|
|
15
|
+
# vardict
|
|
16
|
+
|
|
17
|
+
### Introduction
|
|
18
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vardict"
|
|
7
|
+
authors = [
|
|
8
|
+
{name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com"}
|
|
9
|
+
]
|
|
10
|
+
description = "vardict - dict with variables"
|
|
11
|
+
version = "1.0.0-1"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.9"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"executing>=2.2.0",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 5 - Production/Stable",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only"
|
|
21
|
+
]
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/salabim/vardict"
|
|
24
|
+
Repository = "https://github.com/salabim/vardict"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools]
|
|
27
|
+
packages = ["vardict"]
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.package-data]
|
|
30
|
+
"*" = ["*.txt"]
|
|
31
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
if __name__ == "__main__": # to make the tests run without the pytest cli
|
|
4
|
+
import os, sys # three lines to use the local package and chdir
|
|
5
|
+
os.chdir(os.path.dirname(__file__))
|
|
6
|
+
sys.path.insert(0, os.path.dirname(__file__) + "/../")
|
|
7
|
+
|
|
8
|
+
from vardict import vardict
|
|
9
|
+
|
|
10
|
+
def test_normal():
|
|
11
|
+
one = 1
|
|
12
|
+
two = 2
|
|
13
|
+
numbers12 = {"one": 1, "two": 2}
|
|
14
|
+
numbers3 = {"three": 3}
|
|
15
|
+
|
|
16
|
+
assert vardict(one, two, three=3) == {"one": 1, "two": 2, "three": 3}
|
|
17
|
+
assert vardict(numbers12, three=3) == {"numbers12": {"one": 1, "two": 2}, "three": 3}
|
|
18
|
+
assert vardict(numbers12, numbers3) == {"numbers12": {"one": 1, "two": 2}, "numbers3": {"three": 3}}
|
|
19
|
+
assert vardict(three=3) == {"three": 3}
|
|
20
|
+
|
|
21
|
+
if __name__ == "__main__":
|
|
22
|
+
pytest.main(["-vv", "-s", "-x", __file__])
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 Ruud van der Ham, ruud@salabim.org
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
import executing
|
|
3
|
+
|
|
4
|
+
__version__ = "1.0.0"
|
|
5
|
+
|
|
6
|
+
class vardict(dict):
|
|
7
|
+
def __new__(cls, *args, **kwargs):
|
|
8
|
+
if len(args) == 0:
|
|
9
|
+
dict(kwargs)
|
|
10
|
+
call_frame = inspect.currentframe().f_back
|
|
11
|
+
call_node = executing.Source.executing(call_frame).node
|
|
12
|
+
if call_node is None:
|
|
13
|
+
raise ValueError("could not assess variables")
|
|
14
|
+
result = {}
|
|
15
|
+
source = executing.Source.for_frame(call_frame)
|
|
16
|
+
for node, right in zip(call_node.args, args):
|
|
17
|
+
left = source.asttokens().get_text(node)
|
|
18
|
+
if not left.isidentifier():
|
|
19
|
+
raise ValueError(f"{left!r} not a valid identifier")
|
|
20
|
+
if left in kwargs:
|
|
21
|
+
raise ValueError(f"parameter {left!r} repeated")
|
|
22
|
+
result[left] = right
|
|
23
|
+
return result | kwargs
|
|
24
|
+
|
|
25
|
+
if __name__ == "__main__":
|
|
26
|
+
one = 1
|
|
27
|
+
two = 2
|
|
28
|
+
numbers12 = {"one": 1, "two": 2}
|
|
29
|
+
numbers3 = {"three": 3}
|
|
30
|
+
|
|
31
|
+
assert vardict(one, two, three=3) == {"one": 1, "two": 2, "three": 3}
|
|
32
|
+
assert vardict(numbers12, three=3) == {"numbers12": {"one": 1, "two": 2}, "three": 3}
|
|
33
|
+
assert vardict(numbers12, numbers3) == {"numbers12": {"one": 1, "two": 2}, "numbers3": {"three": 3}}
|
|
34
|
+
assert vardict(three=3) == {"three": 3}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vardict
|
|
3
|
+
Version: 1.0.0.post1
|
|
4
|
+
Summary: vardict - dict with variables
|
|
5
|
+
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/salabim/vardict
|
|
7
|
+
Project-URL: Repository, https://github.com/salabim/vardict
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: executing>=2.2.0
|
|
14
|
+
|
|
15
|
+
# vardict
|
|
16
|
+
|
|
17
|
+
### Introduction
|
|
18
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
tests/test_vardict.py
|
|
4
|
+
vardict/LICENSE.txt
|
|
5
|
+
vardict/__init__.py
|
|
6
|
+
vardict/vardict.py
|
|
7
|
+
vardict.egg-info/PKG-INFO
|
|
8
|
+
vardict.egg-info/SOURCES.txt
|
|
9
|
+
vardict.egg-info/dependency_links.txt
|
|
10
|
+
vardict.egg-info/requires.txt
|
|
11
|
+
vardict.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
executing>=2.2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
vardict
|