Skip to content

Commit d3dbaf0

Browse files
authored
Test install deps with uv (#488)
* never use container + use uv * install uv * fix unisntall * in source * update main doc as well * sudo * run on runner by default * use sudo only when needed * df * lots of cleaning * purge * one more * let's save space * again * timeout * abandoninig * am I proud of this... * fix * would love to pass * ofc * venv for all
1 parent 762a5b3 commit d3dbaf0

File tree

2 files changed

+87
-19
lines changed

2 files changed

+87
-19
lines changed

.github/workflows/build_main_documentation.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ on:
4646
convert_notebooks:
4747
type: boolean
4848
description: "Convert notebooks to markdown files before building docs."
49-
# Docker image to use for the build. Set custom_container="" if you don't need any.
50-
# Default containers is "huggingface/transformers-doc-builder" which has all the necessary dependencies (torch,
51-
# transformers, tensorflow, etc.) but is quite heavy to download.
49+
# Docker image to use for the build. Set custom_container="huggingface/transformers-doc-builder" if you need
50+
# a complete install. Default to `""` which means CI will run on the runner directly.
5251
custom_container:
5352
type: string
54-
default: "huggingface/transformers-doc-builder"
53+
default: ""
5554
description: "Docker image to use for the build."
5655
secrets:
5756
hf_token:
@@ -64,6 +63,8 @@ jobs:
6463
runs-on: ubuntu-latest
6564
container:
6665
${{ inputs.custom_container }}
66+
env:
67+
UV_HTTP_TIMEOUT: 900 # max 15min to install deps (shouldn't take more than 5min)
6768

6869
steps:
6970
- uses: actions/checkout@v2
@@ -88,6 +89,29 @@ jobs:
8889
node-version: '20'
8990
cache-dependency-path: "kit/package-lock.json"
9091

92+
- name: Export ROOT_APT_GET ('apt-get' or 'sudo apt-get')
93+
# Use `sudo` only if running on the base runner.
94+
# When using a container, `sudo` is not needed (and not installed)
95+
run: |
96+
if [ -z "${{ inputs.custom_container }}" ]
97+
then
98+
echo "ROOT_APT_GET=sudo apt-get" >> $GITHUB_ENV
99+
else
100+
echo "ROOT_APT_GET=apt-get" >> $GITHUB_ENV
101+
fi
102+
103+
- name: Export PIP_OR_UV ('pip' or 'uv pip')
104+
# Use `uv` only if running on the base runner.
105+
# When using a container, `pip` has already been used to installed existing deps
106+
# and is therefore quicker to resolve (already have some cached stuff).
107+
run: |
108+
if [ -z "${{ inputs.custom_container }}" ]
109+
then
110+
echo "PIP_OR_UV=uv pip" >> $GITHUB_ENV
111+
else
112+
echo "PIP_OR_UV=pip" >> $GITHUB_ENV
113+
fi
114+
91115
- name: Set env variables
92116
run: |
93117
if [ -z "${{ inputs.path_to_docs }}" ]
@@ -107,35 +131,44 @@ jobs:
107131
108132
# Needed to upload zips to hf.co
109133
- name: Install zip
110-
run: apt-get install -y zip
134+
# Use sudo only if running on the base runner.
135+
# When using a container, `sudo` is not needed (and not installed).
136+
run: $ROOT_APT_GET install -y zip
111137

112138
- name: Install libgl1
113139
if: inputs.install_libgl1
114-
run: apt-get install -y libgl1
140+
run: $ROOT_APT_GET install -y libgl1
115141

116142
- name: Install Rust
117143
uses: actions-rs/toolchain@v1
118144
if: inputs.install_rust
119145
with:
120146
toolchain: stable
121147

148+
# Use venv in both cases
149+
- name: Install uv
150+
run: |
151+
pip install -U uv
152+
uv venv
153+
122154
- name: Setup environment
123155
shell: bash
124156
run: |
125-
pip uninstall -y doc-builder
157+
source .venv/bin/activate
158+
$PIP_OR_UV uninstall doc-builder
126159
cd doc-builder
127160
git pull origin main
128-
pip install .
161+
$PIP_OR_UV install .
129162
cd ..
130163
131164
if [[ -n "${{ inputs.package_path }}" ]]
132165
then
133166
cd ${{ inputs.package_path }}
134-
pip install .[dev]
167+
$PIP_OR_UV install .[dev]
135168
elif [[ "${{ inputs.additional_args }}" != *"--not_python_module"* ]];
136169
then
137170
cd ${{ inputs.package }}
138-
pip install .[dev]
171+
$PIP_OR_UV install .[dev]
139172
fi
140173
cd ..
141174
@@ -162,6 +195,7 @@ jobs:
162195
- name: Convert notebooks to markdown files
163196
if: inputs.convert_notebooks
164197
run: |
198+
source .venv/bin/activate
165199
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
166200
remaining_part=$(echo "${{ env.doc_folder }}" | perl -pe 's|^[^/]+||')
167201
remaining_part=${remaining_part%/}
@@ -174,6 +208,7 @@ jobs:
174208
env:
175209
NODE_OPTIONS: --max-old-space-size=6656
176210
run: |
211+
source .venv/bin/activate
177212
echo "doc_folder has been set to ${{ env.doc_folder }}"
178213
cd doc-builder
179214
args="--build_dir ../build_dir --clean --html ${{ inputs.additional_args }} --repo_owner ${{ inputs.repo_owner }} --repo_name ${{ inputs.package }} --version_tag_suffix=${{ inputs.version_tag_suffix }}"

.github/workflows/build_pr_documentation.yml

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ on:
4646
convert_notebooks:
4747
type: boolean
4848
description: "Convert notebooks to markdown files before building docs."
49-
# Docker image to use for the build. Set custom_container="" if you don't need any.
50-
# Default containers is "huggingface/transformers-doc-builder" which has all the necessary dependencies (torch,
51-
# transformers, tensorflow, etc.) but is quite heavy to download.
49+
# Docker image to use for the build. Set custom_container="huggingface/transformers-doc-builder" if you need
50+
# a complete install. Default to `""` which means CI will run on the runner directly.
5251
custom_container:
5352
type: string
54-
default: "huggingface/transformers-doc-builder"
53+
default: ""
5554
description: "Docker image to use for the build."
5655
# Debug purposes only!
5756
doc_builder_revision:
@@ -65,6 +64,8 @@ jobs:
6564
runs-on: ubuntu-latest
6665
container:
6766
${{ inputs.custom_container }}
67+
env:
68+
UV_HTTP_TIMEOUT: 900 # max 15min to install deps (shouldn't take more than 5min)
6869

6970
steps:
7071
- uses: actions/checkout@v2
@@ -83,6 +84,29 @@ jobs:
8384
node-version: '20'
8485
cache-dependency-path: "kit/package-lock.json"
8586

87+
- name: Export ROOT_APT_GET ('apt-get' or 'sudo apt-get')
88+
# Use `sudo` only if running on the base runner.
89+
# When using a container, `sudo` is not needed (and not installed)
90+
run: |
91+
if [ -z "${{ inputs.custom_container }}" ]
92+
then
93+
echo "ROOT_APT_GET=sudo apt-get" >> $GITHUB_ENV
94+
else
95+
echo "ROOT_APT_GET=apt-get" >> $GITHUB_ENV
96+
fi
97+
98+
- name: Export PIP_OR_UV ('pip' or 'uv pip')
99+
# Use `uv` only if running on the base runner.
100+
# When using a container, `pip` has already been used to installed existing deps
101+
# and is therefore quicker to resolve (already have some cached stuff).
102+
run: |
103+
if [ -z "${{ inputs.custom_container }}" ]
104+
then
105+
echo "PIP_OR_UV=uv pip" >> $GITHUB_ENV
106+
else
107+
echo "PIP_OR_UV=pip" >> $GITHUB_ENV
108+
fi
109+
86110
- name: Set env variables
87111
run: |
88112
if [ -z "${{ inputs.path_to_docs }}" ]
@@ -109,31 +133,38 @@ jobs:
109133
110134
- name: Install libgl1
111135
if: inputs.install_libgl1
112-
run: apt-get install -y libgl1
136+
run: $ROOT_APT_GET install -y libgl1
113137

114138
- name: Install Rust
115139
uses: actions-rs/toolchain@v1
116140
if: inputs.install_rust
117141
with:
118142
toolchain: stable
119143

144+
# Use venv in both cases
145+
- name: Install uv
146+
run: |
147+
pip install -U uv
148+
uv venv
149+
120150
- name: Setup environment
121151
shell: bash
122152
run: |
123-
pip uninstall -y doc-builder
153+
source .venv/bin/activate
154+
$PIP_OR_UV uninstall doc-builder
124155
cd doc-builder
125156
git pull origin ${{ inputs.doc_builder_revision }}
126-
pip install .
157+
$PIP_OR_UV install .
127158
cd ..
128159
129160
if [[ -n "${{ inputs.package_path }}" ]]
130161
then
131162
cd ${{ inputs.package_path }}
132-
pip install .[dev]
163+
$PIP_OR_UV install .[dev]
133164
elif [[ "${{ inputs.additional_args }}" != *"--not_python_module"* ]];
134165
then
135166
cd ${{ inputs.package }}
136-
pip install .[dev]
167+
$PIP_OR_UV install .[dev]
137168
fi
138169
cd ..
139170
@@ -148,6 +179,7 @@ jobs:
148179
- name: Convert notebooks to markdown files
149180
if: inputs.convert_notebooks
150181
run: |
182+
source .venv/bin/activate
151183
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
152184
remaining_part=$(echo "${{ env.doc_folder }}" | perl -pe 's|^[^/]+||')
153185
remaining_part=${remaining_part%/}
@@ -160,6 +192,7 @@ jobs:
160192
NODE_OPTIONS: --max-old-space-size=6656
161193
shell: bash
162194
run: |
195+
source .venv/bin/activate
163196
echo "doc_folder has been set to ${{ env.doc_folder }}"
164197
cd doc-builder
165198
args="--build_dir ../build_dir --clean --version pr_${{ inputs.pr_number }} --html ${{ inputs.additional_args }} --repo_owner ${{ inputs.repo_owner }} --repo_name ${{ inputs.package }} --version_tag_suffix=${{ inputs.version_tag_suffix }}"

0 commit comments

Comments
 (0)