Skip to content

Commit 372d435

Browse files
committed
Merge branch 'macos-python-update' into bump_CI_images
2 parents c000b55 + 88f8d6e commit 372d435

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

config/python/python_config.gni

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2023 Project CHIP Authors
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+
15+
python_config_script = get_path_info("python_config.py", "abspath")
16+
17+
python_config = exec_script(python_config_script, [], "json")

config/python/python_config.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import json
5+
import subprocess
6+
import shutil
7+
8+
9+
class Config:
10+
def __init__(self):
11+
cipd_install_dir = os.getenv("PW_PYTHON_CIPD_INSTALL_DIR")
12+
self.python_exe = os.path.join(cipd_install_dir, "bin", "python3")
13+
if not os.path.exists(self.python_exe):
14+
self.python_exe = shutil.which("python3")
15+
if not self.python_exe:
16+
raise FileNotFoundError("Python3 not found")
17+
18+
def get_version(self):
19+
out = subprocess.check_output(
20+
[self.python_exe, "-c", "import sys; print(sys.version_info.major, sys.version_info.minor)"], text=True
21+
)
22+
return out.strip().split(" ")
23+
24+
25+
if __name__ == "__main__":
26+
config = Config()
27+
version = config.get_version()
28+
print(
29+
json.dumps(
30+
{
31+
"version": {
32+
"major": version[0],
33+
"minor": version[1],
34+
}
35+
}
36+
)
37+
)

src/pybindings/pycontroller/BUILD.gn

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import("//build_overrides/pigweed.gni")
1717

1818
import("$dir_pw_build/python.gni")
1919

20+
import("${chip_root}/config/python/python_config.gni")
2021
import("${chip_root}/build/chip/tools.gni")
2122
import("${chip_root}/src/platform/device.gni")
2223
import("${dir_pw_unit_test}/test.gni")
@@ -44,12 +45,14 @@ shared_library("CHIPController") {
4445

4546
# TODO: Update to use GN tools to get actual paths
4647
include_dirs = [ "${chip_root}/third_party/pybind11/repo/include" ]
47-
python_version = exec_script("python-version.py", [], "trim string")
48+
version = python_config.version
4849
if (current_os == "mac") {
4950
include_dirs +=
50-
[ "${chip_root}/.environment/cipd/packages/python/include/python" + python_version ]
51+
[ "${chip_root}/.environment/cipd/packages/python/include/python" +
52+
version.major + "." + version.minor ]
5153
} else if (current_os == "linux") {
52-
include_dirs += [ "/usr/include/python" + python_version ]
54+
include_dirs +=
55+
[ "/usr/include/python" + version.major + "." + version.minor ]
5356
} else {
5457
assert(false, "OS not supported.")
5558
}
@@ -87,7 +90,7 @@ shared_library("CHIPController") {
8790
]
8891
}
8992
if (current_os == "linux") {
90-
libs = [ "python" + python_version ]
93+
libs = [ "python" + version.major + "." + version.minor ]
9194
}
9295
}
9396

0 commit comments

Comments
 (0)