2023-06-26 10:01:56 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from .constants import (
|
|
|
|
PHASE0,
|
|
|
|
ALTAIR,
|
|
|
|
BELLATRIX,
|
|
|
|
CAPELLA,
|
|
|
|
DENEB,
|
|
|
|
EIP6110,
|
2023-06-26 10:07:48 +00:00
|
|
|
EIP7002,
|
2024-03-08 03:41:20 +00:00
|
|
|
EIP7251,
|
2024-03-06 15:24:21 +00:00
|
|
|
EIP7549,
|
|
|
|
WHISK,
|
2024-01-13 16:13:08 +00:00
|
|
|
EIP7594,
|
2023-06-26 10:01:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
PREVIOUS_FORK_OF = {
|
|
|
|
PHASE0: None,
|
|
|
|
ALTAIR: PHASE0,
|
|
|
|
BELLATRIX: ALTAIR,
|
|
|
|
CAPELLA: BELLATRIX,
|
|
|
|
DENEB: CAPELLA,
|
|
|
|
EIP6110: DENEB,
|
2024-03-06 15:24:21 +00:00
|
|
|
EIP7549: DENEB,
|
2023-06-26 10:01:56 +00:00
|
|
|
WHISK: CAPELLA,
|
2023-06-26 10:07:48 +00:00
|
|
|
EIP7002: CAPELLA,
|
2024-03-08 03:41:20 +00:00
|
|
|
EIP7251: DENEB,
|
2024-01-13 16:13:08 +00:00
|
|
|
EIP7594: DENEB,
|
2023-06-26 10:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ALL_FORKS = list(PREVIOUS_FORK_OF.keys())
|
|
|
|
|
|
|
|
IGNORE_SPEC_FILES = [
|
|
|
|
"specs/phase0/deposit-contract.md"
|
|
|
|
]
|
|
|
|
|
|
|
|
EXTRA_SPEC_FILES = {
|
|
|
|
BELLATRIX: "sync/optimistic.md"
|
|
|
|
}
|
|
|
|
|
2024-01-11 16:36:06 +00:00
|
|
|
DEFAULT_ORDER = (
|
|
|
|
"beacon-chain",
|
|
|
|
"polynomial-commitments",
|
|
|
|
)
|
|
|
|
|
2023-06-26 10:01:56 +00:00
|
|
|
|
|
|
|
def is_post_fork(a, b) -> bool:
|
|
|
|
"""
|
|
|
|
Returns true if fork a is after b, or if a == b
|
|
|
|
"""
|
|
|
|
if a == b:
|
|
|
|
return True
|
|
|
|
|
|
|
|
prev_fork = PREVIOUS_FORK_OF[a]
|
|
|
|
if prev_fork == b:
|
|
|
|
return True
|
|
|
|
elif prev_fork == None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return is_post_fork(prev_fork, b)
|
|
|
|
|
|
|
|
|
|
|
|
def get_fork_directory(fork):
|
|
|
|
dir1 = f'specs/{fork}'
|
|
|
|
if os.path.exists(dir1):
|
|
|
|
return dir1
|
|
|
|
dir2 = f'specs/_features/{fork}'
|
|
|
|
if os.path.exists(dir2):
|
|
|
|
return dir2
|
|
|
|
raise FileNotFoundError(f"No directory found for fork: {fork}")
|
|
|
|
|
|
|
|
|
2024-01-11 16:36:06 +00:00
|
|
|
def sort_key(s):
|
|
|
|
for index, key in enumerate(DEFAULT_ORDER):
|
|
|
|
if key in s:
|
|
|
|
return (index, s)
|
|
|
|
return (len(DEFAULT_ORDER), s)
|
|
|
|
|
|
|
|
|
2023-06-26 10:01:56 +00:00
|
|
|
def get_md_doc_paths(spec_fork: str) -> str:
|
|
|
|
md_doc_paths = ""
|
|
|
|
|
|
|
|
for fork in ALL_FORKS:
|
|
|
|
if is_post_fork(spec_fork, fork):
|
|
|
|
# Append all files in fork directory recursively
|
2024-01-11 16:36:06 +00:00
|
|
|
for root, _, files in os.walk(get_fork_directory(fork)):
|
|
|
|
filepaths = []
|
2023-06-26 10:01:56 +00:00
|
|
|
for filename in files:
|
|
|
|
filepath = os.path.join(root, filename)
|
2024-01-11 16:36:06 +00:00
|
|
|
filepaths.append(filepath)
|
|
|
|
for filepath in sorted(filepaths, key=sort_key):
|
2023-06-26 10:01:56 +00:00
|
|
|
if filepath.endswith('.md') and filepath not in IGNORE_SPEC_FILES:
|
|
|
|
md_doc_paths += filepath + "\n"
|
|
|
|
# Append extra files if any
|
|
|
|
if fork in EXTRA_SPEC_FILES:
|
|
|
|
md_doc_paths += EXTRA_SPEC_FILES[fork] + "\n"
|
|
|
|
|
|
|
|
return md_doc_paths
|