Skip to content

Commit

Permalink
Merge branch 'main' into m62054_exintrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
DenizUgur authored Oct 19, 2023
2 parents f8c66c5 + 3fc7a85 commit 0606714
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/problem-matchers.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"owner": "loguru",
"pattern": [
{
"regexp": "(ERROR|WARNING).*\\|.+(?:\\[3[13]m.\\[1m)(?:(.*).\\[0m)$",
"regexp": "^(ERROR|WARNING)\\s*:\\s(.+)$",
"severity": 1,
"message": 2
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import json
import requests
from glob import glob
from loguru import logger
from functools import cache

from .unique_logger import logger

MP4RA_BOXES_URL = "https://mp4ra.org/boxes.json"
DOCUMENT_STATUS_URL = (
"https://github.com/MPEGGroup/FileFormat/blob/master/DocumentStatus.md"
Expand Down
40 changes: 40 additions & 0 deletions src/common/unique_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import sys
from loguru import logger as _logger


class LoggerWrapper:
DEDUPLICATE = ["debug", "info", "success", "warning", "error", "critical"]

def __init__(self):
self.messages = set()

def _process(self, severity, message, **kwargs):
if message not in self.messages:
self.messages.add(message)
function = getattr(_logger, severity)
function(message, **kwargs)

def __getattribute__(self, __name: str):
if __name in ["_process", "messages"]:
return object.__getattribute__(self, __name)

if __name in LoggerWrapper.DEDUPLICATE:
return lambda message, **kwargs: self._process(__name, message, **kwargs)
return getattr(_logger, __name)


logger = LoggerWrapper()

# If running in CI, don't add colors
if "CI" in os.environ:
fmt = "{level: <8}: {message}"
else:
fmt = "<level>{level: <8}: {message}</level>"

# Remove default sink
logger.remove(0)

# Add sinks
logger.add(sys.stderr, format=fmt)
logger.add("/tmp/construct.log", format=fmt, level="ERROR")
3 changes: 1 addition & 2 deletions src/construct/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import os
import json
from glob import glob
from loguru import logger
from functools import cache
from dataclasses import dataclass, field

from common.unique_logger import logger
from common import get_mp4ra_boxes

BOXES = {}
Expand Down Expand Up @@ -160,7 +160,6 @@ def update_container(_spec, _box):


def main():
logger.add("/tmp/construct.log", level="ERROR")
files = glob("../data/standard_features/**/*.json")

# Ignore unrelated files
Expand Down
2 changes: 1 addition & 1 deletion src/construct/construct_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from loguru import logger
from common.unique_logger import logger

from construct.boxes import main as construct_boxes_main
from construct.dictionary import main as construct_dictionary_main
Expand Down
11 changes: 7 additions & 4 deletions src/construct/coverage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import json
from glob import glob
from loguru import logger

from common.unique_logger import logger
from common import *


def main():
logger.add("/tmp/construct.log", level="ERROR")

with open("output/dictionary.json", "r", encoding="utf-8") as f:
dictionary = json.load(f)

Expand Down Expand Up @@ -78,9 +76,11 @@ def main():
extensions = list(set(extensions) - ignored)

missing_extensions = set()
fourcc_in_extensions = set()
for extension in extensions:
with open(extension, "r", encoding="utf-8") as f:
ext_data = json.load(f)
fourcc_in_extensions.update([e["box"]["@Type"] for e in ext_data["extensions"]])
missing_extensions.update(
[f"{e['location']}.{e['box']['@Type']}" for e in ext_data["extensions"]]
)
Expand All @@ -106,7 +106,10 @@ def main():

if not known_box:
# Check if this was in under consideration files
if any(["under_consideration" in f for f in in_files]):
if (
any(["under_consideration" in f for f in in_files])
and box_fourcc in fourcc_in_extensions
):
extra = ""
if box_fourcc in get_mp4ra_boxes():
extra = " It exists in MP4RA though."
Expand Down
4 changes: 1 addition & 3 deletions src/construct/files.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import json
from glob import glob
from loguru import logger

from common.unique_logger import logger
from common import get_ignored_files, get_mp4ra_boxes


Expand Down Expand Up @@ -112,8 +112,6 @@ def crawl(root, path):


def main():
logger.add("/tmp/construct.log", level="ERROR")

# Check which boxes can be found anywhere (container.fourcc=* && container.type=*)
can_be_found_anywhere = set()
with open("output/boxes.json", "r", encoding="utf-8") as f:
Expand Down
5 changes: 2 additions & 3 deletions src/construct/hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
from loguru import logger
from dataclasses import dataclass
from argparse import ArgumentParser

from common.unique_logger import logger


@dataclass
class Box:
Expand Down Expand Up @@ -317,8 +318,6 @@ def build_farm(_data, ruleset):


def main():
logger.add("/tmp/construct.log", level="ERROR")

parser = ArgumentParser()
parser.add_argument(
"-r",
Expand Down

0 comments on commit 0606714

Please sign in to comment.