Skip to content
Merged
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
21 changes: 18 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,29 @@ We pledge to maintain a welcoming and inclusive community. Please read
our [Code of Conduct][code-of-conduct] before participating.

## How Can I Contribute?
Clone the repository and install dependencies:

First, clone the repository:

```
git clone git@github.com:bufbuild/protovalidate-python.git
cd protovalidate-python
make install
pipenv shell
```

Then, make any changes you'd like. We use a Makefile to test and lint our code,
so you'll need a few non-Python tools:

* GNU Make (to use the Makefile): part of the `build-essential` package on
Debian-derived Linux distributions (including Ubuntu), and part of
`xcode-select --install` on Macs.
* Go (for the conformance test runner): often available in your system package
manager (`apt`, `dnf`, `brew`, etc.), but most reliable when [installed
directly from upstream](https://go.dev/doc/install).

With Go and GNU Make installed, you can verify that your changes pass tests and
lint checks by running `make`. If your Python 3 interpreter isn't available as
`python3`, try `PYTHON=python make`. For a list of other useful commands, run
`make help`.

### Reporting Bugs

Bugs are tracked as GitHub issues. If you discover a problem
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Set up Python ${{ matrix.python-version }}
- name: Install Go
uses: actions/setup-go@v4
- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Check generated
run: make checkgenerate
- name: Execute tests
run: make test
- name: Check mypy
run: mypy protovalidate
- name: Check ruff
uses: chartboost/ruff-action@v1
with:
src: "./protovalidate"
- name: Lint
run: make lint
- name: Format
run: make format
- name: Check generated
run: make checkgenerate
4 changes: 3 additions & 1 deletion .github/workflows/conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Set up Python ${{ matrix.python-version }}
- name: Install Go
uses: actions/setup-go@v4
- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand Down
55 changes: 28 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,58 @@ LICENSE_IGNORE :=
LICENSE_HEADER_VERSION := 59c69fa4ddbd56c887cb178a03257cd3908ce518
# Set to use a different compiler. For example, `GO=go1.18rc1 make test`.
GO ?= go
ARGS ?= --strict --expected_failures=nonconforming.yaml
# Set to use a different Python interpreter. For example, `PYTHON=python make test`.
PYTHON ?= python3
CONFORMANCE_ARGS ?= --strict --expected_failures=nonconforming.yaml
LICENSE_HEADER := $(BIN)/license-header \
--license-type apache \
--copyright-holder "Buf Technologies, Inc." \
--year-range "$(COPYRIGHT_YEARS)"

.PHONY: help
help: ## Describe useful make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-15s %s\n", $$1, $$2}'

.PHONY: all
all: test conformance
all: test conformance lint ## Run all tests and lint (default)

.PHONY: clean
clean: ## Delete intermediate build artifacts
@# -X only removes untracked files, -d recurses into directories, -f actually removes files/dirs
git clean -Xdf

.PHONY: generate
generate: generate-proto generate-license ## Regenerate code and license headers

.PHONY: generate-license
generate-license: $(BIN)/license-header format-python ## Format code and regenerate license headers
$(BIN)/license-header \
--license-type apache \
--copyright-holder "Buf Technologies, Inc." \
--year-range "$(COPYRIGHT_YEARS)" $(LICENSE_IGNORE)

.PHONY: generate-proto
generate-proto: $(BIN)/buf ## Regenerate code from proto files
generate: $(BIN)/buf $(BIN)/license-header ## Regenerate code and license headers
rm -rf gen
$(BIN)/buf generate buf.build/bufbuild/protovalidate
$(BIN)/buf generate buf.build/bufbuild/protovalidate-testing
$(LICENSE_HEADER) --ignore __init__.py

.PHONY: format ## Format all code
format: generate-license

.PHONY: format-python
format-python: install ## Format all code according to isort and black
python3 -m isort protovalidate tests
python3 -m black protovalidate tests
.PHONY: format
format: install $(BIN)/license-header ## Format code
$(LICENSE_HEADER)
pipenv run black protovalidate tests
pipenv run ruff --fix protovalidate tests

.PHONY: test
test: generate install ## Run all unit tests
test: $(BIN)/protovalidate-conformance generate install ## Run unit tests
pipenv run pytest

.PHONY: conformance
conformance: $(BIN)/protovalidate-conformance install
$(BIN)/protovalidate-conformance $(ARGS) pipenv -- run python3 -m tests.conformance.runner
conformance: $(BIN)/protovalidate-conformance generate install ## Run conformance tests
$(BIN)/protovalidate-conformance $(CONFORMANCE_ARGS) pipenv -- run $(PYTHON) -m tests.conformance.runner

.PHONY: lint
lint: install ## Lint code
pipenv run black --check --diff protovalidate tests
pipenv run mypy protovalidate
pipenv run ruff protovalidate tests
pipenv verify

.PHONY: install
install:
python3 -m pip install --upgrade pip
pip install pipenv ruff mypy types-protobuf black isort
pipenv --python python3 install
install: ## Install dependencies
$(PYTHON) -m pip install --upgrade pip pipenv
pipenv --python $(PYTHON) sync --dev

.PHONY: checkgenerate
checkgenerate: generate
Expand Down
7 changes: 5 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ name = "pypi"
[packages]
cel-python = "*"
protobuf = "*"
pytest = "*"
validate-email = "*"

[dev-packages]
pytest = "*"
mypy = "*"
ruff = "*"
types-protobuf = "*"
black = "*"

[requires]
python_version = "3.11"
Loading