Skip to content

Commit a6232fb

Browse files
aviralgarg05klesh
andauthored
fix(ci): replace Poetry runtime setup with uv (#8830)
Co-authored-by: Klesh Wong <klesh@qq.com>
1 parent 78cb8d7 commit a6232fb

9 files changed

Lines changed: 130 additions & 22 deletions

File tree

backend/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ RUN mkdir logs
143143
VOLUME /app/logs
144144

145145
# Setup Python
146-
COPY python/ /app/python/
146+
COPY --chown=devlake:devlake python/ /app/python/
147147
RUN python3 -m pip install --no-cache --upgrade pip setuptools && \
148148
python3 -m pip install --no-cache -r python/requirements.txt && \
149149
python3 -m pip install --upgrade pip
150150

151-
# Setup Python Poetry package manager
152-
RUN curl -sSL https://install.python-poetry.org | python3 - --version 2.2.1
153-
ENV PATH="$PATH:/app/.local/bin"
151+
# Setup Python package manager
152+
RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_UNMANAGED_INSTALL=/app/.local/bin sh
153+
ENV PATH="/app/.local/bin:${PATH}"
154154

155155
# Build Python plugins, make sure the scripts has execute permission
156156
# RUN find /app/python/ -name "*.sh" | xargs -I{} chmod +x {}
@@ -182,4 +182,3 @@ USER devlake
182182
ENTRYPOINT ["/usr/bin/tini", "--"]
183183

184184
CMD ["lake"]
185-

backend/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ unit-test-go:
8484
scripts/unit-test-go.sh
8585

8686
build-pydevlake:
87-
poetry install -C python/pydevlake
87+
sh python/uv.sh sync python/pydevlake
8888

8989
unit-test-python: build-pydevlake
9090
sh python/build.sh python/test &&\

backend/python/plugins/azuredevops/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
#
1818

1919
cd "$(dirname "$0")"
20-
poetry install
20+
sh ../../uv.sh sync .

backend/python/plugins/azuredevops/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
#
1818

1919
cd "$(dirname "$0")"
20-
poetry run python azuredevops/main.py "$@"
20+
sh ../../uv.sh python . azuredevops/main.py "$@"

backend/python/run_tests.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18-
cd "${0%/*}" # make sure we're in the correct dir
18+
SCRIPT_DIR=$(CDPATH= cd -- "${0%/*}" && pwd)
1919

20-
for test_dir in $(find . -type f -name "*_test.py" | xargs dirname | sort -u); do
20+
for test_dir in $(find "$SCRIPT_DIR" -path '*/.venv' -prune -o -type f -name "*_test.py" -print | xargs dirname | sort -u); do
21+
project_dir=$(dirname "$test_dir")
2122
printf "Running Python tests in $test_dir\n"
22-
cd $test_dir
23-
poetry run pytest
23+
sh "$SCRIPT_DIR/uv.sh" sync "$project_dir"
24+
sh "$SCRIPT_DIR/uv.sh" pytest "$project_dir" "$test_dir"
2425
if [ $? != 0 ]; then
2526
exit 1
2627
fi
27-
cd -
28-
done
28+
done

backend/python/test/fakeplugin/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
#
1818

1919
cd "$(dirname "$0")"
20-
poetry install
20+
sh ../../uv.sh sync .

backend/python/test/fakeplugin/run.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@
1616
# limitations under the License.
1717
#
1818

19-
echo sys path $PATH >&2
20-
[ -n "$VIRTUAL_ENV" ] && echo "Using virtualenv: $VIRTUAL_ENV" >&2 && . "$VIRTUAL_ENV/bin/activate"
21-
2219
cd "$(dirname "$0")"
23-
poetry run python fakeplugin/main.py "$@"
20+
sh ../../uv.sh python . fakeplugin/main.py "$@"

backend/python/uv.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/sh
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
set -eu
20+
21+
resolve_path() {
22+
CDPATH= cd -- "$1" && pwd
23+
}
24+
25+
ensure_uv() {
26+
if command -v uv >/dev/null 2>&1; then
27+
return 0
28+
fi
29+
30+
uv_install_dir=${DEVLAKE_UV_INSTALL_DIR:-${HOME:-$(pwd)}/.local/bin}
31+
if [ -x "$uv_install_dir/uv" ]; then
32+
PATH="$uv_install_dir:$PATH"
33+
export PATH
34+
return 0
35+
fi
36+
mkdir -p "$uv_install_dir"
37+
curl -LsSf https://astral.sh/uv/install.sh | env UV_UNMANAGED_INSTALL="$uv_install_dir" sh
38+
PATH="$uv_install_dir:$PATH"
39+
export PATH
40+
}
41+
42+
sync_project() {
43+
project_dir=$(resolve_path "$1")
44+
ensure_uv
45+
cd "$project_dir"
46+
if [ -d .venv ] && [ ! -x .venv/bin/python ]; then
47+
rm -rf .venv
48+
fi
49+
if [ -x .venv/bin/python ] && ! .venv/bin/python -c "import sys" >/dev/null 2>&1; then
50+
rm -rf .venv
51+
fi
52+
if [ ! -x .venv/bin/python ]; then
53+
uv venv --python "${DEVLAKE_PYTHON_VERSION:-3.9}" .venv
54+
fi
55+
uv pip install --python .venv/bin/python -e .
56+
}
57+
58+
ensure_project_python() {
59+
project_dir=$(resolve_path "$1")
60+
if [ ! -x "$project_dir/.venv/bin/python" ]; then
61+
sync_project "$project_dir"
62+
else
63+
ensure_uv
64+
fi
65+
printf '%s/.venv/bin/python\n' "$project_dir"
66+
}
67+
68+
run_python() {
69+
project_dir=$(resolve_path "$1")
70+
shift
71+
python_bin=$(ensure_project_python "$project_dir")
72+
exec "$python_bin" "$@"
73+
}
74+
75+
run_pytest() {
76+
project_dir=$(resolve_path "$1")
77+
shift
78+
ensure_uv
79+
python_bin=$(ensure_project_python "$project_dir")
80+
uv pip install --python "$python_bin" pytest
81+
exec "$python_bin" -m pytest "$@"
82+
}
83+
84+
usage() {
85+
echo "Usage: $0 {sync|python|pytest} <project-dir> [args...]" >&2
86+
exit 1
87+
}
88+
89+
command_name=${1:-}
90+
[ -n "$command_name" ] || usage
91+
shift
92+
93+
case "$command_name" in
94+
sync)
95+
[ $# -eq 1 ] || usage
96+
sync_project "$1"
97+
;;
98+
python)
99+
[ $# -ge 2 ] || usage
100+
project_dir=$1
101+
shift
102+
run_python "$project_dir" "$@"
103+
;;
104+
pytest)
105+
[ $# -ge 1 ] || usage
106+
project_dir=$1
107+
shift
108+
run_pytest "$project_dir" "$@"
109+
;;
110+
*)
111+
usage
112+
;;
113+
esac

devops/docker/lake-builder/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,5 @@ ENV GOPATH=/go
7171
ENV GOROOT=
7272
ENV PATH=${GOPATH}/bin:${PATH}
7373

74-
# Python Poetry package manager
75-
RUN curl -sSL https://install.python-poetry.org | python3 -
76-
RUN ln -sf /root/.local/bin/poetry /usr/local/bin
74+
# Python package manager
75+
RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_UNMANAGED_INSTALL=/usr/local/bin sh

0 commit comments

Comments
 (0)