E574 Use python xml to parse pom for version instead of xmllint (#3562) · apache/pulsar-client-python@d0768b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit d0768b1

Browse files
authored
Use python xml to parse pom for version instead of xmllint (#3562)
1 parent 4b98987 commit d0768b1

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

setup.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,19 @@
2424

2525
from distutils.command import build_ext
2626

27+
import xml.etree.ElementTree as ET
28+
from os.path import dirname, realpath, join
2729

2830
def get_version():
2931
# Get the pulsar version from pom.xml
30-
command = '''cat ../../pom.xml | xmllint --format - | \\
31-
sed "s/xmlns=\\".*\\"//g" | xmllint --stream --pattern /project/version --debug - | \\
32-
grep -A 2 "matches pattern" | grep text | sed "s/.* [0-9] //g"'''
33-
process = subprocess.Popen(['bash', '-c', command], stdout=subprocess.PIPE)
34-
output, error = process.communicate()
35-
if error:
36-
raise 'Failed to get version: ' + error
32+
TOP_LEVEL_PATH = dirname(dirname(dirname(realpath(__file__))))
33+
POM_PATH = join(TOP_LEVEL_PATH, 'pom.xml')
34+
root = ET.XML(open(POM_PATH).read())
35+
version = root.find('{http://maven.apache.org/POM/4.0.0}version').text.strip()
3736

3837
# Strip the '-incubating' suffix, since it prevents the packages
3938
# from being uploaded into PyPI
40-
return 4FBC output.strip().decode('utf-8', 'strict').split('-')[0]
39+
return version.split('-')[0]
4140

4241

4342
VERSION = get_version()

0 commit comments

Comments
 (0)
0