Skip to content

Commit

Permalink
Revert "remove lxml based schema linter"
Browse files Browse the repository at this point in the history
This reverts commit bc4a3f2.

The xsd linting is used also to other xml files,
tool_dependencies.xml. So I guess the changed default for
`--xsd` should be suffiecient
  • Loading branch information
bernt-matthias committed Dec 15, 2023
1 parent 3395bf7 commit 58a45ab
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions planemo/xml/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
from collections import namedtuple

from galaxy.util import unicodify
from galaxy.util.commands import which

try:
Expand All @@ -13,7 +14,7 @@
XMLLINT_COMMAND = "xmllint --noout --schema {0} {1} 2>&1"
INSTALL_VALIDATOR_MESSAGE = (
"This feature requires an external dependency "
"to function, please install xmllint (e.g 'brew "
"to function, pleaes install xmllint (e.g 'brew "
"install libxml2' or 'apt-get install "
"libxml2-utils'."
)
Expand All @@ -40,11 +41,27 @@ def enabled(self):
ValidationResult = namedtuple("ValidationResult", ["passed", "output"])


class LxmlValidator(XsdValidator):
"""Validate XSD files using lxml library."""

def validate(self, schema_path, target_path):
try:
xsd_doc = etree.parse(schema_path)
xsd = etree.XMLSchema(xsd_doc)
xml = etree.parse(target_path)
passed = xsd.validate(xml)
return ValidationResult(passed, xsd.error_log)
except etree.XMLSyntaxError as e:
return ValidationResult(False, unicodify(e))

def enabled(self):
return etree is not None


class XmllintValidator(XsdValidator):
"""Validate XSD files with the external tool xmllint."""

def validate(self, schema_path, target_path):
print("XmllintValidator")
command = XMLLINT_COMMAND.format(schema_path, target_path)
p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
stdout, _ = p.communicate()
Expand All @@ -55,7 +72,7 @@ def enabled(self):
return bool(which("xmllint"))


VALIDATORS = [XmllintValidator()]
VALIDATORS = [LxmlValidator(), XmllintValidator()]


def get_validator(require=True):
Expand Down

0 comments on commit 58a45ab

Please sign in to comment.