Skip to content

Commit e2e2132

Browse files
committed
Use shutil.which for python >= 3.3
1 parent c135a5c commit e2e2132

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pygccxml/utils/utils.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import platform
1111
import logging
1212
import tempfile
13+
import shutil
1314
import subprocess
1415
import warnings
1516

@@ -46,21 +47,34 @@ def find_xml_generator(name="castxml"):
4647
pygccxml does currently only support castxml as c++ parser.
4748
4849
"""
50+
51+
if sys.version_info >= (3, 3):
52+
path = _find_xml_generator_for_python_greater_equals_33(name)
53+
else:
54+
path = _find_xml_generator_for_legacy_python(name)
55+
56+
if path == "":
57+
raise(Exception("No c++ parser found. Please install castxml."))
58+
else:
59+
return path.rstrip(), name
60+
61+
62+
def _find_xml_generator_for_python_greater_equals_33(name):
63+
return shutil.which(name)
64+
65+
66+
def _find_xml_generator_for_legacy_python(name):
4967
if platform.system() == "Windows":
5068
command = "where"
5169
else:
5270
command = "which"
53-
5471
p = subprocess.Popen([command, name], stdout=subprocess.PIPE,
5572
stderr=subprocess.PIPE)
5673
path = p.stdout.read().decode("utf-8")
5774
p.wait()
5875
p.stdout.close()
5976
p.stderr.close()
60-
if path == "":
61-
raise(Exception("No c++ parser found. Please install castxml."))
62-
else:
63-
return path.rstrip(), name
77+
return path.rstrip()
6478

6579

6680
def _create_logger_(name):

0 commit comments

Comments
 (0)