From 3a7f93e41f4b45010d15ed80cb7eabfeff31335e Mon Sep 17 00:00:00 2001 From: John Bampton Date: Sun, 30 Nov 2025 17:48:02 +1000 Subject: [PATCH 1/4] [GH-2503] Switch to `prek` using `uv` --- .github/workflows/pre-commit.yml | 43 ++++++++++++++-------- .pre-commit-config.yaml | 12 +++--- Makefile | 63 +++++++++++++++++--------------- pyproject.toml | 3 ++ 4 files changed, 70 insertions(+), 51 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 6faa88ffc5..5a04699887 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -26,28 +26,39 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} +env: + UV_VERSION: '0.7.12' + jobs: pre-commit: - name: Run pre-commit # https://pre-commit.com/ runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: + - '3.10' steps: - - name: 'Checkout ${{ github.ref }} ( ${{ github.sha }} )' - uses: actions/checkout@v5 - - uses: actions/setup-python@v6 # https://www.python.org/ + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + with: + persist-credentials: false + - uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 + with: + python-version: ${{ matrix.python-version }} + - name: Install uv + uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 with: - python-version: '3.10' # Version range or exact version of a Python version to use, using SemVer's version range syntax - architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified - - name: Install dependencies # https://pip.pypa.io/en/stable/ - run: | - python -m pip install --upgrade pip - pip install pre-commit - - name: set PY - run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV - - uses: actions/cache@v4 + version: ${{ env.UV_VERSION }} + + - name: Install dependencies + run: uv sync --all-groups + + - name: Cache pre-commit data + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ~/.cache/pre-commit - key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} + key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + - name: Run pre-commit - run: pre-commit run --color=always --all-files + run: uv run pre-commit run --show-diff-on-failure --color=always --all-files - name: Run manual pre-commit hooks - run: pre-commit run --color=always --all-files --hook-stage manual + run: uv run pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8242431ae5..4d8fec29b2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -286,12 +286,12 @@ repos: description: check spelling with codespell args: [--ignore-words=.github/linters/codespell.txt] exclude: ^docs/image|^spark/common/src/test/resources|^docs/usecases|^tools/maven/scalafmt|osmpbf/build|^docker/zeppelin|^docs-overrides - - repo: https://github.com/gitleaks/gitleaks - rev: v8.28.0 - hooks: - - id: gitleaks - name: run gitleaks - description: check for secrets with gitleaks + # - repo: https://github.com/gitleaks/gitleaks + # rev: v8.28.0 + # hooks: + # - id: gitleaks + # name: run gitleaks + # description: check for secrets with gitleaks - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 hooks: diff --git a/Makefile b/Makefile index 972e17d748..dfa37182e8 100644 --- a/Makefile +++ b/Makefile @@ -15,36 +15,29 @@ # specific language governing permissions and limitations # under the License. -PYTHON := $(shell command -v python || command -v python3 || echo python) -PIP := $(PYTHON) -m pip +.PHONY: check check-from-ref check-install check-last check-stage clean docsbuild docsinstall install run-docs \ + sync-no-dev update update-deps -.PHONY: check checkinstall checkupdate install docsinstall docsbuild clean test +check: install ## run all pre-commit checks + prek run --all-files -check: - @echo "Running pre-commit checks..." - @if ! command -v pre-commit >/dev/null 2>&1; then \ - echo "Error: pre-commit is not installed. Run 'make checkinstall' first."; \ - exit 1; \ - fi - pre-commit run --all-files +check-from-ref: install ## will run prek checks for all changes since you branched off + prek run --from-ref main -checkinstall: - @echo "Installing pre-commit..." - @if ! command -v pre-commit >/dev/null 2>&1; then \ - $(PIP) install pre-commit; \ - fi - pre-commit install +check-install: ## checks for a uv installation + @command -v uv >/dev/null 2>&1 || (echo 'uv not found, install via: curl -LsSf https://astral.sh/uv/install.sh | sh' && exit 1) -checkupdate: checkinstall - @echo "Updating pre-commit hooks..." - pre-commit autoupdate +check-last: install ## will run pre-commit checks on last commit only + prek --last-commit -install: checkinstall +check-stage: install ## runs check on currently staged changes + prek -docsinstall: - @echo "Installing documentation dependencies..." - @command -v uv >/dev/null 2>&1 || (echo 'uv not found, install via: curl -LsSf https://astral.sh/uv/install.sh | sh' && exit 1) - uv sync --group docs +clean: + @echo "Cleaning up generated files... (TODO)" + rm -rf __pycache__ + rm -rf .mypy_cache + rm -rf .pytest_cache docsbuild: docsinstall @echo "Building documentation..." @@ -52,12 +45,24 @@ docsbuild: docsinstall uv run mike deploy --update-aliases latest-snapshot -b website -p uv run mike serve -clean: - @echo "Cleaning up generated files... (TODO)" - rm -rf __pycache__ - rm -rf .mypy_cache - rm -rf .pytest_cache +docsinstall: check-install + @echo "Installing documentation dependencies..." + uv sync --group docs + +install: check-install ## Sync all dependencies (including development) using uv + uv sync --all-groups run-docs: docker build -f docker/docs/Dockerfile -t mkdocs-sedona . docker run --rm -it -p 8000:8000 -v ${PWD}:/docs mkdocs-sedona + +sync-no-dev: check-install ## Sync non-development dependencies using uv + uv sync --no-dev + +update: install + prek auto-update + +update-deps: check-install ## Update pre-commit hooks and dependency locks + prek auto-update || : + uv lock --upgrade + uv sync --all-groups diff --git a/pyproject.toml b/pyproject.toml index 8b0c6be2f5..9b95d1e770 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,3 +50,6 @@ docs = [ "sphinx_rtd_theme", "sphinx-autobuild", ] +dev = [ + "prek>=0.2.19" +] From ec1431d40a196435d3ce5ff110cc504c9f334f01 Mon Sep 17 00:00:00 2001 From: John Bampton Date: Sun, 30 Nov 2025 18:02:10 +1000 Subject: [PATCH 2/4] Fix up --- .github/workflows/pre-commit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5a04699887..029e7b49f7 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -59,6 +59,6 @@ jobs: key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} - name: Run pre-commit - run: uv run pre-commit run --show-diff-on-failure --color=always --all-files + run: uv run prek run --show-diff-on-failure --color=always --all-files - name: Run manual pre-commit hooks - run: uv run pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual + run: uv run prek run --show-diff-on-failure --color=always --all-files --hook-stage manual From 629823c2f88db795eef70304ab28bd970b4d2a1d Mon Sep 17 00:00:00 2001 From: John Bampton Date: Sun, 30 Nov 2025 18:27:59 +1000 Subject: [PATCH 3/4] Try fix codeql; install uv --- .github/workflows/codeql.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 32c313e872..1b8c46faad 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -28,6 +28,9 @@ permissions: contents: read security-events: write +env: + UV_VERSION: '0.7.12' + jobs: codeql: name: CodeQL @@ -42,6 +45,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v5 + - name: Install uv + uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 + with: + version: ${{ env.UV_VERSION }} + - name: Initialize CodeQL uses: github/codeql-action/init@v4 with: From 7854f0fcaeedfa594672022e1810f844806141b1 Mon Sep 17 00:00:00 2001 From: John Bampton Date: Sun, 30 Nov 2025 18:35:45 +1000 Subject: [PATCH 4/4] Fix up try build mode none --- .github/workflows/codeql.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 1b8c46faad..82872a0d68 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -28,9 +28,6 @@ permissions: contents: read security-events: write -env: - UV_VERSION: '0.7.12' - jobs: codeql: name: CodeQL @@ -45,18 +42,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v5 - - name: Install uv - uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 - with: - version: ${{ env.UV_VERSION }} - - name: Initialize CodeQL uses: github/codeql-action/init@v4 with: languages: ${{ matrix.language }} - - - name: Autobuild - uses: github/codeql-action/autobuild@v4 + build-mode: none - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v4