Skip to content

Commit

Permalink
Move ElementTree patching to be earlier (lyft#44)
Browse files Browse the repository at this point in the history
This makes it OK for checkers to import ElementTree without adverse effects.
  • Loading branch information
Ilya Konstantinov authored Jun 25, 2019
1 parent 985ba29 commit ce17137
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion xiblint/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.9.4'
__version__ = '0.9.5'
9 changes: 6 additions & 3 deletions xiblint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import sys

from xiblint import __version__
from xiblint.config import Config
from xiblint.xibcontext import XibContext
import xiblint.rules


def make_epilog_text():
import xiblint.rules
description = "Lint rules:\n"

for rule_name in sorted(xiblint.rules.rule_checkers.keys()):
Expand All @@ -26,6 +24,9 @@ def make_epilog_text():


def main():
from patch_element_tree import patch_element_tree
patch_element_tree()

parser = argparse.ArgumentParser(
description='.xib / .storyboard linter',
epilog=make_epilog_text(),
Expand All @@ -41,6 +42,7 @@ def main():
args = parser.parse_args()

try:
from xiblint.config import Config
config = Config()
except IOError as ex:
print('Error: {}\n'.format(ex))
Expand Down Expand Up @@ -75,6 +77,7 @@ def main():


def process_file(file_path, config):
from xiblint.xibcontext import XibContext
checkers = config.checkers(file_path)
context = XibContext(file_path)
if context.tree:
Expand Down
5 changes: 5 additions & 0 deletions xiblint/patch_element_tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def patch_element_tree():
# HACK to ensure cElementTree is not loaded -- we need the pure Python implementation
import sys
assert 'xml.etree.ElementTree' not in sys.modules
sys.modules['_elementtree'] = None # type: ignore
10 changes: 2 additions & 8 deletions xiblint/xmlutils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import weakref

# HACK to ensure cElementTree is not loaded -- we need the pure Python implementation
import sys

assert 'xml.etree.ElementTree' not in sys.modules
sys.modules['_elementtree'] = None # type: ignore

from xml.etree import ElementTree # noqa: E402
from defusedxml.ElementTree import DefusedXMLParser # noqa: E402
from xml.etree import ElementTree
from defusedxml.ElementTree import DefusedXMLParser


class _TreeBuilder(ElementTree.TreeBuilder):
Expand Down

0 comments on commit ce17137

Please sign in to comment.