Commit f0850eb1 authored by Stefan Behnel's avatar Stefan Behnel

simplify cygdb test code to remove an unnecessary indentation level

parent ce3e9f23
...@@ -35,50 +35,52 @@ build_ext = sys.modules['Cython.Distutils.build_ext'] ...@@ -35,50 +35,52 @@ build_ext = sys.modules['Cython.Distutils.build_ext']
have_gdb = None have_gdb = None
def test_gdb(): def test_gdb():
global have_gdb global have_gdb
if have_gdb is None: if have_gdb is not None:
try: return have_gdb
p = subprocess.Popen(['gdb', '-v'], stdout=subprocess.PIPE)
have_gdb = True try:
except OSError: p = subprocess.Popen(['gdb', '-v'], stdout=subprocess.PIPE)
# gdb was not installed have_gdb = True
have_gdb = False except OSError:
else: # gdb was not installed
gdb_version = p.stdout.read().decode('ascii', 'ignore') have_gdb = False
p.wait() else:
p.stdout.close() gdb_version = p.stdout.read().decode('ascii', 'ignore')
p.wait()
if have_gdb: p.stdout.close()
# Based on Lib/test/test_gdb.py
regex = "^GNU gdb [^\d]*(\d+)\.(\d+)" if have_gdb:
gdb_version_number = list(map(int, re.search(regex, gdb_version).groups())) # Based on Lib/test/test_gdb.py
regex = "^GNU gdb [^\d]*(\d+)\.(\d+)"
if gdb_version_number >= [7, 2]: gdb_version_number = list(map(int, re.search(regex, gdb_version).groups()))
python_version_script = tempfile.NamedTemporaryFile(mode='w+')
if gdb_version_number >= [7, 2]:
python_version_script = tempfile.NamedTemporaryFile(mode='w+')
try:
python_version_script.write(
'python import sys; print("%s %s" % sys.version_info[:2])')
python_version_script.flush()
p = subprocess.Popen(['gdb', '-batch', '-x', python_version_script.name],
stdout=subprocess.PIPE)
try: try:
python_version_script.write( python_version = p.stdout.read().decode('ascii')
'python import sys; print("%s %s" % sys.version_info[:2])') p.wait()
python_version_script.flush()
p = subprocess.Popen(['gdb', '-batch', '-x', python_version_script.name],
stdout=subprocess.PIPE)
try:
python_version = p.stdout.read().decode('ascii')
p.wait()
finally:
p.stdout.close()
try:
python_version_number = list(map(int, python_version.split()))
except ValueError:
have_gdb = False
finally: finally:
python_version_script.close() p.stdout.close()
try:
# Be Python 3 compatible python_version_number = list(map(int, python_version.split()))
if (not have_gdb except ValueError:
or gdb_version_number < [7, 2] have_gdb = False
or python_version_number < [2, 6]): finally:
warnings.warn( python_version_script.close()
'Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6')
have_gdb = False # Be Python 3 compatible
if (not have_gdb
or gdb_version_number < [7, 2]
or python_version_number < [2, 6]):
warnings.warn(
'Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6')
have_gdb = False
return have_gdb return have_gdb
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment