This is an automated email from the ASF dual-hosted git repository. yzheng pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push: new 3650c68d2 Package polaris client as python package (#2049) 3650c68d2 is described below commit 3650c68d2d797d8d1fa49bcd54172646305e8c7f Author: Yong Zheng <yongzheng0...@gmail.com> AuthorDate: Sun Jul 20 23:47:42 2025 -0500 Package polaris client as python package (#2049) * Package polaris client as python package * Package polaris client as python package * Change owner to spark when copying files from local into Dockerfile --- client/python/cli/polaris_cli.py | 6 +++++- client/python/pyproject.toml | 11 ++++++++++- polaris | 12 ++++++++---- regtests/Dockerfile | 14 ++++++++------ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/client/python/cli/polaris_cli.py b/client/python/cli/polaris_cli.py index 83341ada4..3711bdb9e 100644 --- a/client/python/cli/polaris_cli.py +++ b/client/python/cli/polaris_cli.py @@ -191,5 +191,9 @@ class PolarisCli: return lambda: ApiClient(config) -if __name__ == "__main__": +def main(): PolarisCli.execute() + + +if __name__ == "__main__": + main() diff --git a/client/python/pyproject.toml b/client/python/pyproject.toml index 538efe969..b8b1d2961 100644 --- a/client/python/pyproject.toml +++ b/client/python/pyproject.toml @@ -41,9 +41,18 @@ dependencies = [ homepage = "https://polaris.apache.org/" repository = "https://github.com/apache/polaris/" +[project.scripts] +polaris = "cli.polaris_cli:main" + [tool.poetry] requires-poetry = "==2.1.3" -packages = [{ include = "polaris" }] +packages = [ + { include = "polaris" }, + { include = "cli" } +] +include = [ + "polaris/**" +] [tool.poetry.group.test.dependencies] pytest = ">= 7.2.1" diff --git a/polaris b/polaris index a8fb55837..1b072a6c2 100755 --- a/polaris +++ b/polaris @@ -51,8 +51,7 @@ if [ ! -d "${dir}"/polaris-venv ] || [ "$repair" == true ]; then pip install --upgrade pip pip install --upgrade -r regtests/requirements.txt - cp "${dir}"/client/python/pyproject.toml "${dir}" - pushd "$dir" && poetry install ; popd + (cd "${dir}/client/python" && poetry install) deactivate @@ -63,5 +62,10 @@ if [ ! -d "${dir}"/polaris-venv ] || [ "$repair" == true ]; then fi fi -cd "$dir" -env PYTHONPATH=client/python SCRIPT_DIR="$dir" "${dir}"/polaris-venv/bin/python3 client/python/cli/polaris_cli.py "$@" +# Check if the correct virtual environment is already active, if not, activate it. +if [ -z "$VIRTUAL_ENV" ] || [ "$(realpath "$VIRTUAL_ENV")" != "$(realpath "${dir}/polaris-venv")" ]; then + source "${dir}/polaris-venv/bin/activate" +fi + +export SCRIPT_DIR="${dir}" +exec polaris "$@" diff --git a/regtests/Dockerfile b/regtests/Dockerfile index 85f9cee5a..8e19979e3 100644 --- a/regtests/Dockerfile +++ b/regtests/Dockerfile @@ -37,17 +37,19 @@ ENV PYTHONPATH="${SPARK_HOME}/python/:${SPARK_HOME}/python/lib/py4j-0.10.9.7-src # Copy and run setup.sh separately so that test sources can change, but the setup script run is still cached WORKDIR /home/spark/polaris -COPY ./regtests/setup.sh /home/spark/polaris/regtests/setup.sh -COPY ./regtests/pyspark-setup.sh /home/spark/polaris/regtests/pyspark-setup.sh -COPY ./client/python /home/spark/polaris/client/python -COPY ./polaris /home/spark/polaris/polaris -COPY ./regtests/requirements.txt /tmp/ +COPY --chown=spark ./regtests/setup.sh /home/spark/polaris/regtests/setup.sh +COPY --chown=spark ./regtests/pyspark-setup.sh /home/spark/polaris/regtests/pyspark-setup.sh +COPY --chown=spark ./client/python /home/spark/polaris/client/python +COPY --chown=spark ./polaris /home/spark/polaris/polaris +COPY --chown=spark ./regtests/requirements.txt /tmp/ RUN python3 -m venv /home/spark/polaris/polaris-venv && \ . /home/spark/polaris/polaris-venv/bin/activate && \ pip install -r /tmp/requirements.txt && \ + cd /home/spark/polaris/client/python && \ + poetry install && \ deactivate \ - ./regtests/setup.sh + /home/spark/polaris/regtests/setup.sh COPY --chown=spark ./regtests /home/spark/polaris/regtests