diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-dataconf.spec | 750 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 752 insertions, 0 deletions
@@ -0,0 +1 @@ +/dataconf-2.1.3.tar.gz diff --git a/python-dataconf.spec b/python-dataconf.spec new file mode 100644 index 0000000..de3005a --- /dev/null +++ b/python-dataconf.spec @@ -0,0 +1,750 @@ +%global _empty_manifest_terminate_build 0 +Name: python-dataconf +Version: 2.1.3 +Release: 1 +Summary: Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support. +License: Apache2 +URL: https://github.com/zifeo/dataconf +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/3e/c5/9922fb8deb686f377cd8e4e6d20dd7f42a0f5b755d408f8164e5d1b2ab4c/dataconf-2.1.3.tar.gz +BuildArch: noarch + +Requires: python3-pyhocon +Requires: python3-dateutil +Requires: python3-PyYAML + +%description +# Dataconf + +[](https://github.com/zifeo/dataconf/actions) +[](https://badge.fury.io/py/dataconf) + +Simple dataclasses configuration management for Python with +hocon/json/yaml/properties/env-vars/dict/cli support. + +## Getting started + +Requires at least Python 3.8. + +```bash +# pypi +pip install dataconf +poetry add dataconf + +# remote master +pip install --upgrade git+https://github.com/zifeo/dataconf.git +poetry add git+https://github.com/zifeo/dataconf.git + +# local repo/dev +poetry install +pre-commit install +``` + +## Usage + +```python +import os +from dataclasses import dataclass, field +from typing import List, Dict, Text, Union +from dateutil.relativedelta import relativedelta +from datetime import datetime +import dataconf + +conf = """ +str_name = test +str_name = ${?HOME} +dash-to-underscore = true +float_num = 2.2 +iso_datetime = "2000-01-01T20:00:00" +# this is a comment +list_data = [ + a + b +] +nested { + a = test + b : 1 +} +nested_list = [ + { + a = test1 + b : 2.5 + } +] +duration = 2s +union = 1 +people { + name = Thailand +} +zone { + area_code = 42 +} +""" + +class AbstractBaseClass: + pass + +@dataclass +class Person(AbstractBaseClass): + name: Text + +@dataclass +class Zone(AbstractBaseClass): + area_code: int + +@dataclass +class Nested: + a: Text + b: float + +@dataclass +class Config: + str_name: Text + dash_to_underscore: bool + float_num: float + iso_datetime: datetime + list_data: List[Text] + nested: Nested + nested_list: List[Nested] + duration: relativedelta + union: Union[Text, int] + people: AbstractBaseClass + zone: AbstractBaseClass + default: Text = 'hello' + default_factory: Dict[Text, Text] = field(default_factory=dict) + +print(dataconf.string(conf, Config)) +# Config( +# str_name='/users/root', +# dash_to_underscore=True, +# float_num=2.2, +# list_data=['a', 'b'], +# nested=Nested(a='test'), +# nested_list=[Nested(a='test1', b=2.5)], +# duration=relativedelta(seconds=+2), +# union=1, +# people=Person(name='Thailand'), +# zone=Zone(area_code=42), +# default='hello', +# default_factory={} +# ) + +@dataclass +class Example: + hello: str + world: str + foo: List[str] + +os.environ['DC_WORLD'] = 'monde' + +print( + dataconf + .multi + .url('https://raw.githubusercontent.com/zifeo/dataconf/main/confs/simple.hocon') + .env('DC') + .on(Example) +) +# Example(hello='bonjour',world='monde') +``` + +## API + +```python +import dataconf + +conf = dataconf.string('{ name: Test }', Config) +conf = dataconf.string('name:\n\tvalue: Test', Config, loader=dataconf.YAML) # dataconf.HOCON by default +conf = dataconf.env('PREFIX_', Config) +conf = dataconf.dict({'name': 'Test'}, Config) +conf = dataconf.url('https://raw.githubusercontent.com/zifeo/dataconf/master/confs/test.hocon', Config) # hocon, json, yaml, properties +conf = dataconf.file('confs/test.hocon', Config) # hocon, json, yaml, properties +conf = dataconf.cli(sys.argv, Config) + +# Aggregation +conf = dataconf.multi.string(...).env(...).url(...).file(...).dict(...).cli(...).on(Config) + +# Same api as Python json/yaml packages (e.g. `load`, `loads`, `dump`, `dumps`) +conf = dataconf.load('confs/test.hocon', Config) # hocon, json, yaml, properties +conf = dataconf.load('confs/test.yaml', Config, loader=dataconf.YAML) # dataconf.HOCON by default +dataconf.dump('confs/test.hocon', conf, out='hocon') +dataconf.dump('confs/test.json', conf, out='json') +dataconf.dump('confs/test.yaml', conf, out='yaml') +dataconf.dump('confs/test.properties', conf, out='properties') +``` + +For full HOCON capabilities see +[here](https://github.com/chimpler/pyhocon/#example-of-hocon-file). + +## Parse env vars + +```bash +PREFIX_VAR=a +PREFIX_VAR_NAME=b +PREFIX_TEST__NAME=c +PREFIX_LS_0=d +PREFIX_LS_1=e +PREFIX_LSLS_0_0=f +PREFIX_LSOB_0__NAME=g +PREFIX_NESTED_="{ name: Test }" +PREFIX_SUB_="{ value: ${PREFIX_VAR} }" +``` + +is equivalent to + +``` +{ + var = a + var_name = b + test { + name = c + } + ls = [ + d + e + ] + lsls = [ + [ + f + ] + ] + lsob = [ + { + name = g + } + ] + nested { + # parse nested config by suffixing env var with `_` + name: Test + } + sub { + # will have value "a" at parsing, useful for aliases + value = ${PREFIX_VAR} + } +} +``` + +Note that when using `.env` source, the strict mode is disabled and value might +be casted. + +## Parse CLI arguments + +Same as env vars parse (dashes are converted to underscore, e.g. `TEST_A` → +`--test-a`). + +## CLI usage + +Can be used for validation or converting between supported file formats (`-o`). + +```shell +dataconf -c confs/test.hocon -m tests.configs -d TestConf -o hocon +# dataconf.exceptions.TypeConfigException: expected type <class 'datetime.timedelta'> at .duration, got <class 'int'> +``` + + +%package -n python3-dataconf +Summary: Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support. +Provides: python-dataconf +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-dataconf +# Dataconf + +[](https://github.com/zifeo/dataconf/actions) +[](https://badge.fury.io/py/dataconf) + +Simple dataclasses configuration management for Python with +hocon/json/yaml/properties/env-vars/dict/cli support. + +## Getting started + +Requires at least Python 3.8. + +```bash +# pypi +pip install dataconf +poetry add dataconf + +# remote master +pip install --upgrade git+https://github.com/zifeo/dataconf.git +poetry add git+https://github.com/zifeo/dataconf.git + +# local repo/dev +poetry install +pre-commit install +``` + +## Usage + +```python +import os +from dataclasses import dataclass, field +from typing import List, Dict, Text, Union +from dateutil.relativedelta import relativedelta +from datetime import datetime +import dataconf + +conf = """ +str_name = test +str_name = ${?HOME} +dash-to-underscore = true +float_num = 2.2 +iso_datetime = "2000-01-01T20:00:00" +# this is a comment +list_data = [ + a + b +] +nested { + a = test + b : 1 +} +nested_list = [ + { + a = test1 + b : 2.5 + } +] +duration = 2s +union = 1 +people { + name = Thailand +} +zone { + area_code = 42 +} +""" + +class AbstractBaseClass: + pass + +@dataclass +class Person(AbstractBaseClass): + name: Text + +@dataclass +class Zone(AbstractBaseClass): + area_code: int + +@dataclass +class Nested: + a: Text + b: float + +@dataclass +class Config: + str_name: Text + dash_to_underscore: bool + float_num: float + iso_datetime: datetime + list_data: List[Text] + nested: Nested + nested_list: List[Nested] + duration: relativedelta + union: Union[Text, int] + people: AbstractBaseClass + zone: AbstractBaseClass + default: Text = 'hello' + default_factory: Dict[Text, Text] = field(default_factory=dict) + +print(dataconf.string(conf, Config)) +# Config( +# str_name='/users/root', +# dash_to_underscore=True, +# float_num=2.2, +# list_data=['a', 'b'], +# nested=Nested(a='test'), +# nested_list=[Nested(a='test1', b=2.5)], +# duration=relativedelta(seconds=+2), +# union=1, +# people=Person(name='Thailand'), +# zone=Zone(area_code=42), +# default='hello', +# default_factory={} +# ) + +@dataclass +class Example: + hello: str + world: str + foo: List[str] + +os.environ['DC_WORLD'] = 'monde' + +print( + dataconf + .multi + .url('https://raw.githubusercontent.com/zifeo/dataconf/main/confs/simple.hocon') + .env('DC') + .on(Example) +) +# Example(hello='bonjour',world='monde') +``` + +## API + +```python +import dataconf + +conf = dataconf.string('{ name: Test }', Config) +conf = dataconf.string('name:\n\tvalue: Test', Config, loader=dataconf.YAML) # dataconf.HOCON by default +conf = dataconf.env('PREFIX_', Config) +conf = dataconf.dict({'name': 'Test'}, Config) +conf = dataconf.url('https://raw.githubusercontent.com/zifeo/dataconf/master/confs/test.hocon', Config) # hocon, json, yaml, properties +conf = dataconf.file('confs/test.hocon', Config) # hocon, json, yaml, properties +conf = dataconf.cli(sys.argv, Config) + +# Aggregation +conf = dataconf.multi.string(...).env(...).url(...).file(...).dict(...).cli(...).on(Config) + +# Same api as Python json/yaml packages (e.g. `load`, `loads`, `dump`, `dumps`) +conf = dataconf.load('confs/test.hocon', Config) # hocon, json, yaml, properties +conf = dataconf.load('confs/test.yaml', Config, loader=dataconf.YAML) # dataconf.HOCON by default +dataconf.dump('confs/test.hocon', conf, out='hocon') +dataconf.dump('confs/test.json', conf, out='json') +dataconf.dump('confs/test.yaml', conf, out='yaml') +dataconf.dump('confs/test.properties', conf, out='properties') +``` + +For full HOCON capabilities see +[here](https://github.com/chimpler/pyhocon/#example-of-hocon-file). + +## Parse env vars + +```bash +PREFIX_VAR=a +PREFIX_VAR_NAME=b +PREFIX_TEST__NAME=c +PREFIX_LS_0=d +PREFIX_LS_1=e +PREFIX_LSLS_0_0=f +PREFIX_LSOB_0__NAME=g +PREFIX_NESTED_="{ name: Test }" +PREFIX_SUB_="{ value: ${PREFIX_VAR} }" +``` + +is equivalent to + +``` +{ + var = a + var_name = b + test { + name = c + } + ls = [ + d + e + ] + lsls = [ + [ + f + ] + ] + lsob = [ + { + name = g + } + ] + nested { + # parse nested config by suffixing env var with `_` + name: Test + } + sub { + # will have value "a" at parsing, useful for aliases + value = ${PREFIX_VAR} + } +} +``` + +Note that when using `.env` source, the strict mode is disabled and value might +be casted. + +## Parse CLI arguments + +Same as env vars parse (dashes are converted to underscore, e.g. `TEST_A` → +`--test-a`). + +## CLI usage + +Can be used for validation or converting between supported file formats (`-o`). + +```shell +dataconf -c confs/test.hocon -m tests.configs -d TestConf -o hocon +# dataconf.exceptions.TypeConfigException: expected type <class 'datetime.timedelta'> at .duration, got <class 'int'> +``` + + +%package help +Summary: Development documents and examples for dataconf +Provides: python3-dataconf-doc +%description help +# Dataconf + +[](https://github.com/zifeo/dataconf/actions) +[](https://badge.fury.io/py/dataconf) + +Simple dataclasses configuration management for Python with +hocon/json/yaml/properties/env-vars/dict/cli support. + +## Getting started + +Requires at least Python 3.8. + +```bash +# pypi +pip install dataconf +poetry add dataconf + +# remote master +pip install --upgrade git+https://github.com/zifeo/dataconf.git +poetry add git+https://github.com/zifeo/dataconf.git + +# local repo/dev +poetry install +pre-commit install +``` + +## Usage + +```python +import os +from dataclasses import dataclass, field +from typing import List, Dict, Text, Union +from dateutil.relativedelta import relativedelta +from datetime import datetime +import dataconf + +conf = """ +str_name = test +str_name = ${?HOME} +dash-to-underscore = true +float_num = 2.2 +iso_datetime = "2000-01-01T20:00:00" +# this is a comment +list_data = [ + a + b +] +nested { + a = test + b : 1 +} +nested_list = [ + { + a = test1 + b : 2.5 + } +] +duration = 2s +union = 1 +people { + name = Thailand +} +zone { + area_code = 42 +} +""" + +class AbstractBaseClass: + pass + +@dataclass +class Person(AbstractBaseClass): + name: Text + +@dataclass +class Zone(AbstractBaseClass): + area_code: int + +@dataclass +class Nested: + a: Text + b: float + +@dataclass +class Config: + str_name: Text + dash_to_underscore: bool + float_num: float + iso_datetime: datetime + list_data: List[Text] + nested: Nested + nested_list: List[Nested] + duration: relativedelta + union: Union[Text, int] + people: AbstractBaseClass + zone: AbstractBaseClass + default: Text = 'hello' + default_factory: Dict[Text, Text] = field(default_factory=dict) + +print(dataconf.string(conf, Config)) +# Config( +# str_name='/users/root', +# dash_to_underscore=True, +# float_num=2.2, +# list_data=['a', 'b'], +# nested=Nested(a='test'), +# nested_list=[Nested(a='test1', b=2.5)], +# duration=relativedelta(seconds=+2), +# union=1, +# people=Person(name='Thailand'), +# zone=Zone(area_code=42), +# default='hello', +# default_factory={} +# ) + +@dataclass +class Example: + hello: str + world: str + foo: List[str] + +os.environ['DC_WORLD'] = 'monde' + +print( + dataconf + .multi + .url('https://raw.githubusercontent.com/zifeo/dataconf/main/confs/simple.hocon') + .env('DC') + .on(Example) +) +# Example(hello='bonjour',world='monde') +``` + +## API + +```python +import dataconf + +conf = dataconf.string('{ name: Test }', Config) +conf = dataconf.string('name:\n\tvalue: Test', Config, loader=dataconf.YAML) # dataconf.HOCON by default +conf = dataconf.env('PREFIX_', Config) +conf = dataconf.dict({'name': 'Test'}, Config) +conf = dataconf.url('https://raw.githubusercontent.com/zifeo/dataconf/master/confs/test.hocon', Config) # hocon, json, yaml, properties +conf = dataconf.file('confs/test.hocon', Config) # hocon, json, yaml, properties +conf = dataconf.cli(sys.argv, Config) + +# Aggregation +conf = dataconf.multi.string(...).env(...).url(...).file(...).dict(...).cli(...).on(Config) + +# Same api as Python json/yaml packages (e.g. `load`, `loads`, `dump`, `dumps`) +conf = dataconf.load('confs/test.hocon', Config) # hocon, json, yaml, properties +conf = dataconf.load('confs/test.yaml', Config, loader=dataconf.YAML) # dataconf.HOCON by default +dataconf.dump('confs/test.hocon', conf, out='hocon') +dataconf.dump('confs/test.json', conf, out='json') +dataconf.dump('confs/test.yaml', conf, out='yaml') +dataconf.dump('confs/test.properties', conf, out='properties') +``` + +For full HOCON capabilities see +[here](https://github.com/chimpler/pyhocon/#example-of-hocon-file). + +## Parse env vars + +```bash +PREFIX_VAR=a +PREFIX_VAR_NAME=b +PREFIX_TEST__NAME=c +PREFIX_LS_0=d +PREFIX_LS_1=e +PREFIX_LSLS_0_0=f +PREFIX_LSOB_0__NAME=g +PREFIX_NESTED_="{ name: Test }" +PREFIX_SUB_="{ value: ${PREFIX_VAR} }" +``` + +is equivalent to + +``` +{ + var = a + var_name = b + test { + name = c + } + ls = [ + d + e + ] + lsls = [ + [ + f + ] + ] + lsob = [ + { + name = g + } + ] + nested { + # parse nested config by suffixing env var with `_` + name: Test + } + sub { + # will have value "a" at parsing, useful for aliases + value = ${PREFIX_VAR} + } +} +``` + +Note that when using `.env` source, the strict mode is disabled and value might +be casted. + +## Parse CLI arguments + +Same as env vars parse (dashes are converted to underscore, e.g. `TEST_A` → +`--test-a`). + +## CLI usage + +Can be used for validation or converting between supported file formats (`-o`). + +```shell +dataconf -c confs/test.hocon -m tests.configs -d TestConf -o hocon +# dataconf.exceptions.TypeConfigException: expected type <class 'datetime.timedelta'> at .duration, got <class 'int'> +``` + + +%prep +%autosetup -n dataconf-2.1.3 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-dataconf -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon May 15 2023 Python_Bot <Python_Bot@openeuler.org> - 2.1.3-1 +- Package Spec generated @@ -0,0 +1 @@ +1db85fb0c98bda9e046619190df503a0 dataconf-2.1.3.tar.gz |
