Skip to content

Commit eda7074

Browse files
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
1 parent 5983c81 commit eda7074

File tree

5 files changed

+91
-121
lines changed

5 files changed

+91
-121
lines changed

.github/workflows/python-client.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ jobs:
5959
python-version: ${{ matrix.python-version }}
6060

6161
- name: Lint
62-
working-directory: client/python
6362
run: |
64-
make lint
63+
make client-lint
6564
6665
- name: Generated Client Tests
67-
working-directory: client/python
6866
run: |
69-
make test-client
67+
make client-unit-test
7068
7169
- name: Image build
7270
run: |
@@ -76,6 +74,5 @@ jobs:
7674
-Dquarkus.container-image.build=true
7775
7876
- name: Integration Tests
79-
working-directory: client/python
8077
run: |
81-
make test-integration
78+
make client-integration-test

Makefile

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ DOCKER ?= docker
2626
MINIKUBE_PROFILE ?= minikube
2727
DEPENDENCIES ?= ct helm helm-docs java21 git
2828
OPTIONAL_DEPENDENCIES := jq kubectl minikube
29+
VENV_DIR := .venv
30+
PYTHON_CLIENT_DIR := client/python
31+
ACTIVATE_AND_CD = source $(VENV_DIR)/bin/activate && cd $(PYTHON_CLIENT_DIR)
2932

3033
## Version information
3134
BUILD_VERSION := $(shell cat version.txt)
3235
GIT_COMMIT := $(shell git rev-parse HEAD)
36+
POETRY_VERSION := $(shell cat client/python/pyproject.toml | grep requires-poetry | sed 's/requires-poetry *= *"\(.*\)"/\1/')
3337

3438
##@ General
3539

@@ -41,6 +45,7 @@ help: ## Display this help
4145
version: ## Display version information
4246
@echo "Build version: ${BUILD_VERSION}"
4347
@echo "Git commit: ${GIT_COMMIT}"
48+
@echo "Poetry version: ${POETRY_VERSION}"
4449

4550
##@ Polaris Build
4651

@@ -99,6 +104,79 @@ spotless-apply: check-dependencies ## Apply code formatting using Spotless Gradl
99104
@./gradlew spotlessApply
100105
@echo "--- Spotless formatting applied ---"
101106

107+
##@ Polaris Client
108+
109+
# Target to create the virtual environment directory
110+
$(VENV_DIR):
111+
@echo "Setting up Python virtual environment at $(VENV_DIR)..."
112+
@python3 -m venv $(VENV_DIR)
113+
@echo "Virtual environment created."
114+
115+
.PHONY: client-install-dependencies
116+
client-install-dependencies: $(VENV_DIR)
117+
@echo "Installing Poetry and project dependencies into $(VENV_DIR)..."
118+
@$(VENV_DIR)/bin/pip install --upgrade pip
119+
@if [ ! -f "$(VENV_DIR)/bin/poetry" ]; then \
120+
$(VENV_DIR)/bin/pip install --upgrade "poetry$(POETRY_VERSION)"; \
121+
fi
122+
@$(ACTIVATE_AND_CD) && poetry install --all-extras
123+
@echo "Poetry and dependencies installed."
124+
125+
.PHONY: client-setup-env
126+
client-setup-env: $(VENV_DIR) client-install-dependencies
127+
128+
.PHONY: client-lint
129+
client-lint: client-setup-env ## Run linting checks for Polaris client
130+
@echo "--- Running client linting checks ---"
131+
@$(ACTIVATE_AND_CD) && poetry run pre-commit run --files integration_tests/* python/cli/*
132+
@echo "--- Client linting checks complete ---"
133+
134+
.PHONY: client-regenerate
135+
client-regenerate: client-setup-env ## Regenerate the client code
136+
@echo "--- Regenerating client code ---"
137+
@client/templates/regenerate.sh
138+
@echo "--- Client code regeneration complete ---"
139+
140+
.PHONY: client-unit-test
141+
client-unit-test: client-setup-env ## Run client unit tests
142+
@echo "--- Running client unit tests ---"
143+
@$(ACTIVATE_AND_CD) && SCRIPT_DIR="non-existing-mock-directory" poetry run pytest test/
144+
@echo "--- Client unit tests complete ---"
145+
146+
.PHONY: client-integration-test
147+
client-integration-test: client-setup-env ## Run client integration tests
148+
@echo "--- Starting client integration tests ---"
149+
@echo "Ensuring Docker Compose services are stopped and removed..."
150+
@$(CONTAINER_TOOL) compose -f $(PYTHON_CLIENT_DIR)/docker-compose.yml kill || true # `|| true` prevents make from failing if containers don't exist
151+
@$(CONTAINER_TOOL) compose -f $(PYTHON_CLIENT_DIR)/docker-compose.yml rm -f || true # `|| true` prevents make from failing if containers don't exist
152+
@echo "Bringing up Docker Compose services in detached mode..."
153+
@$(CONTAINER_TOOL) compose -f $(PYTHON_CLIENT_DIR)/docker-compose.yml up -d
154+
@echo "Waiting for Polaris HTTP health check to pass..."
155+
@until curl -s -f http://localhost:8182/q/health > /dev/null; do \
156+
echo "Still waiting for HTTP 200 from /q/health (sleeping 2s)..."; \
157+
sleep 2; \
158+
done
159+
@echo "Polaris is healthy. Starting integration tests..."
160+
@$(ACTIVATE_AND_CD) && poetry run pytest integration_tests/
161+
@echo "--- Client integration tests complete ---"
162+
@echo "Tearing down Docker Compose services..."
163+
@$(CONTAINER_TOOL) compose -f $(PYTHON_CLIENT_DIR)/docker-compose.yml down || true # Ensure teardown even if tests fail
164+
165+
.PHONY: client-cleanup
166+
client-cleanup: ## Cleanup virtual environment and Python cache files
167+
@echo "--- Cleaning up virtual environment and Python cache files ---"
168+
@echo "Attempting to remove virtual environment directory: $(VENV_DIR)..."
169+
@if [ -n "$(VENV_DIR)" ] && [ -d "$(VENV_DIR)" ]; then \
170+
rm -rf "$(VENV_DIR)"; \
171+
echo "Virtual environment removed."; \
172+
else \
173+
echo "Virtual environment directory '$(VENV_DIR)' not found or VENV_DIR is empty. No action taken."; \
174+
fi
175+
@echo "Cleaning up Python cache files..."
176+
@find $(PYTHON_CLIENT_DIR) -type f -name "*.pyc" -delete
177+
@find $(PYTHON_CLIENT_DIR) -type d -name "__pycache__" -delete
178+
@echo "--- Virtual environment and Python cache cleanup complete ---"
179+
102180
##@ Helm
103181

104182
helm-doc-generate: DEPENDENCIES := helm-docs
@@ -178,7 +256,7 @@ minikube-cleanup: check-dependencies ## Cleanup the Minikube cluster
178256
##@ Pre-commit
179257

180258
.PHONY: pre-commit
181-
pre-commit: spotless-apply helm-doc-generate ## Run tasks for pre-commit
259+
pre-commit: spotless-apply helm-doc-generate client-lint ## Run tasks for pre-commit
182260

183261
##@ Dependencies
184262

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ To streamline the developer experience, especially for common setup and build ta
8787
- Managing development clusters: e.g., `make minikube-start-cluster, make minikube-cleanup`
8888
- Automating Helm tasks: e.g., `make helm-doc-generate, make helm-unittest`
8989
- Handling dependencies: e.g., `make install-dependencies-brew`
90+
- Managing client operations: e.g., `make client-lint, make client-regenerate`
9091

9192
To see available commands:
9293
```bash

client/python/Makefile

Lines changed: 0 additions & 107 deletions
This file was deleted.

client/python/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@ The Apache Polaris Python package provides a client for interacting with the Apa
2525
### Prerequisites
2626
- Python 3.9 or later
2727
- poetry >= 2.1
28+
- Docker
2829

2930
### Installation
30-
First we need to generate the OpenAPI client code from the OpenAPI specification.
31-
```
32-
make regenerate-client
31+
First we need to generate the OpenAPI client code from the OpenAPI specification by running the following command **from the project root directory**:
32+
```bash
33+
make client-regenerate
3334
```
3435

3536
### Auto-formatting and Linting
36-
```
37-
make lint
37+
```bash
38+
make client-lint
3839
```
3940

4041
### Running Integration Tests
41-
```
42-
make test-integration
42+
```bash
43+
make client-integration-test
4344
```

0 commit comments

Comments
 (0)