Skip to content

Commit 6c9e30b

Browse files
dinsepitrou
andauthored
GH-46728: [Python] Skip test_gdb.py tests if PyArrow wasn't built debug (#46755)
### Rationale for this change As mentioned in #46728, if Arrow C++ was built debug, and PyArrow wasn't, test_gdb.py runs tests that fail. ### What changes are included in this PR? The CMAKE_BUILD_TYPE environment variable is propagated from build into PyArrow, where it's checked to skip unit tests. ### Are these changes tested? Yes. I have built PyArrow in release, debug, and relwithdebinfo and observed the new behavior. Because CMakeLists.txt was changed, I built PyArrow twice via setup.py and pip install, and checked the new function. ### Are there any user-facing changes? Devs may skip unit tests that would fail. PyArrow now has build_info() with information about the build type. * GitHub Issue: #46728 Lead-authored-by: Eric Dinse <293818+dinse@users.noreply.github.com> Co-authored-by: Antoine Pitrou <antoine@python.org> Co-authored-by: Antoine Pitrou <pitrou@free.fr> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 6e5d143 commit 6c9e30b

10 files changed

Lines changed: 184 additions & 49 deletions

File tree

python/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,17 @@ endif()
350350
# PyArrow C++
351351
set(PYARROW_CPP_ROOT_DIR pyarrow/src)
352352
set(PYARROW_CPP_SOURCE_DIR ${PYARROW_CPP_ROOT_DIR}/arrow/python)
353+
354+
# Write out compile-time configuration constants
355+
string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_PYBUILD_TYPE)
356+
configure_file("${PYARROW_CPP_SOURCE_DIR}/config_internal.h.cmake"
357+
"${PYARROW_CPP_SOURCE_DIR}/config_internal.h" ESCAPE_QUOTES)
358+
353359
set(PYARROW_CPP_SRCS
354360
${PYARROW_CPP_SOURCE_DIR}/arrow_to_pandas.cc
355361
${PYARROW_CPP_SOURCE_DIR}/benchmark.cc
356362
${PYARROW_CPP_SOURCE_DIR}/common.cc
363+
${PYARROW_CPP_SOURCE_DIR}/config.cc
357364
${PYARROW_CPP_SOURCE_DIR}/datetime.cc
358365
${PYARROW_CPP_SOURCE_DIR}/decimal.cc
359366
${PYARROW_CPP_SOURCE_DIR}/extension_type.cc

python/pyarrow/__init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def parse_git(root, **kwargs):
5959
__version__ = None
6060

6161
import pyarrow.lib as _lib
62-
from pyarrow.lib import (BuildInfo, RuntimeInfo, set_timezone_db_path,
63-
MonthDayNano, VersionInfo, cpp_build_info,
62+
from pyarrow.lib import (BuildInfo, CppBuildInfo, RuntimeInfo, set_timezone_db_path,
63+
MonthDayNano, VersionInfo, build_info, cpp_build_info,
6464
cpp_version, cpp_version_info, runtime_info,
6565
cpu_count, set_cpu_count, enable_signal_handlers,
6666
io_thread_count, set_io_thread_count)
@@ -74,16 +74,18 @@ def print_entry(label, value):
7474
print(f"{label: <26}: {value: <8}")
7575

7676
print("pyarrow version info\n--------------------")
77-
print_entry("Package kind", cpp_build_info.package_kind
78-
if len(cpp_build_info.package_kind) > 0
77+
print_entry("Package kind", build_info.cpp_build_info.package_kind
78+
if len(build_info.cpp_build_info.package_kind) > 0
7979
else "not indicated")
80-
print_entry("Arrow C++ library version", cpp_build_info.version)
80+
print_entry("Arrow C++ library version", build_info.cpp_build_info.version)
8181
print_entry("Arrow C++ compiler",
82-
f"{cpp_build_info.compiler_id} {cpp_build_info.compiler_version}")
83-
print_entry("Arrow C++ compiler flags", cpp_build_info.compiler_flags)
84-
print_entry("Arrow C++ git revision", cpp_build_info.git_id)
85-
print_entry("Arrow C++ git description", cpp_build_info.git_description)
86-
print_entry("Arrow C++ build type", cpp_build_info.build_type)
82+
(f"{build_info.cpp_build_info.compiler_id} "
83+
f"{build_info.cpp_build_info.compiler_version}"))
84+
print_entry("Arrow C++ compiler flags", build_info.cpp_build_info.compiler_flags)
85+
print_entry("Arrow C++ git revision", build_info.cpp_build_info.git_id)
86+
print_entry("Arrow C++ git description", build_info.cpp_build_info.git_description)
87+
print_entry("Arrow C++ build type", build_info.cpp_build_info.build_type)
88+
print_entry("PyArrow build type", build_info.build_type)
8789

8890

8991
def _module_is_available(module):

python/pyarrow/config.pxi

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,18 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from pyarrow.includes.libarrow cimport GetBuildInfo
18+
cimport pyarrow.includes.libarrow as libarrow
19+
cimport pyarrow.includes.libarrow_python as libarrow_python
1920

2021
from collections import namedtuple
2122
import os
2223

2324

2425
VersionInfo = namedtuple('VersionInfo', ('major', 'minor', 'patch'))
2526

26-
BuildInfo = namedtuple(
27-
'BuildInfo',
28-
('version', 'version_info', 'so_version', 'full_so_version',
29-
'compiler_id', 'compiler_version', 'compiler_flags',
30-
'git_id', 'git_description', 'package_kind', 'build_type'))
31-
3227
RuntimeInfo = namedtuple('RuntimeInfo',
3328
('simd_level', 'detected_simd_level'))
3429

35-
cdef _build_info():
36-
cdef:
37-
const CBuildInfo* c_info
38-
39-
c_info = &GetBuildInfo()
40-
41-
return BuildInfo(version=frombytes(c_info.version_string),
42-
version_info=VersionInfo(c_info.version_major,
43-
c_info.version_minor,
44-
c_info.version_patch),
45-
so_version=frombytes(c_info.so_version),
46-
full_so_version=frombytes(c_info.full_so_version),
47-
compiler_id=frombytes(c_info.compiler_id),
48-
compiler_version=frombytes(c_info.compiler_version),
49-
compiler_flags=frombytes(c_info.compiler_flags),
50-
git_id=frombytes(c_info.git_id),
51-
git_description=frombytes(c_info.git_description),
52-
package_kind=frombytes(c_info.package_kind),
53-
build_type=frombytes(c_info.build_type).lower(),
54-
)
55-
56-
57-
cpp_build_info = _build_info()
58-
cpp_version = cpp_build_info.version
59-
cpp_version_info = cpp_build_info.version_info
60-
6130

6231
def runtime_info():
6332
"""
@@ -77,6 +46,58 @@ def runtime_info():
7746
detected_simd_level=frombytes(c_info.detected_simd_level))
7847

7948

49+
BuildInfo = namedtuple(
50+
'BuildInfo',
51+
('build_type', 'cpp_build_info'))
52+
53+
CppBuildInfo = namedtuple(
54+
'CppBuildInfo',
55+
('version', 'version_info', 'so_version', 'full_so_version',
56+
'compiler_id', 'compiler_version', 'compiler_flags',
57+
'git_id', 'git_description', 'package_kind', 'build_type'))
58+
59+
60+
def _build_info():
61+
"""
62+
Get PyArrow build information.
63+
64+
Returns
65+
-------
66+
info : pyarrow.BuildInfo
67+
"""
68+
cdef:
69+
const libarrow_python.CBuildInfo* c_info
70+
const libarrow.CCppBuildInfo* c_cpp_info
71+
72+
c_info = &libarrow_python.GetBuildInfo()
73+
c_cpp_info = &libarrow.GetCppBuildInfo()
74+
75+
cpp_build_info = CppBuildInfo(version=frombytes(c_cpp_info.version_string),
76+
version_info=VersionInfo(c_cpp_info.version_major,
77+
c_cpp_info.version_minor,
78+
c_cpp_info.version_patch),
79+
so_version=frombytes(c_cpp_info.so_version),
80+
full_so_version=frombytes(c_cpp_info.full_so_version),
81+
compiler_id=frombytes(c_cpp_info.compiler_id),
82+
compiler_version=frombytes(
83+
c_cpp_info.compiler_version),
84+
compiler_flags=frombytes(c_cpp_info.compiler_flags),
85+
git_id=frombytes(c_cpp_info.git_id),
86+
git_description=frombytes(c_cpp_info.git_description),
87+
package_kind=frombytes(c_cpp_info.package_kind),
88+
build_type=frombytes(c_cpp_info.build_type).lower(),
89+
)
90+
91+
return BuildInfo(build_type=c_info.build_type.decode('utf-8').lower(),
92+
cpp_build_info=cpp_build_info)
93+
94+
95+
build_info = _build_info()
96+
cpp_build_info = build_info.cpp_build_info
97+
cpp_version = build_info.cpp_build_info.version
98+
cpp_version_info = build_info.cpp_build_info.version_info
99+
100+
80101
def set_timezone_db_path(path):
81102
"""
82103
Configure the path to text timezone database on Windows.

python/pyarrow/includes/libarrow.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ cdef extern from "arrow/util/decimal.h" namespace "arrow" nogil:
6666

6767

6868
cdef extern from "arrow/config.h" namespace "arrow" nogil:
69-
cdef cppclass CBuildInfo" arrow::BuildInfo":
69+
cdef cppclass CCppBuildInfo "arrow::BuildInfo":
7070
int version
7171
int version_major
7272
int version_minor
@@ -82,7 +82,7 @@ cdef extern from "arrow/config.h" namespace "arrow" nogil:
8282
c_string package_kind
8383
c_string build_type
8484

85-
const CBuildInfo& GetBuildInfo()
85+
const CCppBuildInfo& GetCppBuildInfo "arrow::GetBuildInfo"()
8686

8787
cdef cppclass CRuntimeInfo" arrow::RuntimeInfo":
8888
c_string simd_level

python/pyarrow/includes/libarrow_python.pxd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,9 @@ cdef extern from "arrow/python/gdb.h" namespace "arrow::gdb" nogil:
288288

289289
cdef extern from "arrow/python/helpers.h" namespace "arrow::py::internal":
290290
c_bool IsThreadingEnabled()
291+
292+
cdef extern from "arrow/python/config.h" namespace "arrow::py":
293+
cdef cppclass CBuildInfo "arrow::py::BuildInfo":
294+
c_string build_type
295+
296+
const CBuildInfo& GetBuildInfo "arrow::py::GetBuildInfo"()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#include "arrow/python/config.h"
19+
#include "arrow/python/config_internal.h"
20+
21+
namespace arrow {
22+
namespace py {
23+
24+
namespace {
25+
26+
const BuildInfo kBuildInfo = {
27+
PYARROW_BUILD_TYPE,
28+
};
29+
30+
} // namespace
31+
32+
const BuildInfo& GetBuildInfo() { return kBuildInfo; }
33+
34+
} // namespace py
35+
} // namespace arrow
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#pragma once
19+
20+
#include <string>
21+
22+
#include "arrow/python/visibility.h"
23+
24+
namespace arrow {
25+
namespace py {
26+
27+
struct BuildInfo {
28+
// The uppercase build type, e.g. "DEBUG" or "RELEASE"
29+
std::string build_type;
30+
};
31+
32+
/// \brief Get build info for PyArrow.
33+
///
34+
ARROW_PYTHON_EXPORT
35+
const BuildInfo& GetBuildInfo();
36+
37+
} // namespace py
38+
} // namespace arrow
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#define PYARROW_BUILD_TYPE "@UPPERCASE_PYBUILD_TYPE@"

python/pyarrow/tests/test_gdb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ def gdb():
193193

194194
@pytest.fixture(scope='session')
195195
def gdb_arrow(gdb):
196-
if 'deb' not in pa.cpp_build_info.build_type:
196+
if 'deb' not in pa.build_info.cpp_build_info.build_type:
197197
pytest.skip("Arrow C++ debug symbols not available")
198+
if pa.build_info.build_type != 'debug':
199+
pytest.skip("PyArrow C++ not built in debug mode")
198200

199201
skip_if_gdb_script_unavailable()
200202
gdb.run_command(f"source {gdb_script}")

python/pyarrow/tests/test_misc.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,19 @@ def run_with_env_var(env_var):
8585

8686

8787
def test_build_info():
88-
assert isinstance(pa.cpp_build_info, pa.BuildInfo)
88+
assert isinstance(pa.build_info.cpp_build_info, pa.CppBuildInfo)
8989
assert isinstance(pa.cpp_version_info, pa.VersionInfo)
9090
assert isinstance(pa.cpp_version, str)
9191
assert isinstance(pa.__version__, str)
92-
assert pa.cpp_build_info.version_info == pa.cpp_version_info
92+
assert pa.build_info.cpp_build_info.version == pa.cpp_version
93+
assert pa.build_info.cpp_build_info.version_info == pa.cpp_version_info
94+
assert pa.build_info.cpp_build_info is pa.cpp_build_info
9395

94-
assert pa.cpp_build_info.build_type in (
96+
assert pa.build_info.cpp_build_info.build_type in (
97+
'debug', 'release', 'minsizerel', 'relwithdebinfo')
98+
99+
assert isinstance(pa.build_info, pa.BuildInfo)
100+
assert pa.build_info.build_type in (
95101
'debug', 'release', 'minsizerel', 'relwithdebinfo')
96102

97103
# assert pa.version == pa.__version__ # XXX currently false

0 commit comments

Comments
 (0)