dataconf 2.5.0__tar.gz → 3.1.0__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.
- {dataconf-2.5.0 → dataconf-3.1.0}/PKG-INFO +26 -11
- {dataconf-2.5.0 → dataconf-3.1.0}/README.md +23 -8
- {dataconf-2.5.0 → dataconf-3.1.0}/dataconf/utils.py +33 -9
- {dataconf-2.5.0 → dataconf-3.1.0}/dataconf/version.py +1 -1
- {dataconf-2.5.0 → dataconf-3.1.0}/pyproject.toml +5 -5
- dataconf-3.1.0/setup.py +38 -0
- dataconf-2.5.0/setup.py +0 -38
- {dataconf-2.5.0 → dataconf-3.1.0}/LICENSE +0 -0
- {dataconf-2.5.0 → dataconf-3.1.0}/dataconf/__init__.py +0 -0
- {dataconf-2.5.0 → dataconf-3.1.0}/dataconf/cli.py +0 -0
- {dataconf-2.5.0 → dataconf-3.1.0}/dataconf/exceptions.py +0 -0
- {dataconf-2.5.0 → dataconf-3.1.0}/dataconf/main.py +0 -0
- {dataconf-2.5.0 → dataconf-3.1.0}/dataconf/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dataconf
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.
|
|
5
5
|
Home-page: https://github.com/zifeo/dataconf
|
|
6
6
|
License: MPL-2.0
|
|
@@ -20,8 +20,8 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
20
20
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
21
|
Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
|
|
22
22
|
Requires-Dist: isodate (>=0.6.1,<0.7.0)
|
|
23
|
-
Requires-Dist: pyhocon (
|
|
24
|
-
Requires-Dist: pyparsing (
|
|
23
|
+
Requires-Dist: pyhocon (>=0.3.60,<0.4.0)
|
|
24
|
+
Requires-Dist: pyparsing (>=3.1.2,<4.0.0)
|
|
25
25
|
Requires-Dist: python-dateutil (>=2.8.2,<3.0.0)
|
|
26
26
|
Project-URL: Repository, https://github.com/zifeo/dataconf
|
|
27
27
|
Description-Content-Type: text/markdown
|
|
@@ -57,9 +57,9 @@ pre-commit install
|
|
|
57
57
|
```python
|
|
58
58
|
import os
|
|
59
59
|
from dataclasses import dataclass, field
|
|
60
|
-
from typing import List, Dict, Text, Union
|
|
60
|
+
from typing import List, Dict, Text, Union, Tuple
|
|
61
61
|
from dateutil.relativedelta import relativedelta
|
|
62
|
-
from datetime import datetime
|
|
62
|
+
from datetime import datetime, timedelta
|
|
63
63
|
import dataconf
|
|
64
64
|
|
|
65
65
|
conf = """
|
|
@@ -69,6 +69,15 @@ dash-to-underscore = true
|
|
|
69
69
|
float_num = 2.2
|
|
70
70
|
iso_datetime = "2000-01-01T20:00:00"
|
|
71
71
|
iso_duration = "P123DT4H5M6S"
|
|
72
|
+
variable_length_tuple_data = [
|
|
73
|
+
1
|
|
74
|
+
2
|
|
75
|
+
3
|
|
76
|
+
]
|
|
77
|
+
tuple_data = [
|
|
78
|
+
a
|
|
79
|
+
P1D
|
|
80
|
+
]
|
|
72
81
|
# this is a comment
|
|
73
82
|
list_data = [
|
|
74
83
|
a
|
|
@@ -117,6 +126,8 @@ class Config:
|
|
|
117
126
|
float_num: float
|
|
118
127
|
iso_datetime: datetime
|
|
119
128
|
iso_duration: timedelta
|
|
129
|
+
variable_length_tuple_data: Tuple[int, ...]
|
|
130
|
+
tuple_data: Tuple[Text, timedelta]
|
|
120
131
|
list_data: List[Text]
|
|
121
132
|
nested: Nested
|
|
122
133
|
nested_list: List[Nested]
|
|
@@ -129,17 +140,21 @@ class Config:
|
|
|
129
140
|
|
|
130
141
|
print(dataconf.string(conf, Config))
|
|
131
142
|
# Config(
|
|
132
|
-
# str_name='/users/root',
|
|
143
|
+
# str_name='/users/root/',
|
|
133
144
|
# dash_to_underscore=True,
|
|
134
145
|
# float_num=2.2,
|
|
146
|
+
# iso_datetime=datetime.datetime(2000, 1, 1, 20, 0),
|
|
147
|
+
# iso_duration=datetime.timedelta(days=123, seconds=14706),
|
|
148
|
+
# variable_length_tuple_data=(1,2,3),
|
|
149
|
+
# tuple_data=('a', datetime.timedelta(days=1)),
|
|
135
150
|
# list_data=['a', 'b'],
|
|
136
|
-
# nested=Nested(a='test'),
|
|
151
|
+
# nested=Nested(a='test', b=1),
|
|
137
152
|
# nested_list=[Nested(a='test1', b=2.5)],
|
|
138
|
-
# duration=relativedelta(seconds=+2),
|
|
139
|
-
# union=1,
|
|
140
|
-
# people=Person(name='Thailand'),
|
|
153
|
+
# duration=relativedelta(seconds=+2),
|
|
154
|
+
# union=1,
|
|
155
|
+
# people=Person(name='Thailand'),
|
|
141
156
|
# zone=Zone(area_code=42),
|
|
142
|
-
# default='hello',
|
|
157
|
+
# default='hello',
|
|
143
158
|
# default_factory={}
|
|
144
159
|
# )
|
|
145
160
|
|
|
@@ -29,9 +29,9 @@ pre-commit install
|
|
|
29
29
|
```python
|
|
30
30
|
import os
|
|
31
31
|
from dataclasses import dataclass, field
|
|
32
|
-
from typing import List, Dict, Text, Union
|
|
32
|
+
from typing import List, Dict, Text, Union, Tuple
|
|
33
33
|
from dateutil.relativedelta import relativedelta
|
|
34
|
-
from datetime import datetime
|
|
34
|
+
from datetime import datetime, timedelta
|
|
35
35
|
import dataconf
|
|
36
36
|
|
|
37
37
|
conf = """
|
|
@@ -41,6 +41,15 @@ dash-to-underscore = true
|
|
|
41
41
|
float_num = 2.2
|
|
42
42
|
iso_datetime = "2000-01-01T20:00:00"
|
|
43
43
|
iso_duration = "P123DT4H5M6S"
|
|
44
|
+
variable_length_tuple_data = [
|
|
45
|
+
1
|
|
46
|
+
2
|
|
47
|
+
3
|
|
48
|
+
]
|
|
49
|
+
tuple_data = [
|
|
50
|
+
a
|
|
51
|
+
P1D
|
|
52
|
+
]
|
|
44
53
|
# this is a comment
|
|
45
54
|
list_data = [
|
|
46
55
|
a
|
|
@@ -89,6 +98,8 @@ class Config:
|
|
|
89
98
|
float_num: float
|
|
90
99
|
iso_datetime: datetime
|
|
91
100
|
iso_duration: timedelta
|
|
101
|
+
variable_length_tuple_data: Tuple[int, ...]
|
|
102
|
+
tuple_data: Tuple[Text, timedelta]
|
|
92
103
|
list_data: List[Text]
|
|
93
104
|
nested: Nested
|
|
94
105
|
nested_list: List[Nested]
|
|
@@ -101,17 +112,21 @@ class Config:
|
|
|
101
112
|
|
|
102
113
|
print(dataconf.string(conf, Config))
|
|
103
114
|
# Config(
|
|
104
|
-
# str_name='/users/root',
|
|
115
|
+
# str_name='/users/root/',
|
|
105
116
|
# dash_to_underscore=True,
|
|
106
117
|
# float_num=2.2,
|
|
118
|
+
# iso_datetime=datetime.datetime(2000, 1, 1, 20, 0),
|
|
119
|
+
# iso_duration=datetime.timedelta(days=123, seconds=14706),
|
|
120
|
+
# variable_length_tuple_data=(1,2,3),
|
|
121
|
+
# tuple_data=('a', datetime.timedelta(days=1)),
|
|
107
122
|
# list_data=['a', 'b'],
|
|
108
|
-
# nested=Nested(a='test'),
|
|
123
|
+
# nested=Nested(a='test', b=1),
|
|
109
124
|
# nested_list=[Nested(a='test1', b=2.5)],
|
|
110
|
-
# duration=relativedelta(seconds=+2),
|
|
111
|
-
# union=1,
|
|
112
|
-
# people=Person(name='Thailand'),
|
|
125
|
+
# duration=relativedelta(seconds=+2),
|
|
126
|
+
# union=1,
|
|
127
|
+
# people=Person(name='Thailand'),
|
|
113
128
|
# zone=Zone(area_code=42),
|
|
114
|
-
# default='hello',
|
|
129
|
+
# default='hello',
|
|
115
130
|
# default_factory={}
|
|
116
131
|
# )
|
|
117
132
|
|
|
@@ -113,16 +113,41 @@ def __parse(value: any, clazz: Type, path: str, strict: bool, ignore_unexpected:
|
|
|
113
113
|
args = get_args(clazz)
|
|
114
114
|
|
|
115
115
|
if origin is list:
|
|
116
|
+
if value is None:
|
|
117
|
+
raise MalformedConfigException(f"expected list at {path} but received None")
|
|
118
|
+
|
|
116
119
|
if len(args) != 1:
|
|
117
120
|
raise MissingTypeException("expected list with type information: List[?]")
|
|
118
121
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
parse_candidate = args[0]
|
|
123
|
+
return [
|
|
124
|
+
__parse(v, parse_candidate, f"{path}[]", strict, ignore_unexpected)
|
|
125
|
+
for v in value
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
if origin is tuple:
|
|
129
|
+
if value is None:
|
|
130
|
+
raise MalformedConfigException(
|
|
131
|
+
f"expected tuple at {path} but received None"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
if len(args) < 1:
|
|
135
|
+
raise MissingTypeException("expected tuple with type information: Tuple[?]")
|
|
136
|
+
|
|
137
|
+
has_ellipsis = args[-1] == Ellipsis
|
|
138
|
+
if has_ellipsis and len(args) != 2:
|
|
139
|
+
raise MissingTypeException(
|
|
140
|
+
"expected one type since ellipsis is used: Tuple[?, ...]"
|
|
141
|
+
)
|
|
142
|
+
_args = args if not has_ellipsis else [args[0]] * len(value)
|
|
143
|
+
if len(value) > 0 and len(value) != len(_args):
|
|
144
|
+
raise MalformedConfigException(
|
|
145
|
+
"number of provided values does not match expected number of values for tuple."
|
|
146
|
+
)
|
|
147
|
+
return tuple(
|
|
148
|
+
__parse(v, arg, f"{path}[]", strict, ignore_unexpected)
|
|
149
|
+
for v, arg in zip(value, _args)
|
|
150
|
+
)
|
|
126
151
|
|
|
127
152
|
if origin is dict:
|
|
128
153
|
if len(args) != 2:
|
|
@@ -200,8 +225,7 @@ def __parse(value: any, clazz: Type, path: str, strict: bool, ignore_unexpected:
|
|
|
200
225
|
elif issubclass(clazz, str):
|
|
201
226
|
return clazz(value)
|
|
202
227
|
elif isinstance(value, str):
|
|
203
|
-
return clazz.
|
|
204
|
-
|
|
228
|
+
return clazz.__getitem__(value)
|
|
205
229
|
raise TypeConfigException(f"expected str or int at {path}, got {type(value)}")
|
|
206
230
|
|
|
207
231
|
if isclass(clazz) and issubclass(clazz, Path):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "dataconf"
|
|
3
|
-
version = "
|
|
3
|
+
version = "3.1.0"
|
|
4
4
|
description = "Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support."
|
|
5
5
|
authors = []
|
|
6
6
|
license = "MPL-2.0"
|
|
@@ -33,22 +33,22 @@ dataconf = 'dataconf.cli:run'
|
|
|
33
33
|
|
|
34
34
|
[tool.poetry.dependencies]
|
|
35
35
|
python = "^3.8"
|
|
36
|
-
pyhocon = "0.3.59"
|
|
37
36
|
python-dateutil = "^2.8.2"
|
|
38
37
|
PyYAML = "^6.0.1"
|
|
39
|
-
pyparsing = "2.4.7"
|
|
40
38
|
isodate = "^0.6.1"
|
|
39
|
+
pyhocon = "^0.3.60"
|
|
40
|
+
pyparsing = "^3.1.2"
|
|
41
41
|
|
|
42
42
|
[tool.poetry.group.dev.dependencies]
|
|
43
43
|
pytest = ">=7.4.2,<9.0.0"
|
|
44
44
|
pre-commit = ">=2.21,<4.0"
|
|
45
45
|
commitizen = ">=2.42.1,<4.0.0"
|
|
46
46
|
pytest-httpserver = "^1.0.8"
|
|
47
|
-
ruff = "
|
|
47
|
+
ruff = ">=0.1.9,<0.4.0"
|
|
48
48
|
|
|
49
49
|
[tool.commitizen]
|
|
50
50
|
name = "cz_conventional_commits"
|
|
51
|
-
version = "
|
|
51
|
+
version = "3.1.0"
|
|
52
52
|
tag_format = "v$major.$minor.$patch$prerelease"
|
|
53
53
|
version_files = [
|
|
54
54
|
"pyproject.toml:version",
|
dataconf-3.1.0/setup.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
packages = \
|
|
5
|
+
['dataconf']
|
|
6
|
+
|
|
7
|
+
package_data = \
|
|
8
|
+
{'': ['*']}
|
|
9
|
+
|
|
10
|
+
install_requires = \
|
|
11
|
+
['PyYAML>=6.0.1,<7.0.0',
|
|
12
|
+
'isodate>=0.6.1,<0.7.0',
|
|
13
|
+
'pyhocon>=0.3.60,<0.4.0',
|
|
14
|
+
'pyparsing>=3.1.2,<4.0.0',
|
|
15
|
+
'python-dateutil>=2.8.2,<3.0.0']
|
|
16
|
+
|
|
17
|
+
entry_points = \
|
|
18
|
+
{'console_scripts': ['dataconf = dataconf.cli:run']}
|
|
19
|
+
|
|
20
|
+
setup_kwargs = {
|
|
21
|
+
'name': 'dataconf',
|
|
22
|
+
'version': '3.1.0',
|
|
23
|
+
'description': 'Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.',
|
|
24
|
+
'long_description': '# Dataconf\n\n[](https://github.com/zifeo/dataconf/actions)\n[](https://badge.fury.io/py/dataconf)\n\nSimple dataclasses configuration management for Python with\nhocon/json/yaml/properties/env-vars/dict/cli support.\n\n## Getting started\n\nRequires at least Python 3.8.\n\n```bash\n# pypi\npip install dataconf\npoetry add dataconf\n\n# remote master\npip install --upgrade git+https://github.com/zifeo/dataconf.git\npoetry add git+https://github.com/zifeo/dataconf.git\n\n# local repo/dev\npoetry install\npre-commit install\n```\n\n## Usage\n\n```python\nimport os\nfrom dataclasses import dataclass, field\nfrom typing import List, Dict, Text, Union, Tuple\nfrom dateutil.relativedelta import relativedelta\nfrom datetime import datetime, timedelta\nimport dataconf\n\nconf = """\nstr_name = test\nstr_name = ${?HOME}\ndash-to-underscore = true\nfloat_num = 2.2\niso_datetime = "2000-01-01T20:00:00"\niso_duration = "P123DT4H5M6S"\nvariable_length_tuple_data = [\n 1\n 2\n 3\n]\ntuple_data = [\n a\n P1D\n]\n# this is a comment\nlist_data = [\n a\n b\n]\nnested {\n a = test\n b : 1\n}\nnested_list = [\n {\n a = test1\n b : 2.5\n }\n]\nduration = 2s\nunion = 1\npeople {\n name = Thailand\n}\nzone {\n area_code = 42\n}\n"""\n\nclass AbstractBaseClass:\n pass\n \n@dataclass\nclass Person(AbstractBaseClass):\n name: Text\n \n@dataclass\nclass Zone(AbstractBaseClass):\n area_code: int\n\n@dataclass\nclass Nested:\n a: Text\n b: float\n\n@dataclass\nclass Config:\n str_name: Text\n dash_to_underscore: bool\n float_num: float\n iso_datetime: datetime\n iso_duration: timedelta\n variable_length_tuple_data: Tuple[int, ...]\n tuple_data: Tuple[Text, timedelta]\n list_data: List[Text]\n nested: Nested\n nested_list: List[Nested]\n duration: relativedelta\n union: Union[Text, int]\n people: AbstractBaseClass\n zone: AbstractBaseClass\n default: Text = \'hello\'\n default_factory: Dict[Text, Text] = field(default_factory=dict)\n\nprint(dataconf.string(conf, Config))\n# Config(\n# str_name=\'/users/root/\',\n# dash_to_underscore=True,\n# float_num=2.2,\n# iso_datetime=datetime.datetime(2000, 1, 1, 20, 0),\n# iso_duration=datetime.timedelta(days=123, seconds=14706),\n# variable_length_tuple_data=(1,2,3),\n# tuple_data=(\'a\', datetime.timedelta(days=1)),\n# list_data=[\'a\', \'b\'],\n# nested=Nested(a=\'test\', b=1),\n# nested_list=[Nested(a=\'test1\', b=2.5)],\n# duration=relativedelta(seconds=+2),\n# union=1,\n# people=Person(name=\'Thailand\'),\n# zone=Zone(area_code=42),\n# default=\'hello\',\n# default_factory={}\n# )\n\n@dataclass\nclass Example:\n hello: str\n world: str\n foo: List[str]\n\nos.environ[\'DC_WORLD\'] = \'monde\'\n\nprint(\n dataconf\n .multi\n .url(\'https://raw.githubusercontent.com/zifeo/dataconf/main/confs/simple.hocon\')\n .env(\'DC\')\n .on(Example)\n)\n# Example(hello=\'bonjour\',world=\'monde\')\n```\n\n## API\n\n```python\nimport dataconf\n\nconf = dataconf.string(\'{ name: Test }\', Config)\nconf = dataconf.string(\'name:\\n\\tvalue: Test\', Config, loader=dataconf.YAML) # dataconf.HOCON by default\nconf = dataconf.env(\'PREFIX_\', Config)\nconf = dataconf.dict({\'name\': \'Test\'}, Config)\nconf = dataconf.url(\'https://raw.githubusercontent.com/zifeo/dataconf/master/confs/test.hocon\', Config) # hocon, json, yaml, properties\nconf = dataconf.file(\'confs/test.hocon\', Config) # hocon, json, yaml, properties\nconf = dataconf.cli(sys.argv, Config)\n\n# Aggregation\nconf = dataconf.multi.string(...).env(...).url(...).file(...).dict(...).cli(...).on(Config)\n\n# Same api as Python json/yaml packages (e.g. `load`, `loads`, `dump`, `dumps`)\nconf = dataconf.load(\'confs/test.hocon\', Config) # hocon, json, yaml, properties\nconf = dataconf.load(\'confs/test.yaml\', Config, loader=dataconf.YAML) # dataconf.HOCON by default\ndataconf.dump(\'confs/test.hocon\', conf, out=\'hocon\')\ndataconf.dump(\'confs/test.json\', conf, out=\'json\')\ndataconf.dump(\'confs/test.yaml\', conf, out=\'yaml\')\ndataconf.dump(\'confs/test.properties\', conf, out=\'properties\')\n```\n\nFor full HOCON capabilities see\n[here](https://github.com/chimpler/pyhocon/#example-of-hocon-file).\n\n## Parse env vars\n\n```bash\nPREFIX_VAR=a\nPREFIX_VAR_NAME=b\nPREFIX_TEST__NAME=c\nPREFIX_LS_0=d\nPREFIX_LS_1=e\nPREFIX_LSLS_0_0=f\nPREFIX_LSOB_0__NAME=g\nPREFIX_NESTED_="{ name: Test }"\nPREFIX_SUB_="{ value: ${PREFIX_VAR} }"\n```\n\nis equivalent to\n\n```\n{\n var = a\n var_name = b\n test {\n name = c\n }\n ls = [\n d\n e\n ]\n lsls = [\n [\n f\n ]\n ]\n lsob = [\n {\n name = g\n }\n ]\n nested {\n # parse nested config by suffixing env var with `_`\n name: Test\n }\n sub {\n # will have value "a" at parsing, useful for aliases\n value = ${PREFIX_VAR}\n }\n}\n```\n\nNote that when using `.env` source, the strict mode is disabled and value might\nbe casted.\n\n## Parse CLI arguments\n\nSame as env vars parse (dashes are converted to underscore, e.g. `TEST_A` →\n`--test-a`).\n\n## CLI usage\n\nCan be used for validation or converting between supported file formats (`-o`).\n\n```shell\ndataconf -c confs/test.hocon -m tests.configs -d TestConf -o hocon\n# dataconf.exceptions.TypeConfigException: expected type <class \'datetime.timedelta\'> at .duration, got <class \'int\'>\n```\n',
|
|
25
|
+
'author': 'None',
|
|
26
|
+
'author_email': 'None',
|
|
27
|
+
'maintainer': 'None',
|
|
28
|
+
'maintainer_email': 'None',
|
|
29
|
+
'url': 'https://github.com/zifeo/dataconf',
|
|
30
|
+
'packages': packages,
|
|
31
|
+
'package_data': package_data,
|
|
32
|
+
'install_requires': install_requires,
|
|
33
|
+
'entry_points': entry_points,
|
|
34
|
+
'python_requires': '>=3.8,<4.0',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
setup(**setup_kwargs)
|
dataconf-2.5.0/setup.py
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
packages = \
|
|
5
|
-
['dataconf']
|
|
6
|
-
|
|
7
|
-
package_data = \
|
|
8
|
-
{'': ['*']}
|
|
9
|
-
|
|
10
|
-
install_requires = \
|
|
11
|
-
['PyYAML>=6.0.1,<7.0.0',
|
|
12
|
-
'isodate>=0.6.1,<0.7.0',
|
|
13
|
-
'pyhocon==0.3.59',
|
|
14
|
-
'pyparsing==2.4.7',
|
|
15
|
-
'python-dateutil>=2.8.2,<3.0.0']
|
|
16
|
-
|
|
17
|
-
entry_points = \
|
|
18
|
-
{'console_scripts': ['dataconf = dataconf.cli:run']}
|
|
19
|
-
|
|
20
|
-
setup_kwargs = {
|
|
21
|
-
'name': 'dataconf',
|
|
22
|
-
'version': '2.5.0',
|
|
23
|
-
'description': 'Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.',
|
|
24
|
-
'long_description': '# Dataconf\n\n[](https://github.com/zifeo/dataconf/actions)\n[](https://badge.fury.io/py/dataconf)\n\nSimple dataclasses configuration management for Python with\nhocon/json/yaml/properties/env-vars/dict/cli support.\n\n## Getting started\n\nRequires at least Python 3.8.\n\n```bash\n# pypi\npip install dataconf\npoetry add dataconf\n\n# remote master\npip install --upgrade git+https://github.com/zifeo/dataconf.git\npoetry add git+https://github.com/zifeo/dataconf.git\n\n# local repo/dev\npoetry install\npre-commit install\n```\n\n## Usage\n\n```python\nimport os\nfrom dataclasses import dataclass, field\nfrom typing import List, Dict, Text, Union\nfrom dateutil.relativedelta import relativedelta\nfrom datetime import datetime\nimport dataconf\n\nconf = """\nstr_name = test\nstr_name = ${?HOME}\ndash-to-underscore = true\nfloat_num = 2.2\niso_datetime = "2000-01-01T20:00:00"\niso_duration = "P123DT4H5M6S"\n# this is a comment\nlist_data = [\n a\n b\n]\nnested {\n a = test\n b : 1\n}\nnested_list = [\n {\n a = test1\n b : 2.5\n }\n]\nduration = 2s\nunion = 1\npeople {\n name = Thailand\n}\nzone {\n area_code = 42\n}\n"""\n\nclass AbstractBaseClass:\n pass\n \n@dataclass\nclass Person(AbstractBaseClass):\n name: Text\n \n@dataclass\nclass Zone(AbstractBaseClass):\n area_code: int\n\n@dataclass\nclass Nested:\n a: Text\n b: float\n\n@dataclass\nclass Config:\n str_name: Text\n dash_to_underscore: bool\n float_num: float\n iso_datetime: datetime\n iso_duration: timedelta\n list_data: List[Text]\n nested: Nested\n nested_list: List[Nested]\n duration: relativedelta\n union: Union[Text, int]\n people: AbstractBaseClass\n zone: AbstractBaseClass\n default: Text = \'hello\'\n default_factory: Dict[Text, Text] = field(default_factory=dict)\n\nprint(dataconf.string(conf, Config))\n# Config(\n# str_name=\'/users/root\',\n# dash_to_underscore=True,\n# float_num=2.2,\n# list_data=[\'a\', \'b\'],\n# nested=Nested(a=\'test\'),\n# nested_list=[Nested(a=\'test1\', b=2.5)],\n# duration=relativedelta(seconds=+2), \n# union=1, \n# people=Person(name=\'Thailand\'), \n# zone=Zone(area_code=42),\n# default=\'hello\', \n# default_factory={}\n# )\n\n@dataclass\nclass Example:\n hello: str\n world: str\n foo: List[str]\n\nos.environ[\'DC_WORLD\'] = \'monde\'\n\nprint(\n dataconf\n .multi\n .url(\'https://raw.githubusercontent.com/zifeo/dataconf/main/confs/simple.hocon\')\n .env(\'DC\')\n .on(Example)\n)\n# Example(hello=\'bonjour\',world=\'monde\')\n```\n\n## API\n\n```python\nimport dataconf\n\nconf = dataconf.string(\'{ name: Test }\', Config)\nconf = dataconf.string(\'name:\\n\\tvalue: Test\', Config, loader=dataconf.YAML) # dataconf.HOCON by default\nconf = dataconf.env(\'PREFIX_\', Config)\nconf = dataconf.dict({\'name\': \'Test\'}, Config)\nconf = dataconf.url(\'https://raw.githubusercontent.com/zifeo/dataconf/master/confs/test.hocon\', Config) # hocon, json, yaml, properties\nconf = dataconf.file(\'confs/test.hocon\', Config) # hocon, json, yaml, properties\nconf = dataconf.cli(sys.argv, Config)\n\n# Aggregation\nconf = dataconf.multi.string(...).env(...).url(...).file(...).dict(...).cli(...).on(Config)\n\n# Same api as Python json/yaml packages (e.g. `load`, `loads`, `dump`, `dumps`)\nconf = dataconf.load(\'confs/test.hocon\', Config) # hocon, json, yaml, properties\nconf = dataconf.load(\'confs/test.yaml\', Config, loader=dataconf.YAML) # dataconf.HOCON by default\ndataconf.dump(\'confs/test.hocon\', conf, out=\'hocon\')\ndataconf.dump(\'confs/test.json\', conf, out=\'json\')\ndataconf.dump(\'confs/test.yaml\', conf, out=\'yaml\')\ndataconf.dump(\'confs/test.properties\', conf, out=\'properties\')\n```\n\nFor full HOCON capabilities see\n[here](https://github.com/chimpler/pyhocon/#example-of-hocon-file).\n\n## Parse env vars\n\n```bash\nPREFIX_VAR=a\nPREFIX_VAR_NAME=b\nPREFIX_TEST__NAME=c\nPREFIX_LS_0=d\nPREFIX_LS_1=e\nPREFIX_LSLS_0_0=f\nPREFIX_LSOB_0__NAME=g\nPREFIX_NESTED_="{ name: Test }"\nPREFIX_SUB_="{ value: ${PREFIX_VAR} }"\n```\n\nis equivalent to\n\n```\n{\n var = a\n var_name = b\n test {\n name = c\n }\n ls = [\n d\n e\n ]\n lsls = [\n [\n f\n ]\n ]\n lsob = [\n {\n name = g\n }\n ]\n nested {\n # parse nested config by suffixing env var with `_`\n name: Test\n }\n sub {\n # will have value "a" at parsing, useful for aliases\n value = ${PREFIX_VAR}\n }\n}\n```\n\nNote that when using `.env` source, the strict mode is disabled and value might\nbe casted.\n\n## Parse CLI arguments\n\nSame as env vars parse (dashes are converted to underscore, e.g. `TEST_A` →\n`--test-a`).\n\n## CLI usage\n\nCan be used for validation or converting between supported file formats (`-o`).\n\n```shell\ndataconf -c confs/test.hocon -m tests.configs -d TestConf -o hocon\n# dataconf.exceptions.TypeConfigException: expected type <class \'datetime.timedelta\'> at .duration, got <class \'int\'>\n```\n',
|
|
25
|
-
'author': 'None',
|
|
26
|
-
'author_email': 'None',
|
|
27
|
-
'maintainer': 'None',
|
|
28
|
-
'maintainer_email': 'None',
|
|
29
|
-
'url': 'https://github.com/zifeo/dataconf',
|
|
30
|
-
'packages': packages,
|
|
31
|
-
'package_data': package_data,
|
|
32
|
-
'install_requires': install_requires,
|
|
33
|
-
'entry_points': entry_points,
|
|
34
|
-
'python_requires': '>=3.8,<4.0',
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
setup(**setup_kwargs)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|