Skip to content

Commit

Permalink
Merge pull request #21 from MPEGGroup/dev
Browse files Browse the repository at this point in the history
Syntax parsing and dependency upgrades
  • Loading branch information
podborski authored Aug 11, 2023
2 parents 7c7c9ab + 3263c5f commit 3126a6f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 44 deletions.
12 changes: 6 additions & 6 deletions conformance-search/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion conformance-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"copyfiles": "^2.4.1",
"eslint": "^8.46.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.10.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jest": "^27.2.3",
Expand Down
40 changes: 39 additions & 1 deletion src/construct/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import json
from glob import glob
from loguru import logger
from functools import cache
from dataclasses import dataclass, field

from common import get_mp4ra_boxes

BOXES = {}
EXTENSIONS = {}
TYPE_HIERARCHY = {}


@dataclass
Expand Down Expand Up @@ -43,6 +45,22 @@ def serialize(self):
}


@cache
def get_all_inheritors(cls):
"""
Get all inheritors of a class. Skip subclasses that are not in TYPE_HIERARCHY.
If requested class is not in TYPE_HIERARCHY, return a set with only the requested class.
"""
if cls not in TYPE_HIERARCHY:
return set([cls])
subclasses = set(sc for sc in TYPE_HIERARCHY[cls] if sc in TYPE_HIERARCHY)
return (
set([cls])
| subclasses
| set(s for c in subclasses for s in get_all_inheritors(c))
)


def get_all_boxes(json_file):
with open(json_file, "r") as f:
data = json.load(f)
Expand Down Expand Up @@ -114,7 +132,8 @@ def update_container(_spec, _box):
{"fourcc": container_box.fourcc, "type": container_box.type}
)
else:
_box.containers.append({"fourcc": "*", "type": container_box["type"]})
for inheritor in get_all_inheritors(container_box["type"]):
_box.containers.append({"fourcc": "*", "type": inheritor})

for container_box in [_box for _box in container_boxes if isinstance(_box, Box)]:
if container_box.incomplete:
Expand All @@ -135,6 +154,25 @@ def main():
for file in files:
get_all_boxes(file)

# Get all available syntaxes
extract_syntax = re.compile(
r"(?:[Cc]lass\s*([a-zA-Z0-9]+).*extends\s*([a-zA-Z0-9]+)).*{",
flags=re.MULTILINE | re.DOTALL,
)
syntaxes = set()
for value in BOXES.values():
for _box in value:
matches = extract_syntax.findall(_box.syntax)
for match in matches:
syntaxes.add(match)

# Extract type hierarchy
for cls, ext in syntaxes:
if ext not in TYPE_HIERARCHY:
TYPE_HIERARCHY[ext] = set()
TYPE_HIERARCHY[ext].add(cls)

# Update containers
for spec, boxes in BOXES.items():
for _box in boxes:
update_container(spec, _box)
Expand Down
40 changes: 5 additions & 35 deletions src/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ python-docx = "^0.8.11"
tqdm = "^4.65.0"
loguru = "^0.7.0"
gitpython = "^3.1.32"
jsonschema = "^4.18.4"
jsonschema = "^4.19.0"
pytest-check = "^2.2.0"
pytest-dependency = "^0.5.1"
requests = "^2.31.0"
Expand Down

0 comments on commit 3126a6f

Please sign in to comment.