mirror of
https://github.com/matrix-org/matrix-spec
synced 2026-04-28 21:34:09 +02:00
Use attrs class for report
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
parent
785a81cd5e
commit
635035d74b
|
|
@ -53,6 +53,20 @@ except ImportError as e:
|
||||||
import_error("jsonpath", "python-jsonpath", "jsonpath", e)
|
import_error("jsonpath", "python-jsonpath", "jsonpath", e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
try:
|
||||||
|
import attrs
|
||||||
|
except ImportError as e:
|
||||||
|
import_error("attrs", "attrs", "attrs", e)
|
||||||
|
raise
|
||||||
|
|
||||||
|
@attrs.define
|
||||||
|
class SchemaDirReport:
|
||||||
|
files: int = 0
|
||||||
|
errors: int = 0
|
||||||
|
|
||||||
|
def add(self, other_report):
|
||||||
|
self.files += other_report.files
|
||||||
|
self.errors += other_report.errors
|
||||||
|
|
||||||
def load_file(path):
|
def load_file(path):
|
||||||
if not path.startswith("file://"):
|
if not path.startswith("file://"):
|
||||||
|
|
@ -134,16 +148,12 @@ def check_schema_file(schema_path):
|
||||||
# Check schema examples are valid.
|
# Check schema examples are valid.
|
||||||
check_schema_examples(schema_path, schema)
|
check_schema_examples(schema_path, schema)
|
||||||
|
|
||||||
def check_schema_dir(schemadir):
|
def check_schema_dir(schemadir: str) -> SchemaDirReport:
|
||||||
report = {
|
report = SchemaDirReport()
|
||||||
"files": 0,
|
|
||||||
"errors": 0,
|
|
||||||
}
|
|
||||||
for root, dirs, files in os.walk(schemadir):
|
for root, dirs, files in os.walk(schemadir):
|
||||||
for schemadir in dirs:
|
for schemadir in dirs:
|
||||||
dir_report = check_schema_dir(os.path.join(root, schemadir))
|
dir_report = check_schema_dir(os.path.join(root, schemadir))
|
||||||
report["files"] += dir_report["files"]
|
report.add(dir_report)
|
||||||
report["errors"] += dir_report["errors"]
|
|
||||||
for filename in files:
|
for filename in files:
|
||||||
if filename.startswith("."):
|
if filename.startswith("."):
|
||||||
# Skip over any vim .swp files.
|
# Skip over any vim .swp files.
|
||||||
|
|
@ -152,10 +162,10 @@ def check_schema_dir(schemadir):
|
||||||
# Skip over any explicit examples (partial event definitions)
|
# Skip over any explicit examples (partial event definitions)
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
report["files"] += 1
|
report.files += 1
|
||||||
check_schema_file(os.path.join(root, filename))
|
check_schema_file(os.path.join(root, filename))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
report["errors"] += 1
|
report.errors += 1
|
||||||
return report
|
return report
|
||||||
|
|
||||||
# The directory that this script is residing in.
|
# The directory that this script is residing in.
|
||||||
|
|
@ -174,17 +184,13 @@ schema_dirs = [
|
||||||
"schemas",
|
"schemas",
|
||||||
]
|
]
|
||||||
|
|
||||||
report = {
|
report = SchemaDirReport()
|
||||||
"files": 0,
|
|
||||||
"errors": 0,
|
|
||||||
}
|
|
||||||
for schema_dir in schema_dirs:
|
for schema_dir in schema_dirs:
|
||||||
dir_report = check_schema_dir(os.path.join(project_dir, "data", schema_dir))
|
dir_report = check_schema_dir(os.path.join(project_dir, "data", schema_dir))
|
||||||
report["files"] += dir_report["files"]
|
report.add(dir_report)
|
||||||
report["errors"] += dir_report["errors"]
|
|
||||||
|
|
||||||
print(f"Found {report['errors']} errors in {report['files']} files")
|
print(f"Found {report.errors} errors in {report.files} files")
|
||||||
|
|
||||||
if report["errors"]:
|
if report.errors:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
jsonschema == 4.17.3
|
jsonschema == 4.17.3
|
||||||
python-jsonpath == 0.9.0
|
python-jsonpath == 0.9.0
|
||||||
|
|
||||||
|
attrs >= 23.1.0
|
||||||
PyYAML >= 3.12
|
PyYAML >= 3.12
|
||||||
requests >= 2.18.4
|
requests >= 2.18.4
|
||||||
towncrier == 23.6.0
|
towncrier == 23.6.0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue