Skip to content

Commit e8d25a2

Browse files
yukawahiroyuki-komatsu
authored andcommitted
Fix #910: Use python venv for macOS build
With this commit macOS build starts using Python virtual environment so that our build steps can comply with PEP 668 [1]. This is only about the build procedure. There must be no behavior change in the build artifacts. #codehealth [1]: https://peps.python.org/pep-0668/ PiperOrigin-RevId: 621123606
1 parent 9c5fc40 commit e8d25a2

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

.github/workflows/macos.yaml

+27-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ concurrency:
1111
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
1212
cancel-in-progress: true
1313

14+
env:
15+
PYTHON_VENV_ROOT: ${{ github.workspace }}/src/python-venv
16+
1417
jobs:
1518
build_arm64:
1619
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-14-Readme.md
@@ -23,9 +26,10 @@ jobs:
2326
with:
2427
submodules: 'recursive'
2528

26-
- name: Install pip dependencies
27-
working-directory: ./src
29+
- name: Setup Python
2830
run: |
31+
python3 -m venv ${PYTHON_VENV_ROOT}
32+
source ${PYTHON_VENV_ROOT}/bin/activate
2933
python3 -m pip install requests
3034
3135
- name: Try to restore update_deps cache
@@ -38,11 +42,13 @@ jobs:
3842
working-directory: ./src
3943
# This command uses src/third_party_cache as the download cache.
4044
run: |
45+
source ${PYTHON_VENV_ROOT}/bin/activate
4146
python3 build_tools/update_deps.py
4247
4348
- name: Build Qt
4449
working-directory: ./src
4550
run: |
51+
source ${PYTHON_VENV_ROOT}/bin/activate
4652
python3 build_tools/build_qt.py --release --confirm_license --macos_cpus=arm64
4753
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
4854
@@ -69,9 +75,10 @@ jobs:
6975
with:
7076
submodules: 'recursive'
7177

72-
- name: Install pip dependencies
73-
working-directory: ./src
78+
- name: Setup Python
7479
run: |
80+
python3 -m venv ${PYTHON_VENV_ROOT}
81+
source ${PYTHON_VENV_ROOT}/bin/activate
7582
python3 -m pip install requests
7683
7784
- name: Try to restore update_deps cache
@@ -84,11 +91,13 @@ jobs:
8491
working-directory: ./src
8592
# This command uses src/third_party_cache as the download cache.
8693
run: |
94+
source ${PYTHON_VENV_ROOT}/bin/activate
8795
python3 build_tools/update_deps.py
8896
8997
- name: Build Qt
9098
working-directory: ./src
9199
run: |
100+
source ${PYTHON_VENV_ROOT}/bin/activate
92101
python3 build_tools/build_qt.py --release --confirm_license --macos_cpus=x86_64
93102
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
94103
@@ -115,9 +124,10 @@ jobs:
115124
with:
116125
submodules: 'recursive'
117126

118-
- name: Install pip dependencies
119-
working-directory: ./src
127+
- name: Setup Python
120128
run: |
129+
python3 -m venv ${PYTHON_VENV_ROOT}
130+
source ${PYTHON_VENV_ROOT}/bin/activate
121131
python3 -m pip install requests
122132
123133
- name: Try to restore update_deps cache
@@ -130,11 +140,13 @@ jobs:
130140
working-directory: ./src
131141
# This command uses src/third_party_cache as the download cache.
132142
run: |
143+
source ${PYTHON_VENV_ROOT}/bin/activate
133144
python3 build_tools/update_deps.py
134145
135146
- name: Build Qt
136147
working-directory: ./src
137148
run: |
149+
source ${PYTHON_VENV_ROOT}/bin/activate
138150
python3 build_tools/build_qt.py --release --confirm_license --macos_cpus=x86_64,arm64
139151
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
140152
@@ -161,9 +173,10 @@ jobs:
161173
with:
162174
submodules: 'recursive'
163175

164-
- name: Install pip dependencies
165-
working-directory: ./src
176+
- name: Setup Python
166177
run: |
178+
python3 -m venv ${PYTHON_VENV_ROOT}
179+
source ${PYTHON_VENV_ROOT}/bin/activate
167180
python3 -m pip install requests
168181
169182
- name: Try to restore update_deps cache
@@ -176,11 +189,13 @@ jobs:
176189
working-directory: ./src
177190
# This command uses src/third_party_cache as the download cache.
178191
run: |
192+
source ${PYTHON_VENV_ROOT}/bin/activate
179193
python3 build_tools/update_deps.py
180194
181195
- name: Build Qt
182196
working-directory: ./src
183197
run: |
198+
source ${PYTHON_VENV_ROOT}/bin/activate
184199
python3 build_tools/build_qt.py --release --confirm_license
185200
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
186201
@@ -201,9 +216,10 @@ jobs:
201216
- name: checkout
202217
uses: actions/checkout@v4
203218

204-
- name: Install pip dependencies
205-
working-directory: ./src
219+
- name: Setup Python
206220
run: |
221+
python3 -m venv ${PYTHON_VENV_ROOT}
222+
source ${PYTHON_VENV_ROOT}/bin/activate
207223
python3 -m pip install requests
208224
209225
- name: Try to restore update_deps cache
@@ -216,4 +232,5 @@ jobs:
216232
working-directory: ./src
217233
# This command uses src/third_party_cache as the download cache.
218234
run: |
235+
source ${PYTHON_VENV_ROOT}/bin/activate
219236
python3 build_tools/update_deps.py --cache_only

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
/src-*
3535
/src_*
3636

37+
# Python venv dir used to conform PEP 668
38+
# https://peps.python.org/pep-0668/
39+
/src/python-venv
40+
3741
# Mozc build artifacts by Bazel (symbolic links)
3842
/src/bazel-bin
3943
/src/bazel-out

docs/build_mozc_in_osx.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ If you are not sure what the following commands do, please check the description
99
and make sure the operations before running them.
1010

1111
```
12-
python3 -m pip install requests
13-
1412
git clone https://github.com/google/mozc.git
1513
cd mozc/src
1614
15+
export PYTHON_VENV_ROOT=${PWD}/python-venv
16+
python3 -m venv ${PYTHON_VENV_ROOT}
17+
source ${PYTHON_VENV_ROOT}/bin/activate
18+
python3 -m pip install requests
19+
1720
python3 build_tools/update_deps.py
1821
1922
# CMake is also required to build Qt.
@@ -62,6 +65,19 @@ cd mozc/src
6265

6366
Hereafter you can do all the operations without changing directory.
6467

68+
### Set up and enable Python virtual environment
69+
70+
The following commands set up Python virtual environment under `mozc/src/python-venv`.
71+
72+
```
73+
export PYTHON_VENV_ROOT=${PWD}/python-venv
74+
python3 -m venv ${PYTHON_VENV_ROOT}
75+
source ${PYTHON_VENV_ROOT}/bin/activate
76+
python3 -m pip install requests
77+
```
78+
79+
Using `mozc/src/python-venv` as the virtual environment location is not mandatory. Any other location should also work.
80+
6581
### Check out additional build dependencies
6682

6783
```

0 commit comments

Comments
 (0)