Scope pyspec packages, make pyspec more readable, fix imports

This commit is contained in:
protolambda 2019-03-28 01:21:07 +08:00
parent 883ea93545
commit a106edacad
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
16 changed files with 1728 additions and 20 deletions

View File

@ -12,8 +12,8 @@ GENERATORS = $(sort $(dir $(wildcard $(GENERATOR_DIR)/*/)))
# Map this list of generator paths to a list of test output paths
YAML_TEST_TARGETS = $(patsubst $(GENERATOR_DIR)/%, $(YAML_TEST_DIR)/%, $(GENERATORS))
PY_SPEC_PHASE_0_TARGET = $(PY_SPEC_DIR)/phase0/spec.py
PY_SPEC_ALL_TARGETS = $(PY_SPEC_PHASE_0_TARGET)
PY_SPEC_PHASE_0_TARGETS = $(PY_SPEC_DIR)/eth2/phase0/spec.py
PY_SPEC_ALL_TARGETS = $(PY_SPEC_PHASE_0_TARGETS)
.PHONY: clean all test yaml_tests pyspec phase0
@ -37,11 +37,11 @@ test: $(PY_SPEC_TARGETS)
pyspec: $(PY_SPEC_TARGETS)
# "make phase0" to create pyspec for phase0
phase0: $(PY_SPEC_DIR)/phase0/spec.py
phase0: $(PY_SPEC_PHASE_0_TARGETS)
$(PY_SPEC_DIR)/phase0/spec.py:
python3 $(SCRIPT_DIR)/phase0/build_spec.py $(SPEC_DIR)/core/0_beacon-chain.md $@/spec.py
$(PY_SPEC_DIR)/eth2/phase0/spec.py:
python3 $(SCRIPT_DIR)/phase0/build_spec.py $(SPEC_DIR)/core/0_beacon-chain.md $@

View File

@ -4,15 +4,8 @@ import function_puller
def build_spec(sourcefile, outfile):
code_lines = []
code_lines.append("from build.phase0.utils.minimal_ssz import *")
code_lines.append("from build.phase0.utils.bls_stub import *")
for i in (1, 2, 3, 4, 8, 32, 48, 96):
code_lines.append("def int_to_bytes%d(x): return x.to_bytes(%d, 'little')" % (i, i))
code_lines.append("SLOTS_PER_EPOCH = 64") # stub, will get overwritten by real var
code_lines.append("def slot_to_epoch(x): return x // SLOTS_PER_EPOCH")
code_lines.append("""
from typing import (
Any,
Callable,
@ -20,6 +13,20 @@ from typing import (
NewType,
Tuple,
)
from eth2.utils.minimal_ssz import *
from eth2.utils.bls_stub import *
""")
for i in (1, 2, 3, 4, 8, 32, 48, 96):
code_lines.append("def int_to_bytes%d(x): return x.to_bytes(%d, 'little')" % (i, i))
code_lines.append("""
# stub, will get overwritten by real var
SLOTS_PER_EPOCH = 64
def slot_to_epoch(x): return x // SLOTS_PER_EPOCH
Slot = NewType('Slot', int) # uint64
@ -40,6 +47,8 @@ Store = None
# Monkey patch validator get committee code
_compute_committee = compute_committee
committee_cache = {}
def compute_committee(validator_indices: List[ValidatorIndex],
seed: Bytes32,
index: int,
@ -60,6 +69,8 @@ def compute_committee(validator_indices: List[ValidatorIndex],
# Monkey patch hash cache
_hash = hash
hash_cache = {}
def hash(x):
if x in hash_cache:
return hash_cache[x]

View File

@ -27,6 +27,10 @@ def get_lines(file_name):
code_lines.append('%s = SSZType({' % current_name)
processing_typedef = True
elif pulling_from is not None:
# Add some whitespace between functions
if line[:3] == 'def':
code_lines.append("")
code_lines.append("")
code_lines.append(line)
elif pulling_from is None and len(line) > 0 and line[0] == '|':
row = line[1:].split('|')

View File

@ -4,5 +4,8 @@ setup(
name='gen_helpers',
version='1.0',
packages=['gen_base'],
install_requires=['ruamel.yaml', 'eth-utils']
install_requires=[
"ruamel.yaml==0.15.87",
"eth-utils==1.4.1"
]
)

View File

@ -1,4 +1,4 @@
from shared_eth2.minimal_ssz import hash_tree_root
from eth2.utils.minimal_ssz import hash_tree_root
def jsonize(value, typ, include_hash_tree_roots=False):

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,10 @@
from . import spec
from typing import ( # noqa: F401
from typing import (
Any,
Callable,
List,
NewType,
Tuple,
List
)
from .spec import (

View File

View File

@ -3,7 +3,7 @@ from distutils.core import setup
setup(
name='pyspec',
version='1.0',
packages=['debug', 'utils', 'phase0'],
packages=['eth2'],
install_requires=[
"eth-utils>=1.3.0,<2",
"eth-typing>=2.1.0,<3.0.0",