Skip to content

Commit f3f0cb9

Browse files
Removed lxml from dependencies
Switched usages to standard lib to reduce dependencies
1 parent da9a63e commit f3f0cb9

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

arcpyext/_patches/metadata/Metadata.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
"""
66
import collections.abc
77
import re
8+
import xml.etree.ElementTree as ET
89

910
import arcpy
1011

11-
from lxml import etree as ET
12-
1312
from ...TopicCategory import TopicCategory
1413

1514
TOPIC_CATEGORIES_DISPLAY_NAME_TO_ENUM = {e.display_name.lower(): e for e in TopicCategory}
@@ -47,13 +46,13 @@ def topicCategories_getter(self):
4746
raise NotImplementedError("Metadata object currently has none or empty XML.")
4847

4948
metadata_xml_tree = ET.ElementTree(ET.fromstring(metadata_xml))
50-
topic_categories_xpath = "/metadata[@xml:lang=\"en\"]/dataIdInfo/tpCat/TopicCatCd"
49+
topic_categories_xpath = "./dataIdInfo/tpCat/TopicCatCd"
5150

5251
# get a list of topic elements
53-
topic_category_elements = metadata_xml_tree.xpath(topic_categories_xpath)
52+
topic_category_elements = metadata_xml_tree.findall(topic_categories_xpath)
5453

5554
if not topic_category_elements:
56-
# no elmeents found, return empty list
55+
# no elements found, return empty list
5756
return []
5857

5958
# convert each element value to a str
@@ -68,7 +67,7 @@ def topicCategories_setter(self, value):
6867

6968
# process value into elements
7069
if isinstance(value, str):
71-
# presume we were supplied a one or more topic categorie as a string, delimited
70+
# presume we were supplied a one or more topic categories as a string, delimited
7271
value = [s.strip() for s in re.split(",|;", value)]
7372
elif isinstance(value, TopicCategory):
7473
# a single enumerated type has been given, put in a list
@@ -80,20 +79,20 @@ def topicCategories_setter(self, value):
8079
elif not isinstance(value, collections.abc.Sequence):
8180
raise ValueError("Input 'topicCategories' value is not valid.")
8281

83-
# value is now a sequence presumeably of either an enumerated type already, or a string representing the
82+
# value is now a sequence presumably of either an enumerated type already, or a string representing the
8483
# display name, the ISO name, or portal name.
8584
# attempt to resolve each sequence value to an enum and then create element
8685
value = [ET.Element("TopicCatCd", value=_str_to_topic_category(v).value) for v in value]
8786

8887
# set elements in XML
89-
topic_categories_parent_xpath = "/metadata[@xml:lang=\"en\"]/dataIdInfo/tpCat"
88+
topic_categories_parent_xpath = "./dataIdInfo/tpCat"
9089
metadata_xml_tree = ET.ElementTree(ET.fromstring(metadata_xml))
91-
topic_category_parent_element = next(iter(metadata_xml_tree.xpath(topic_categories_parent_xpath)), None)
90+
topic_category_parent_element = next(iter(metadata_xml_tree.findall(topic_categories_parent_xpath)), None)
9291
topic_category_parent_element.clear()
9392
topic_category_parent_element.extend(value)
9493

9594
# save XML back to arcpy
96-
self.xml = ET.tostring(metadata_xml_tree.getroot(), encoding="utf-8", pretty_print=False)
95+
self.xml = "<?xml version=\"1.0\"?>{}".format(ET.tostring(metadata_xml_tree.getroot(), encoding="unicode"))
9796

9897
topicCategories_prop = property(topicCategories_getter, topicCategories_setter)
9998

arcpyext/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.7.32"
1+
__version__ = "0.7.33"
22
__author__ = "David Whittingham; David Payne; Adam Kerz; Peter Reyne; Daniel Baternik; Chris Blanchfield; Gary Bagnall"
33
__copyright__ = "Copyright (C) 2013-2024 David Whittingham"

arcpyext/toolbox/PythonToolbox.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import arcpy
1616

17-
from lxml import etree as ET
17+
import xml.etree.ElementTree as ET
1818

1919

2020
class PythonToolbox(object):
@@ -61,9 +61,9 @@ def load_xml(self):
6161
t.load_xml()
6262

6363
def save_definitions(self):
64-
#with open(self.xml_path,'w') as fout:
65-
# self.xml_tree.write(fout,encoding = 'utf-8')
66-
self.xml_tree.write(self.xml_path, encoding='utf-8')
64+
with open(self.xml_path, 'wb') as fout:
65+
self.xml_tree.write(fout, encoding='utf-8', xml_declaration=True)
66+
6767
# and save tools too
6868
for t in self.tools:
6969
t.save_definitions()
@@ -104,7 +104,7 @@ def load_xml(self):
104104

105105
def save_definitions(self):
106106
with open(self.xml_path, 'wb') as fout:
107-
self.xml_tree.write(fout, encoding='utf-8')
107+
self.xml_tree.write(fout, encoding='utf-8', xml_declaration=True)
108108

109109
def set_description_in_xml(self, description):
110110
e = PythonToolbox.get_or_create_element(self.xml_tree.getroot(), 'dataIdInfo')
@@ -121,4 +121,4 @@ def set_parameter_description_in_xml(self, param_name, description):
121121
def set_summary_in_xml(self, summary):
122122
e = PythonToolbox.get_or_create_element(self.xml_tree.getroot(), 'tool', attributes={'name': self.tool_name})
123123
e = PythonToolbox.get_or_create_element(e, 'summary')
124-
e.text = summary
124+
e.text = summary

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
aenum>=3.1.11,<4
22
future>=0.18.2
3-
lxml>=4.3.2,<5
4-
olefile==0.46 ; python_version<'3.4'
3+
olefile==0.47 ; python_version<'3.4'
54
pathlib2>=2.3.4,<3
65
pythonnet>=2.4.0,<3 ; python_version<'3'
76
pythonnet>=3.0.0,<4 ; python_version>='3'
87
sqlparse>=0.3.1,<0.4 ; python_version<'3'
98
sqlparse>=0.4.4,<0.5 ; python_version>='3'
10-
XlsxWriter>=2.0.0,<3
9+
XlsxWriter>=2,<3 ; python_version<'3'
10+
XlsxWriter>=3,<4 ; python_version>='3'

0 commit comments

Comments
 (0)