Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 20, 2024
1 parent 1adf83d commit 05801fc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 44 deletions.
21 changes: 0 additions & 21 deletions mscxyz/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,6 @@ def get_version(self) -> float:
return version
raise ValueError("Could not get version number")

def remove_tags_by_xpath(self, *xpath_strings: str) -> None:
"""Remove tags by xpath strings.
:param xpath_strings: A xpath string.
.. code:: Python
tree.remove_tags_by_xpath(
'/museScore/Score/Style', '//LayoutBreak', '//StemDirection'
)
"""
for xpath_string in xpath_strings:
x: _XPathObject = self.xml_root.xpath(xpath_string)
if isinstance(x, list):
for rm in x:
if isinstance(rm, _Element):
p: _Element | None = rm.getparent()
if isinstance(p, _Element):
p.remove(rm)

def print_diff(self) -> None:
if self.__xml_string_initial is None:
return
Expand Down
12 changes: 9 additions & 3 deletions mscxyz/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import lxml
import lxml.etree
from lxml.etree import _Attrib, _Element, strip_tags
from lxml.etree import _Attrib, _Element

from mscxyz import utils
from mscxyz.utils import INCH
Expand Down Expand Up @@ -244,9 +244,15 @@ def clean(self) -> None:
"""Remove the style, the layout breaks, the stem directions and the
``font``, ``b``, ``i``, ``pos``, ``offset`` tags"""
self.score.xml.remove_tags(
"./Score/Style", ".//LayoutBreak", ".//StemDirection"
"./Score/Style",
".//LayoutBreak",
".//StemDirection",
".//font",
".//b",
".//i",
".//pos",
".//offset",
)
strip_tags(self.score.xml_root, "font", "b", "i", "pos", "offset")

def get(self, style_name: str, raise_exception: bool = True) -> str | None:
"""
Expand Down
7 changes: 1 addition & 6 deletions mscxyz/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import lxml
import lxml.etree
from lxml.etree import _Element, _ElementTree, strip_tags
from lxml.etree import _Element, _ElementTree

if typing.TYPE_CHECKING:
from lxml.etree import _DictAnyStr, _XPathObject
Expand Down Expand Up @@ -331,8 +331,3 @@ def remove_tags_by_xpath(self, *xpath_strings: str) -> None:
p: _Element | None = rm.getparent()
if isinstance(p, _Element):
p.remove(rm)

def strip_tags(self, *tag_names: str) -> Xml:
"""TODO remove. Use remove_tags instead."""
strip_tags(self.root, *tag_names)
return self
14 changes: 0 additions & 14 deletions tests/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,3 @@ def test_with_text(self, custom_xml: Xml) -> None:

def test_navigate_in_tree(self, custom_xml: Xml) -> None:
assert "<root><a><c/></a>" in custom_xml.remove_tags("./a/b").tostring()


class TestStripTags:
def test_element_with_childs(self, custom_xml: Xml) -> None:
custom_xml.strip_tags("a")
assert "<root><b/><c/><d>some text<e/></d></root>" in custom_xml.tostring()

def test_child_element(self, custom_xml: Xml) -> None:
custom_xml.strip_tags("b", "c", "d")
assert "<root><a/>some text<e/></root>" in custom_xml.tostring()

def test_containing_text(self, custom_xml: Xml) -> None:
custom_xml.strip_tags("d")
assert "<root><a><b/><c/></a>some text<e/></root>" in custom_xml.tostring()

0 comments on commit 05801fc

Please sign in to comment.