Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) Thomasht86/move relaxng files #932

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions vespa/configuration/relaxng/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pathlib import Path
import os
from lxml import etree

# Dict of filename (without extension) to RELAXNG schema (open(rb))
RELAXNG = {}
to_import = ["services", "validation-overrides"]
for schema_file in Path(os.path.dirname(__file__)).glob("*.rng"):
if schema_file.stem in to_import:
with open(schema_file, "rb") as fh:
RELAXNG[schema_file.stem] = etree.RelaxNG(etree.parse(fh))
7 changes: 2 additions & 5 deletions vespa/configuration/services.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from vespa.configuration.vt import VT, create_tag_function, voids
from lxml import etree
from vespa.configuration.relaxng import RELAXNG

# List of XML tags (customized for Vespa configuration)
services_tags = [
Expand Down Expand Up @@ -164,9 +164,6 @@
sanitized_name = VT.sanitize_tag_name(tag)
_g[sanitized_name] = create_tag_function(tag, tag in voids)

with open("tests/testfiles/relaxng/services.rng", "rb") as schema_file:
relaxng = etree.RelaxNG(etree.parse(schema_file))


def validate_services(xml_schema: str) -> bool:
"""
Expand All @@ -178,4 +175,4 @@ def validate_services(xml_schema: str) -> bool:
Returns:
bool: True if the XML schema is valid, False otherwise
"""
return relaxng.validate(xml_schema)
return RELAXNG["services"].validate(xml_schema)
Loading