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 eda70740a Move python client Makefile into the root level one (#2140) eda70740a is described below commit eda70740a4e327889f1ac38295d23c8947d87703 Author: Yong Zheng <yongzheng0...@gmail.com> AuthorDate: Thu Aug 7 21:28:19 2025 -0500 Move python client Makefile into the root level one (#2140) * Move python client Makefile into the root level one * Update workflow * add client-lint to pre-commit * Update README.md to include client --- .github/workflows/python-client.yml | 9 +-- Makefile | 80 ++++++++++++++++++++++++++- README.md | 1 + client/python/Makefile | 107 ------------------------------------ client/python/README.md | 15 ++--- 5 files changed, 91 insertions(+), 121 deletions(-) diff --git a/.github/workflows/python-client.yml b/.github/workflows/python-client.yml index 7586e3b18..83b1e26bc 100644 --- a/.github/workflows/python-client.yml +++ b/.github/workflows/python-client.yml @@ -59,14 +59,12 @@ jobs: python-version: ${{ matrix.python-version }} - name: Lint - working-directory: client/python run: | - make lint + make client-lint - name: Generated Client Tests - working-directory: client/python run: | - make test-client + make client-unit-test - name: Image build run: | @@ -76,6 +74,5 @@ jobs: -Dquarkus.container-image.build=true - name: Integration Tests - working-directory: client/python run: | - make test-integration + make client-integration-test diff --git a/Makefile b/Makefile index 8d064c04a..5ca20c749 100644 --- a/Makefile +++ b/Makefile @@ -26,10 +26,14 @@ DOCKER ?= docker MINIKUBE_PROFILE ?= minikube DEPENDENCIES ?= ct helm helm-docs java21 git OPTIONAL_DEPENDENCIES := jq kubectl minikube +VENV_DIR := .venv +PYTHON_CLIENT_DIR := client/python +ACTIVATE_AND_CD = source $(VENV_DIR)/bin/activate && cd $(PYTHON_CLIENT_DIR) ## Version information BUILD_VERSION := $(shell cat version.txt) GIT_COMMIT := $(shell git rev-parse HEAD) +POETRY_VERSION := $(shell cat client/python/pyproject.toml | grep requires-poetry | sed 's/requires-poetry *= *"\(.*\)"/\1/') ##@ General @@ -41,6 +45,7 @@ help: ## Display this help version: ## Display version information @echo "Build version: ${BUILD_VERSION}" @echo "Git commit: ${GIT_COMMIT}" + @echo "Poetry version: ${POETRY_VERSION}" ##@ Polaris Build @@ -99,6 +104,79 @@ spotless-apply: check-dependencies ## Apply code formatting using Spotless Gradl @./gradlew spotlessApply @echo "--- Spotless formatting applied ---" +##@ Polaris Client + +# Target to create the virtual environment directory +$(VENV_DIR): + @echo "Setting up Python virtual environment at $(VENV_DIR)..." + @python3 -m venv $(VENV_DIR) + @echo "Virtual environment created." + +.PHONY: client-install-dependencies +client-install-dependencies: $(VENV_DIR) + @echo "Installing Poetry and project dependencies into $(VENV_DIR)..." + @$(VENV_DIR)/bin/pip install --upgrade pip + @if [ ! -f "$(VENV_DIR)/bin/poetry" ]; then \ + $(VENV_DIR)/bin/pip install --upgrade "poetry$(POETRY_VERSION)"; \ + fi + @$(ACTIVATE_AND_CD) && poetry install --all-extras + @echo "Poetry and dependencies installed." + +.PHONY: client-setup-env +client-setup-env: $(VENV_DIR) client-install-dependencies + +.PHONY: client-lint +client-lint: client-setup-env ## Run linting checks for Polaris client + @echo "--- Running client linting checks ---" + @$(ACTIVATE_AND_CD) && poetry run pre-commit run --files integration_tests/* python/cli/* + @echo "--- Client linting checks complete ---" + +.PHONY: client-regenerate +client-regenerate: client-setup-env ## Regenerate the client code + @echo "--- Regenerating client code ---" + @client/templates/regenerate.sh + @echo "--- Client code regeneration complete ---" + +.PHONY: client-unit-test +client-unit-test: client-setup-env ## Run client unit tests + @echo "--- Running client unit tests ---" + @$(ACTIVATE_AND_CD) && SCRIPT_DIR="non-existing-mock-directory" poetry run pytest test/ + @echo "--- Client unit tests complete ---" + +.PHONY: client-integration-test +client-integration-test: client-setup-env ## Run client integration tests + @echo "--- Starting client integration tests ---" + @echo "Ensuring Docker Compose services are stopped and removed..." + @$(CONTAINER_TOOL) compose -f $(PYTHON_CLIENT_DIR)/docker-compose.yml kill || true # `|| true` prevents make from failing if containers don't exist + @$(CONTAINER_TOOL) compose -f $(PYTHON_CLIENT_DIR)/docker-compose.yml rm -f || true # `|| true` prevents make from failing if containers don't exist + @echo "Bringing up Docker Compose services in detached mode..." + @$(CONTAINER_TOOL) compose -f $(PYTHON_CLIENT_DIR)/docker-compose.yml up -d + @echo "Waiting for Polaris HTTP health check to pass..." + @until curl -s -f http://localhost:8182/q/health > /dev/null; do \ + echo "Still waiting for HTTP 200 from /q/health (sleeping 2s)..."; \ + sleep 2; \ + done + @echo "Polaris is healthy. Starting integration tests..." + @$(ACTIVATE_AND_CD) && poetry run pytest integration_tests/ + @echo "--- Client integration tests complete ---" + @echo "Tearing down Docker Compose services..." + @$(CONTAINER_TOOL) compose -f $(PYTHON_CLIENT_DIR)/docker-compose.yml down || true # Ensure teardown even if tests fail + +.PHONY: client-cleanup +client-cleanup: ## Cleanup virtual environment and Python cache files + @echo "--- Cleaning up virtual environment and Python cache files ---" + @echo "Attempting to remove virtual environment directory: $(VENV_DIR)..." + @if [ -n "$(VENV_DIR)" ] && [ -d "$(VENV_DIR)" ]; then \ + rm -rf "$(VENV_DIR)"; \ + echo "Virtual environment removed."; \ + else \ + echo "Virtual environment directory '$(VENV_DIR)' not found or VENV_DIR is empty. No action taken."; \ + fi + @echo "Cleaning up Python cache files..." + @find $(PYTHON_CLIENT_DIR) -type f -name "*.pyc" -delete + @find $(PYTHON_CLIENT_DIR) -type d -name "__pycache__" -delete + @echo "--- Virtual environment and Python cache cleanup complete ---" + ##@ Helm helm-doc-generate: DEPENDENCIES := helm-docs @@ -178,7 +256,7 @@ minikube-cleanup: check-dependencies ## Cleanup the Minikube cluster ##@ Pre-commit .PHONY: pre-commit -pre-commit: spotless-apply helm-doc-generate ## Run tasks for pre-commit +pre-commit: spotless-apply helm-doc-generate client-lint ## Run tasks for pre-commit ##@ Dependencies diff --git a/README.md b/README.md index a364889ad..3446ee64f 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ To streamline the developer experience, especially for common setup and build ta - Managing development clusters: e.g., `make minikube-start-cluster, make minikube-cleanup` - Automating Helm tasks: e.g., `make helm-doc-generate, make helm-unittest` - Handling dependencies: e.g., `make install-dependencies-brew` + - Managing client operations: e.g., `make client-lint, make client-regenerate` To see available commands: ```bash diff --git a/client/python/Makefile b/client/python/Makefile deleted file mode 100644 index 9d222fa39..000000000 --- a/client/python/Makefile +++ /dev/null @@ -1,107 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -# .SILENT: - -# Configures the shell for recipes to use bash, enabling bash commands and ensuring -# that recipes exit on any command failure (including within pipes). -SHELL = /usr/bin/env bash -o pipefail -.SHELLFLAGS = -ec - -# Version information -VERSION ?= $(shell cat pyproject.toml | grep version | sed 's/version *= *"\(.*\)"/\1/') -BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%S%:z") -GIT_COMMIT := $(shell git rev-parse HEAD) -POETRY_VERSION := $(shell cat pyproject.toml | grep requires-poetry | sed 's/requires-poetry *= *"\(.*\)"/\1/') - -# Variables -VENV_DIR := .venv - -.PHONY: help -help: ## Display this help. - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-30s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) - -.PHONY: version -version: ## Print version information. - @echo "Apache Polaris version: ${VERSION}" - @echo "Build date: ${BUILD_DATE}" - @echo "Git commit: ${GIT_COMMIT}" - @echo "Poetry version: ${POETRY_VERSION}" - -# Target to create the virtual environment directory -$(VENV_DIR): - @echo "Setting up Python virtual environment at $(VENV_DIR)..." - python3 -m venv $(VENV_DIR) - @echo "Virtual environment created." - -.PHONY: setup-env -setup-env: $(VENV_DIR) install-poetry-deps - -.PHONY: install-poetry-deps -install-poetry-deps: - @echo "Installing Poetry and project dependencies into $(VENV_DIR)..." - # Ensure pip is up-to-date within the venv - $(VENV_DIR)/bin/pip install --upgrade pip - # Install poetry if not already present - @if [ ! -f "$(VENV_DIR)/bin/poetry" ]; then \ - $(VENV_DIR)/bin/pip install --upgrade "poetry${POETRY_VERSION}"; \ - fi - # Install needed dependencies using poetry - $(VENV_DIR)/bin/poetry install --all-extras - @echo "Poetry and dependencies installed." - -.PHONY: regenerate-client -regenerate-client: ## Regenerate the client code - ../templates/regenerate.sh - -.PHONY: test-client -test-client: setup-env ## Run client tests - SCRIPT_DIR="non-existing-mock-directory" $(VENV_DIR)/bin/poetry run pytest test/ - -.PHONY: test-integration -test-integration: setup-env ## Run integration tests - docker compose -f docker-compose.yml kill - docker compose -f docker-compose.yml rm -f - docker compose -f docker-compose.yml up -d - @echo "Waiting for Polaris HTTP health check to pass..." - @until curl -s -f http://localhost:8182/q/health > /dev/null; do \ - sleep 2; \ - echo "Still waiting for HTTP 200 from /q/health..."; \ - done - @echo "Polaris is healthy. Starting integration tests..." - $(VENV_DIR)/bin/poetry run pytest integration_tests/ ${PYTEST_ARGS} - -.PHONY: lint -lint: setup-env ## Run linting checks - $(VENV_DIR)/bin/poetry run pre-commit run --files integration_tests/* cli/* - -.PHONY: clean-venv -clean-venv: - @echo "Attempting to remove virtual environment directory: $(VENV_DIR)..." - # SAFETY CHECK: Ensure VENV_DIR is not empty and exists before attempting to remove - @if [ -n "$(VENV_DIR)" ] && [ -d "$(VENV_DIR)" ]; then \ - rm -rf "$(VENV_DIR)"; \ - echo "Virtual environment removed."; \ - else \ - echo "Virtual environment directory '$(VENV_DIR)' not found or VENV_DIR is empty. No action taken."; \ - fi - -.PHONY: clean -clean: clean-venv ## Cleanup - @echo "Cleaning up Python cache files..." - find . -type f -name "*.pyc" -delete - find . -type d -name "__pycache__" -delete diff --git a/client/python/README.md b/client/python/README.md index 4489452a1..b57e85bf9 100644 --- a/client/python/README.md +++ b/client/python/README.md @@ -25,19 +25,20 @@ The Apache Polaris Python package provides a client for interacting with the Apa ### Prerequisites - Python 3.9 or later - poetry >= 2.1 +- Docker ### Installation -First we need to generate the OpenAPI client code from the OpenAPI specification. -``` -make regenerate-client +First we need to generate the OpenAPI client code from the OpenAPI specification by running the following command **from the project root directory**: +```bash +make client-regenerate ``` ### Auto-formatting and Linting -``` -make lint +```bash +make client-lint ``` ### Running Integration Tests -``` -make test-integration +```bash +make client-integration-test ```