intro configuration support pkg

This commit is contained in:
protolambda
2019-04-07 17:02:20 +10:00
parent 9f32995693
commit 9eb640dd3b
8 changed files with 65 additions and 7 deletions

View File

@@ -0,0 +1,19 @@
# ETH 2.0 config helpers
`preset_loader`: A util to load constants-presets with.
See [Constants-presets documentation](../../configs/constants_presets/README.md).
Usage:
```python
configs_path = 'configs/'
...
import preset_loader
from eth2spec.phase0 import spec
my_presets = preset_loader.load_presets(configs_path, 'main_net')
spec.apply_constants_preset(my_presets)
```
WARNING: this overwrites globals, make sure to prevent accidental collisions with other usage of the same imported specs package.

View File

@@ -0,0 +1,18 @@
from typing import Dict, Any
from ruamel.yaml import (
YAML,
)
from pathlib import Path
from os.path import join
def load_presets(configs_dir, presets_name) -> Dict[str, Any]:
"""
Loads the given preset
:param presets_name: The name of the generator. (lowercase snake_case)
:return: Dictionary, mapping of constant-name -> constant-value
"""
path = Path(join(configs_dir, 'constant_presets', presets_name+'.yaml'))
yaml = YAML(typ='safe')
return yaml.load(path)

View File

@@ -0,0 +1 @@
ruamel.yaml==0.15.87

View File

@@ -0,0 +1,9 @@
from distutils.core import setup
setup(
name='config_helpers',
packages=['preset_loader'],
install_requires=[
"ruamel.yaml==0.15.87"
]
)

View File

@@ -2,7 +2,6 @@ from distutils.core import setup
setup(
name='gen_helpers',
version='1.0',
packages=['gen_base'],
install_requires=[
"ruamel.yaml==0.15.87",