xref: /aosp_15_r20/external/bazelbuild-rules_python/python/private/get_local_runtime_info.py (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1# Copyright 2024 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import json
16import sys
17import sysconfig
18
19data = {
20    "major": sys.version_info.major,
21    "minor": sys.version_info.minor,
22    "micro": sys.version_info.micro,
23    "include": sysconfig.get_path("include"),
24    "implementation_name": sys.implementation.name,
25}
26
27config_vars = [
28    # The libpythonX.Y.so file. Usually?
29    # It might be a static archive (.a) file instead.
30    "LDLIBRARY",
31    # The directory with library files. Supposedly.
32    # It's not entirely clear how to get the directory with libraries.
33    # There's several types of libraries with different names and a plethora
34    # of settings.
35    # https://stackoverflow.com/questions/47423246/get-pythons-lib-path
36    # For now, it seems LIBDIR has what is needed, so just use that.
37    "LIBDIR",
38    # The versioned libpythonX.Y.so.N file. Usually?
39    # It might be a static archive (.a) file instead.
40    "INSTSONAME",
41    # The libpythonX.so file. Usually?
42    # It might be a static archive (a.) file instead.
43    "PY3LIBRARY",
44    # The platform-specific filename suffix for library files.
45    # Includes the dot, e.g. `.so`
46    "SHLIB_SUFFIX",
47]
48data.update(zip(config_vars, sysconfig.get_config_vars(*config_vars)))
49print(json.dumps(data))
50