Skip to content

Commit 6ada172

Browse files
pitrouwesm
andcommitted
ARROW-9283: [Python] Expose build info
Closes apache#7605 from pitrou/ARROW-9283-py-build-info Lead-authored-by: Antoine Pitrou <antoine@python.org> Co-authored-by: Wes McKinney <wesm@apache.org> Signed-off-by: Wes McKinney <wesm@apache.org>
1 parent 2fac048 commit 6ada172

7 files changed

Lines changed: 108 additions & 3 deletions

File tree

cpp/src/arrow/util/config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define ARROW_VERSION_PATCH @ARROW_VERSION_PATCH@
2121
#define ARROW_VERSION ((ARROW_VERSION_MAJOR * 1000) + ARROW_VERSION_MINOR) * 1000 + ARROW_VERSION_PATCH
2222

23-
#define ARROW_VERSION_STRING "@ARROW_VERSION_MAJOR@.@ARROW_VERSION_MINOR@.@ARROW_VERSION_PATCH@"
23+
#define ARROW_VERSION_STRING "@ARROW_VERSION@"
2424

2525
#define ARROW_SO_VERSION "@ARROW_SO_VERSION@"
2626
#define ARROW_FULL_SO_VERSION "@ARROW_FULL_SO_VERSION@"

python/pyarrow/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,26 @@ def parse_git(root, **kwargs):
6363
if _gc_enabled:
6464
_gc.enable()
6565

66-
from pyarrow.lib import cpu_count, set_cpu_count
66+
from pyarrow.lib import (BuildInfo, VersionInfo,
67+
cpp_build_info, cpp_version, cpp_version_info,
68+
cpu_count, set_cpu_count)
69+
70+
71+
def show_versions():
72+
"""
73+
Print various version information, to help with error reporting.
74+
"""
75+
# TODO: CPU information and flags
76+
print("pyarrow version info\n--------------------")
77+
print("Package kind: {}".format(cpp_build_info.package_kind
78+
if len(cpp_build_info.package_kind) > 0
79+
else "not indicated"))
80+
print("Arrow C++ library version: {}".format(cpp_build_info.version))
81+
print("Arrow C++ git revision: {}".format(cpp_build_info.git_id))
82+
print("Arrow C++ git description: {}"
83+
.format(cpp_build_info.git_description))
84+
85+
6786
from pyarrow.lib import (null, bool_,
6887
int8, int16, int32, int64,
6988
uint8, uint16, uint32, uint64,

python/pyarrow/config.pxi

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
from pyarrow.includes.libarrow cimport GetBuildInfo
19+
20+
from collections import namedtuple
21+
22+
23+
VersionInfo = namedtuple('VersionInfo', ('major', 'minor', 'patch'))
24+
25+
BuildInfo = namedtuple(
26+
'BuildInfo',
27+
('version', 'version_info', 'so_version', 'full_so_version',
28+
'git_id', 'git_description', 'package_kind'))
29+
30+
cdef _build_info():
31+
cdef:
32+
const CBuildInfo* c_info
33+
34+
c_info = &GetBuildInfo()
35+
36+
return BuildInfo(version=frombytes(c_info.version_string),
37+
version_info=VersionInfo(c_info.version_major,
38+
c_info.version_minor,
39+
c_info.version_patch),
40+
so_version=frombytes(c_info.so_version),
41+
full_so_version=frombytes(c_info.full_so_version),
42+
git_id=frombytes(c_info.git_id),
43+
git_description=frombytes(c_info.git_description),
44+
package_kind=frombytes(c_info.package_kind))
45+
46+
47+
cpp_build_info = _build_info()
48+
cpp_version = cpp_build_info.version
49+
cpp_version_info = cpp_build_info.version_info

python/pyarrow/includes/libarrow.pxd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ cdef extern from "arrow/util/decimal.h" namespace "arrow" nogil:
5151

5252
cdef extern from "arrow/api.h" namespace "arrow" nogil:
5353

54+
cdef cppclass CBuildInfo "arrow::BuildInfo":
55+
int version
56+
int version_major
57+
int version_minor
58+
int version_patch
59+
c_string version_string
60+
c_string so_version
61+
c_string full_so_version
62+
c_string git_id
63+
c_string git_description
64+
c_string package_kind
65+
66+
const CBuildInfo& GetBuildInfo()
67+
5468
enum Type" arrow::Type::type":
5569
_Type_NA" arrow::Type::NA"
5670

python/pyarrow/lib.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ include "compat.pxi"
109109
# Exception types and Status handling
110110
include "error.pxi"
111111

112+
# Configuration information
113+
include "config.pxi"
114+
112115
# pandas API shim
113116
include "pandas-shim.pxi"
114117

python/pyarrow/tests/test_misc.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ def test_cpu_count():
4242
pa.set_cpu_count(n)
4343

4444

45+
def test_build_info():
46+
assert isinstance(pa.cpp_build_info, pa.BuildInfo)
47+
assert isinstance(pa.cpp_version_info, pa.VersionInfo)
48+
assert isinstance(pa.cpp_version, str)
49+
assert isinstance(pa.__version__, str)
50+
assert pa.cpp_build_info.version_info == pa.cpp_version_info
51+
52+
# assert pa.version == pa.__version__ # XXX currently false
53+
54+
4555
@pytest.mark.parametrize('klass', [
4656
pa.Field,
4757
pa.Schema,

python/setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,15 @@ def parse_git(root, **kwargs):
546546
return parse(root, **kwargs)
547547

548548

549+
def guess_next_dev_version(version):
550+
if version.exact:
551+
return version.format_with('{tag}')
552+
else:
553+
def guess_next_version(tag_version):
554+
return default_version.replace('-SNAPSHOT', '')
555+
return version.format_next_version(guess_next_version)
556+
557+
549558
with open('README.md') as f:
550559
long_description = f.read()
551560

@@ -595,7 +604,8 @@ def has_ext_modules(foo):
595604
'root': os.path.dirname(setup_dir),
596605
'parse': parse_git,
597606
'write_to': os.path.join(scm_version_write_to_prefix,
598-
'pyarrow/_generated_version.py')
607+
'pyarrow/_generated_version.py'),
608+
'version_scheme': guess_next_dev_version
599609
},
600610
setup_requires=['setuptools_scm', 'cython >= 0.29'] + setup_requires,
601611
install_requires=install_requires,

0 commit comments

Comments
 (0)