mirror of
https://github.com/ethereum/consensus-specs.git
synced 2026-02-02 21:55:22 -05:00
intro configuration support pkg
This commit is contained in:
19
test_libs/config_helpers/README.md
Normal file
19
test_libs/config_helpers/README.md
Normal 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.
|
||||
0
test_libs/config_helpers/preset_loader/__init__.py
Normal file
0
test_libs/config_helpers/preset_loader/__init__.py
Normal file
18
test_libs/config_helpers/preset_loader/loader.py
Normal file
18
test_libs/config_helpers/preset_loader/loader.py
Normal 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)
|
||||
1
test_libs/config_helpers/requirements.txt
Normal file
1
test_libs/config_helpers/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
ruamel.yaml==0.15.87
|
||||
9
test_libs/config_helpers/setup.py
Normal file
9
test_libs/config_helpers/setup.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from distutils.core import setup
|
||||
|
||||
setup(
|
||||
name='config_helpers',
|
||||
packages=['preset_loader'],
|
||||
install_requires=[
|
||||
"ruamel.yaml==0.15.87"
|
||||
]
|
||||
)
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user