Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ jobs:
env:
# Shared env variables for all the tests
UV_RESOLUTION: "${{ matrix.resolution }}"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: stable
# We use this to install `buf`, and the `buf` version is controlled by the Makefile.
cache-dependency-path: Makefile
- uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
python-version: ${{ matrix.python-version }}
- run: make install
- run: make test
- run: make conformance

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
Expand All @@ -36,13 +52,6 @@ jobs:
- run: make lint
- run: make format
# When running with matrix.resolution == lowest-direct, we expect uv.lock to change, but we don't want that file checked in.
- if: matrix.resolution == 'highest'
run: make checkgenerate
env:
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
- run: make test
env:
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
- run: make conformance
- run: make checkgenerate
env:
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ __pycache__

# VS Code configuration
/.vscode/
.envrc
54 changes: 19 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ SHELL := bash
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
export PATH := $(BIN):$(PATH)
export GOBIN := $(abspath $(BIN))
export PYTHONPATH ?= gen
BUF_VERSION := 1.69.0
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While there is a slight issue in having this version and the buf version in pyproject.toml, the version of the license header tool isn't that important, and the correct fix will be in the future, using the Python version of the tool we will share among Buf's repos

CONFORMANCE_ARGS ?= --strict_message --expected_failures=test/conformance/nonconforming.yaml --timeout 10s
ADD_LICENSE_HEADER := $(BIN)/license-header \
ADD_LICENSE_HEADER := go run github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v${BUF_VERSION} \
--ignore .github \
--ignore buf.yaml \
--ignore buf.gen.yaml \
Expand Down Expand Up @@ -47,39 +44,38 @@ clean: ## Delete intermediate build artifacts
@echo $(CEL_SPEC_VERSION)

.PHONY: generate
generate: $(BIN)/buf $(BIN)/license-header upstream ## Regenerate code and license headers
rm -rf gen
$(BIN)/buf generate $(PROTOVALIDATE_PROTO_PATH)
$(BIN)/buf generate $(PROTOVALIDATE_TESTING_PROTO_PATH)
$(BIN)/buf generate buf.build/google/cel-spec:$(CEL_SPEC_VERSION) --exclude-path cel/expr/conformance/proto2 --exclude-path cel/expr/conformance/proto3
$(BIN)/buf generate
$(ADD_LICENSE_HEADER)
generate: ## Regenerate code and license headers
cd packages/protovalidate-proto && \
rm -rf src && mkdir -p src/buf/validate && touch src/buf/validate/__init__.py && \
uv run -- buf generate $(PROTOVALIDATE_PROTO_PATH) && \
uv run -- buf generate $(PROTOVALIDATE_TESTING_PROTO_PATH)

cd test && \
rm -rf gen && \
uv run -- buf generate buf.build/google/cel-spec:$(CEL_SPEC_VERSION) --exclude-path cel/expr/conformance/proto2 --exclude-path cel/expr/conformance/proto3 && \
uv run -- buf generate

.PHONY: upstream
upstream: $(BIN)/buf
rm -rf upstream
$(BIN)/buf export $(PROTOVALIDATE_PROTO_PATH) -o upstream/proto
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timostamm I have removed this, looking at #409 I couldn't find a particular reason for vendoring in the proto file itself with this line. We have $(BIN)/buf generate $(PROTOVALIDATE_PROTO_PATH) in the generate script, and then run $(BIN)/buf generate below it. The later does use this proto file to effectively invalidate the former, but it seems enough to use the form that automatically gets the proto from BSR or GitHub without this? Let me know if you remember there was any other reason for keeping this here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we need for development:

  • Generate validate.proto for the validator implementation - proto/protovalidate/ in upstream
  • Generate conformance test protos - proto/protovalidate-testing/ in upstream
  • Run the Go conformance test harness - tools/protovalidate-conformance/ in upstream
  • Local test protos to cover implementation-specific edge cases - proto/tests in this repository - importing upstream's validate.proto

Because upstream's Protobuf definitions are not pushed to the BSR until release, we need the ability to reference arbitrary upstream Git commits. This enables testing changes to validate.proto in implementations before cutting an upstream release - which would be immediately available to users, but not supported by implementations yet. In practice, we need to have all implementations ready to release when we are cutting an upstream release.

If you pull an upstream change in here, it is very possible that you encounter a conformance test failure and need to investigate the problem further. You'll need to add local test protos, and sometimes you may want to modify validate.proto with a patch that you expect will fix the problem, but want to verify locally before going through an upstream commit.

The setup in protovalidate-es checks all boxes. I'm not sure that the setup here ever did. Are there any gaps in the new setup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context!

you may want to modify validate.proto with a patch that you expect will fix the problem, but want to verify locally before going through an upstream commit.

This makes sense. This means probably the step that generated code with upstream before downloading locally and generating again had both a redundant generation step and possibly a frustrating overwrite of local changes when not desired. Will tweak to resolve these.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a "may", and some complications with that are acceptable. But keep in mind that local test protos cannot import from a Git commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I have filed

#474

to track this. I would like to fix forward (technically refix) since many things will open up when migrating off of Makefile and in the meantime, the repo not being easily openable in an IDE should be fixed first. I'll address it soon.

$(ADD_LICENSE_HEADER)

.PHONY: format
format: install $(BIN)/buf $(BIN)/license-header ## Format code
format: install ## Format code
$(ADD_LICENSE_HEADER)
buf format --write .
uv run -- buf format --write .
uv run -- ruff format protovalidate test
uv run -- ruff check --fix protovalidate test
uv run -- tombi format

.PHONY: test
test: generate install $(TESTDATA_FILE) ## Run unit tests
test: install $(TESTDATA_FILE) ## Run unit tests
uv run -- pytest

.PHONY: conformance
conformance: $(BIN)/protovalidate-conformance generate install ## Run conformance tests
protovalidate-conformance $(CONFORMANCE_ARGS) uv run test/conformance/runner.py
conformance: install ## Run conformance tests
go run github.com/bufbuild/protovalidate/tools/protovalidate-conformance@$(PROTOVALIDATE_VERSION) $(CONFORMANCE_ARGS) uv run test/conformance/runner.py

.PHONY: lint
lint: install $(BIN)/buf ## Lint code
buf format -d --exit-code
lint: install ## Lint code
uv run -- buf format -d --exit-code
uv run -- ruff format --check --diff protovalidate test
uv run -- ty check protovalidate
uv run -- ruff check protovalidate test
Expand All @@ -89,7 +85,7 @@ lint: install $(BIN)/buf ## Lint code

.PHONY: install
install: ## Install dependencies
uv sync --dev
uv sync

.PHONY: checkgenerate
checkgenerate: generate
Expand All @@ -99,15 +95,3 @@ checkgenerate: generate
$(TESTDATA_FILE):
mkdir -p $(dir @)
curl -fsSL -o $@ https://raw.githubusercontent.com/google/cel-spec/refs/tags/$(CEL_SPEC_VERSION)/tests/simple/testdata/string_ext.textproto

$(BIN):
@mkdir -p $(BIN)

$(BIN)/buf: Makefile | $(BIN)
go install github.com/bufbuild/buf/cmd/buf@v${BUF_VERSION}

$(BIN)/license-header: Makefile | $(BIN)
go install github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v${BUF_VERSION}

$(BIN)/protovalidate-conformance: Makefile | $(BIN)
go install github.com/bufbuild/protovalidate/tools/protovalidate-conformance@$(PROTOVALIDATE_VERSION)
2 changes: 0 additions & 2 deletions buf.lock

This file was deleted.

1 change: 1 addition & 0 deletions packages/protovalidate-proto/LICENSE
4 changes: 4 additions & 0 deletions packages/protovalidate-proto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# protovalidate-proto

Generated stubs for [protovalidate.proto](https://github.com/bufbuild/protovalidate). These are currently
only used for tests in this repository and are not published.
9 changes: 9 additions & 0 deletions packages/protovalidate-proto/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: v2
managed:
enabled: true
plugins:
# NOTE: v26.0 is the earliest version supporting protobuf==5.
- remote: buf.build/protocolbuffers/python:v26.0
out: src
- remote: buf.build/protocolbuffers/pyi:v26.0
out: src
1 change: 0 additions & 1 deletion buf.yaml → packages/protovalidate-proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: v2
modules:
- path: proto
- path: upstream/proto
lint:
use:
- STANDARD
Expand Down
33 changes: 33 additions & 0 deletions packages/protovalidate-proto/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[project]
name = "protovalidate-proto"
version = "0.1.0"
description = "Protocol Buffer Stubs for protovalidate-python"
readme = "README.md"
requires-python = ">=3.10"
license = "Apache-2.0"
license-files = ["LICENSE"]
keywords = ["protobuf", "protocol buffer", "validate"]
classifiers = [
"Operating System :: OS Independent",
"Private :: Do Not Upload",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Typing :: Typed",
]
dependencies = []

[project.urls]
Documentation = "https://protovalidate.com"
Homepage = "https://github.com/bufbuild/protovalidate-python"
Issues = "https://github.com/bufbuild/protovalidate-python/issues"
Source = "https://github.com/bufbuild/protovalidate-python"

[build-system]
requires = ["uv_build>=0.11.2,<0.12"]
build-backend = "uv_build"

[tool.uv.build-backend]
module-name = ["buf.validate"]
13 changes: 13 additions & 0 deletions packages/protovalidate-proto/src/buf/validate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023-2026 Buf Technologies, Inc.
#
# Licensed 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.
8 changes: 8 additions & 0 deletions packages/protovalidate-proto/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Source = "https://github.com/bufbuild/protovalidate-python"

[dependency-groups]
dev = [
"protovalidate-proto",

"buf-bin==1.69.0",
"google-re2-stubs==0.1.1",
"pytest==9.0.3",
"ruff==0.15.14",
Expand All @@ -62,12 +65,19 @@ raw-options = { fallback_version = "0.0.0" }
# Turn all warnings into errors,
# except DeprecationWarnings (which we knowingly tolerate due to using old `protobuf` APIs).
filterwarnings = ["error", "ignore::DeprecationWarning"]
pythonpath = ["test/gen"]
strict = true
# restrict testpaths to speed up test discovery
testpaths = ["test"]

[tool.ruff]
line-length = 120
exclude = [
# Protobuf generated code
"packages/protovalidate-proto/src/**",
"test/gen/**",
]

lint.select = [
"A",
"ARG",
Expand Down Expand Up @@ -108,12 +118,15 @@ lint.ignore = [
[tool.ruff.lint.isort]
known-first-party = ["protovalidate", "buf"]

[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.lint.per-file-ignores]
# Tests can use assertions.
"test/**/*" = ["S101"]

[tool.ty.environment]
extra-paths = ["gen"]
[tool.uv.sources]
protovalidate = { workspace = true }
protovalidate-proto = { workspace = true }

[tool.uv.workspace]
members = [
"packages/protovalidate-proto",
]
File renamed without changes.
6 changes: 6 additions & 0 deletions test/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/bufbuild/protovalidate
commit: 50325440f8f24053b047484a6bf60b76
digest: b5:74cb6f5c0853c3c10aafc701614194bbd63326bdb8ef4068214454b8894b03ba4113e04b3a33a8321cdf05336e37db4dc14a5e2495db8462566914f36086ba31
11 changes: 11 additions & 0 deletions test/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: v2
modules:
- path: proto
deps:
- buf.build/bufbuild/protovalidate
lint:
use:
- STANDARD
breaking:
use:
- FILE
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading