spec packaging; implement review suggestions from hww
This commit is contained in:
parent
675d404c38
commit
7848500ea9
3
Makefile
3
Makefile
|
@ -1,6 +1,5 @@
|
||||||
SPEC_DIR = ./specs
|
SPEC_DIR = ./specs
|
||||||
SSZ_DIR = ./ssz
|
SSZ_DIR = ./ssz
|
||||||
SCRIPT_DIR = ./scripts
|
|
||||||
TEST_LIBS_DIR = ./tests/core
|
TEST_LIBS_DIR = ./tests/core
|
||||||
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
|
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
|
||||||
TEST_VECTOR_DIR = ../eth2.0-spec-tests/tests
|
TEST_VECTOR_DIR = ../eth2.0-spec-tests/tests
|
||||||
|
@ -61,7 +60,7 @@ pyspec:
|
||||||
|
|
||||||
# installs the packages to run pyspec tests
|
# installs the packages to run pyspec tests
|
||||||
install_test:
|
install_test:
|
||||||
python3 -m venv venv; . venv/bin/activate; pip3 install .[testing] .[linting]
|
python3 -m venv venv; . venv/bin/activate; pip3 install .[test] .[lint]
|
||||||
|
|
||||||
test: pyspec
|
test: pyspec
|
||||||
. venv/bin/activate; cd $(PY_SPEC_DIR); \
|
. venv/bin/activate; cd $(PY_SPEC_DIR); \
|
||||||
|
|
42
setup.py
42
setup.py
|
@ -164,21 +164,25 @@ def cache_this(key_fn, value_fn): # type: ignore
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
_get_base_reward = get_base_reward
|
||||||
get_base_reward = cache_this(
|
get_base_reward = cache_this(
|
||||||
lambda state, index: (state.validators.hash_tree_root(), state.slot),
|
lambda state, index: (state.validators.hash_tree_root(), state.slot),
|
||||||
get_base_reward)
|
_get_base_reward)
|
||||||
|
|
||||||
|
_get_committee_count_at_slot = get_committee_count_at_slot
|
||||||
get_committee_count_at_slot = cache_this(
|
get_committee_count_at_slot = cache_this(
|
||||||
lambda state, epoch: (state.validators.hash_tree_root(), epoch),
|
lambda state, epoch: (state.validators.hash_tree_root(), epoch),
|
||||||
get_committee_count_at_slot)
|
_get_committee_count_at_slot)
|
||||||
|
|
||||||
|
_get_active_validator_indices = get_active_validator_indices
|
||||||
get_active_validator_indices = cache_this(
|
get_active_validator_indices = cache_this(
|
||||||
lambda state, epoch: (state.validators.hash_tree_root(), epoch),
|
lambda state, epoch: (state.validators.hash_tree_root(), epoch),
|
||||||
get_active_validator_indices)
|
_get_active_validator_indices)
|
||||||
|
|
||||||
|
_get_beacon_committee = get_beacon_committee
|
||||||
get_beacon_committee = cache_this(
|
get_beacon_committee = cache_this(
|
||||||
lambda state, slot, index: (state.validators.hash_tree_root(), state.randao_mixes.hash_tree_root(), slot, index),
|
lambda state, slot, index: (state.validators.hash_tree_root(), state.randao_mixes.hash_tree_root(), slot, index),
|
||||||
get_beacon_committee)'''
|
_get_beacon_committee)'''
|
||||||
|
|
||||||
|
|
||||||
def objects_to_spec(spec_object: SpecObject, imports: str, version: str) -> str:
|
def objects_to_spec(spec_object: SpecObject, imports: str, version: str) -> str:
|
||||||
|
@ -283,11 +287,6 @@ def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject:
|
||||||
return SpecObject(functions, custom_types, constants, ssz_objects)
|
return SpecObject(functions, custom_types, constants, ssz_objects)
|
||||||
|
|
||||||
|
|
||||||
def dependency_order_spec(objs: SpecObject):
|
|
||||||
functions, custom_types, constants, ssz_objects = objs
|
|
||||||
dependency_order_ssz_objects(ssz_objects, custom_types)
|
|
||||||
|
|
||||||
|
|
||||||
version_imports = {
|
version_imports = {
|
||||||
'phase0': PHASE0_IMPORTS,
|
'phase0': PHASE0_IMPORTS,
|
||||||
'phase1': PHASE1_IMPORTS,
|
'phase1': PHASE1_IMPORTS,
|
||||||
|
@ -295,13 +294,13 @@ version_imports = {
|
||||||
|
|
||||||
|
|
||||||
def build_spec(version: str, source_files: List[str]) -> str:
|
def build_spec(version: str, source_files: List[str]) -> str:
|
||||||
all_spescs = [get_spec(spec) for spec in source_files]
|
all_specs = [get_spec(spec) for spec in source_files]
|
||||||
|
|
||||||
spec_object = all_spescs[0]
|
spec_object = all_specs[0]
|
||||||
for value in all_spescs[1:]:
|
for value in all_specs[1:]:
|
||||||
spec_object = combine_spec_objects(spec_object, value)
|
spec_object = combine_spec_objects(spec_object, value)
|
||||||
|
|
||||||
dependency_order_spec(spec_object)
|
dependency_order_ssz_objects(spec_object.ssz_objects, spec_object.custom_types)
|
||||||
|
|
||||||
return objects_to_spec(spec_object, version_imports[version], version)
|
return objects_to_spec(spec_object, version_imports[version], version)
|
||||||
|
|
||||||
|
@ -333,6 +332,8 @@ class PySpecCommand(Command):
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
"""Post-process options."""
|
"""Post-process options."""
|
||||||
if len(self.md_doc_paths) == 0:
|
if len(self.md_doc_paths) == 0:
|
||||||
|
print("no paths were specified, using default markdown file paths for pyspec"
|
||||||
|
" build (spec version: %s)" % self.spec_version)
|
||||||
if self.spec_version == "phase0":
|
if self.spec_version == "phase0":
|
||||||
self.md_doc_paths = """
|
self.md_doc_paths = """
|
||||||
specs/phase0/beacon-chain.md
|
specs/phase0/beacon-chain.md
|
||||||
|
@ -351,7 +352,6 @@ class PySpecCommand(Command):
|
||||||
"""
|
"""
|
||||||
else:
|
else:
|
||||||
raise Exception('no markdown files specified, and spec version "%s" is unknown', self.spec_version)
|
raise Exception('no markdown files specified, and spec version "%s" is unknown', self.spec_version)
|
||||||
print("no paths were specified, using default markdown file paths for pyspec build (spec version: %s)" % self.spec_version)
|
|
||||||
|
|
||||||
self.parsed_md_doc_paths = self.md_doc_paths.split()
|
self.parsed_md_doc_paths = self.md_doc_paths.split()
|
||||||
|
|
||||||
|
@ -388,8 +388,8 @@ class BuildPyCommand(build_py):
|
||||||
self.run_command('pyspec')
|
self.run_command('pyspec')
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.run_pyspec_cmd(spec_version="phase0")
|
for spec_version in version_imports:
|
||||||
self.run_pyspec_cmd(spec_version="phase1")
|
self.run_pyspec_cmd(spec_version=spec_version)
|
||||||
|
|
||||||
super(BuildPyCommand, self).run()
|
super(BuildPyCommand, self).run()
|
||||||
|
|
||||||
|
@ -416,9 +416,8 @@ class PyspecDevCommand(Command):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print("running build_py command")
|
print("running build_py command")
|
||||||
self.run_pyspec_cmd(spec_version="phase0", package_inplace=False)
|
for spec_version in version_imports:
|
||||||
self.run_pyspec_cmd(spec_version="phase1", package_inplace=False)
|
self.run_pyspec_cmd(spec_version=spec_version)
|
||||||
|
|
||||||
|
|
||||||
commands = {
|
commands = {
|
||||||
'pyspec': PySpecCommand,
|
'pyspec': PySpecCommand,
|
||||||
|
@ -448,10 +447,9 @@ setup(
|
||||||
py_modules=["eth2spec"],
|
py_modules=["eth2spec"],
|
||||||
cmdclass=commands,
|
cmdclass=commands,
|
||||||
python_requires=">=3.8, <4",
|
python_requires=">=3.8, <4",
|
||||||
tests_require=[], # avoid old style tests require. Enable explicit (re-)installs, e.g. `pip install .[testing]`
|
|
||||||
extras_require={
|
extras_require={
|
||||||
"testing": ["pytest>=4.4", "pytest-cov", "pytest-xdist"],
|
"test": ["pytest>=4.4", "pytest-cov", "pytest-xdist"],
|
||||||
"linting": ["flake8==3.7.7", "mypy==0.750"],
|
"lint": ["flake8==3.7.7", "mypy==0.750"],
|
||||||
},
|
},
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"eth-utils>=1.3.0,<2",
|
"eth-utils>=1.3.0,<2",
|
||||||
|
|
|
@ -9,7 +9,7 @@ With this executable spec,
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
Building the pyspec is simply: `python setup.py build`
|
To build the pyspec: `python setup.py build`
|
||||||
(or `pip install .`, but beware that ignored files will still be copied over to a temporary dir, due to pip issue 2195).
|
(or `pip install .`, but beware that ignored files will still be copied over to a temporary dir, due to pip issue 2195).
|
||||||
This outputs the build files to the `./build/lib/eth2spec/...` dir, and can't be used for local test running. Instead, use the dev-install as described below.
|
This outputs the build files to the `./build/lib/eth2spec/...` dir, and can't be used for local test running. Instead, use the dev-install as described below.
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
from importlib import reload
|
||||||
from eth2spec.test.sanity import test_blocks, test_slots
|
|
||||||
|
|
||||||
from gen_base import gen_runner, gen_typing
|
from gen_base import gen_runner, gen_typing
|
||||||
from gen_from_tests.gen import generate_from_tests
|
from gen_from_tests.gen import generate_from_tests
|
||||||
|
|
||||||
from importlib import reload
|
from eth2spec.test.sanity import test_blocks, test_slots
|
||||||
from eth2spec.config import config_util
|
from eth2spec.config import config_util
|
||||||
|
|
||||||
from eth2spec.phase0 import spec as spec_phase0
|
from eth2spec.phase0 import spec as spec_phase0
|
||||||
from eth2spec.phase1 import spec as spec_phase1
|
from eth2spec.phase1 import spec as spec_phase1
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
from eth2spec.phase0 import spec as spec
|
|
||||||
from eth_utils import to_tuple
|
from eth_utils import to_tuple
|
||||||
from gen_base import gen_runner, gen_typing
|
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
from importlib import reload
|
from importlib import reload
|
||||||
|
|
||||||
|
from gen_base import gen_runner, gen_typing
|
||||||
|
|
||||||
from eth2spec.config import config_util
|
from eth2spec.config import config_util
|
||||||
|
from eth2spec.phase0 import spec as spec
|
||||||
|
|
||||||
|
|
||||||
def shuffling_case_fn(seed, count):
|
def shuffling_case_fn(seed, count):
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
from random import Random
|
from random import Random
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
from importlib import reload
|
||||||
from inspect import getmembers, isclass
|
from inspect import getmembers, isclass
|
||||||
|
|
||||||
|
from gen_base import gen_runner, gen_typing
|
||||||
|
|
||||||
from eth2spec.debug import random_value, encode
|
from eth2spec.debug import random_value, encode
|
||||||
|
from eth2spec.config import config_util
|
||||||
from eth2spec.phase0 import spec
|
from eth2spec.phase0 import spec
|
||||||
from eth2spec.utils.ssz.ssz_typing import Container
|
from eth2spec.utils.ssz.ssz_typing import Container
|
||||||
from eth2spec.utils.ssz.ssz_impl import (
|
from eth2spec.utils.ssz.ssz_impl import (
|
||||||
hash_tree_root,
|
hash_tree_root,
|
||||||
serialize,
|
serialize,
|
||||||
)
|
)
|
||||||
from gen_base import gen_runner, gen_typing
|
|
||||||
|
|
||||||
|
|
||||||
from importlib import reload
|
|
||||||
from eth2spec.config import config_util
|
|
||||||
|
|
||||||
|
|
||||||
MAX_BYTES_LENGTH = 100
|
MAX_BYTES_LENGTH = 100
|
||||||
|
|
Loading…
Reference in New Issue