Skip to content

Remove pipenv install from Makefile #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 9 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
8 changes: 6 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ git clone git@github.com:bufbuild/protovalidate-python.git
cd protovalidate-python
```

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:
Next, install dependencies. You will need:

* Python >=v3.9
* [Pipenv](https://pipenv.pypa.io/en/latest/index.html)

We use a Makefile to test and lint our code, so you'll also 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
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
# Note we can't test above v3.12 because google-re2 does not have a
# built wheel beyond 3.12 on PyPI
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -32,6 +34,8 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pipenv"
- run: ${{steps.python.outputs.python-path}} -m pip install --upgrade pip pipenv
- name: Execute tests
run: make test PYTHON=${{ steps.python.outputs.python-path }}
- name: Lint
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
# Note we can't test above v3.12 because google-re2 does not have a
# built wheel beyond 3.12 on PyPI
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -32,5 +34,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pipenv"
- run: ${{steps.python.outputs.python-path}} -m pip install --upgrade pip pipenv
- name: Test conformance
run: make conformance PYTHON=${{ steps.python.outputs.python-path }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "3.12"
- name: Install pypa/build
run: |
python -m pip install build
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ lint: install ## Lint code

.PHONY: install
install: ## Install dependencies
$(PYTHON) -m pip install --upgrade pip pipenv
pipenv --python $(PYTHON) sync --dev

.PHONY: checkgenerate
Expand Down
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ name = "pypi"
[packages]
cel-python = "==0.2.*"
protobuf = "==6.*"
google-re2 = "*"

[dev-packages]
google-re2-stubs = "*"
pytest = "*"
mypy = "*"
ruff = "*"
types-protobuf = "*"
Copy link
Member

Choose a reason for hiding this comment

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

@smaye81 did we have a reason for pinning to this version? Wasn't sure if we needed this for something or if newer types-protobuf versions were borked in some way.

I'm guessing it's because unpinning results in:

$ make lint
pipenv --python python3 sync --dev
Loading .env environment variables...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
Installing dependencies from Pipfile.lock (8a53a8)...
Installing dependencies from Pipfile.lock (8a53a8)...
All dependencies are now up-to-date!
pipenv run ruff format --check --diff protovalidate tests
Loading .env environment variables...
16 files already formatted
pipenv run mypy protovalidate
Loading .env environment variables...
protovalidate/internal/rules.py:69: error: Incompatible types in assignment (expression has type "google.protobuf.descriptor.Descriptor | google._upb._message.Descriptor", variable has type "google.protobuf.descriptor.Descriptor")  [assignment]
protovalidate/validator.py:88: error: Argument 1 to "get" of "RuleFactory" has incompatible type "google.protobuf.descriptor.Descriptor | google._upb._message.Descriptor"; expected "google.protobuf.descriptor.Descriptor"  [arg-type]
Found 2 errors in 2 files (checked 9 source files)
make: *** [lint] Error 1

for when we want context in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that's why it's pinned. For some reason, that version is out of sync with the protobuf library and expects descriptors to be a union type.

types-protobuf = "==6.30.2.20250503"
exceptiongroup = "*"
tomli = "*"

Expand Down
163 changes: 144 additions & 19 deletions Pipfile.lock

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

18 changes: 16 additions & 2 deletions protovalidate/internal/extra_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,35 @@
# limitations under the License.

import math
import re
import typing
from urllib import parse as urlparse

import celpy
import re2
from celpy import celtypes

from protovalidate.internal import string_format
from protovalidate.internal.rules import MessageType, field_to_cel

# See https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
_email_regex = re.compile(
_email_regex = re2.compile(
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
)


# Currently cel-python does not support re2. So we are overriding their `matches`
# function with our own that leverages re2. Note there is a PR in cel-python to
# add re2 support. See https://github.com/cloud-custodian/cel-python/pull/67.
# Once that lands, this `matches` override can be removed.
def cel_matches(text: str, pattern: str) -> celpy.Result:
try:
m = re2.search(pattern, text)
except re2.error as ex:
msg = "match error"
raise celpy.CELEvalError(msg, ex.__class__, ex.args) from ex
return celtypes.BoolType(m is not None)


def cel_get_field(message: celtypes.Value, field_name: celtypes.Value) -> celpy.Result:
if not isinstance(message, MessageType):
msg = "invalid argument, expected message"
Expand Down Expand Up @@ -1560,6 +1573,7 @@ def make_extra_funcs(locale: str) -> dict[str, celpy.CELFunction]:
return {
# Missing standard functions
"format": string_fmt.format,
"matches": cel_matches,
# protovalidate specific functions
"getField": cel_get_field,
"isNan": cel_is_nan,
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ build-backend = "hatchling.build"
name = "protovalidate"
description = "Protocol Buffer Validation for Python"
readme = "README.md"
license = { file = "LICENSE" }
license-expression = "Apache 2.0"
license-file = "LICENSE"
keywords = ["validate", "protobuf", "protocol buffer"]
requires-python = ">=3.9"
classifiers = [
Expand All @@ -15,12 +16,11 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Typing :: Typed",
]
dynamic = ["version"]
dependencies = ["protobuf", "cel-python"]
dependencies = ["protobuf", "cel-python", "google-re2"]

[project.urls]
Homepage = "https://github.com/bufbuild/protovalidate-python"
Expand Down
Loading
Loading