Skip to content

Commit 3e506c2

Browse files
committed
fixup: changing to mypy-protobuf
Signed-off-by: Simon Schrottner <[email protected]>
1 parent 914d9e0 commit 3e506c2

File tree

7 files changed

+59
-25
lines changed

7 files changed

+59
-25
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ jobs:
3838
python-version: ${{ matrix.python-version }}
3939
cache: "pip"
4040

41-
- uses: bufbuild/buf-action@v1
42-
with:
43-
github_token: ${{ github.token }}
44-
setup_only: true
45-
4641
- name: Install hatch
4742
run: pip install hatch
4843

44+
- name: Building first to generate files
45+
run: hatch build
46+
4947
- name: Test with pytest
50-
run: hatch run cov
48+
run: hatch test -c
5149
working-directory: ${{ matrix.package }}
5250

5351
- if: matrix.python-version == '3.11'

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ To install Hatch, just run `pip install hatch`.
1818

1919
You will also need to setup the `pre-commit` hooks. Run `pre-commit install` in the root directory of the repository. If you don't have `pre-commit` installed, you can install it with `pip install pre-commit`.
2020

21+
> **Note**
22+
> Currently our protobuf files will be generated during `hatch build`
23+
> Please run this command once, to generate all necessary files.
24+
2125
### Testing
2226

23-
Run tests by entering the package directory and running `hatch run test`.
27+
Run tests by entering the package directory and running `hatch test`.
2428

2529
We use `pytest` for our unit testing, making use of `parametrized` to inject cases at scale.
2630

hooks/openfeature-hooks-opentelemetry/pyproject.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,23 @@ Homepage = "https://github.com/open-feature/python-sdk-contrib"
2727

2828
[tool.hatch]
2929

30-
[tool.hatch.envs.default]
30+
[tool.hatch.envs.hatch-test]
3131
dependencies = [
3232
"coverage[toml]>=6.5",
3333
"pytest",
3434
]
35+
pre-install-commands = [
36+
"hatch build",
37+
]
3538

36-
[tool.hatch.envs.default.scripts]
37-
test = "pytest {args:tests}"
38-
test-cov = "coverage run -m pytest {args:tests}"
39+
[tool.hatch.envs.hatch-test.scripts]
40+
run = "pytest {args:tests}"
41+
run-cov = "coverage run -m pytest {args:tests}"
42+
cov-combine = "coverage combine"
3943
cov-report = [
4044
"coverage xml",
45+
"coverage html",
46+
"coverage report",
4147
]
4248
cov = [
4349
"test-cov",

providers/openfeature-provider-flagd/pyproject.toml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Homepage = "https://github.com/open-feature/python-sdk-contrib"
3232

3333
[tool.hatch]
3434

35-
[tool.hatch.envs.default]
35+
[tool.hatch.envs.hatch-test]
3636
dependencies = [
3737
"coverage[toml]>=6.5",
3838
"pytest",
@@ -41,28 +41,49 @@ dependencies = [
4141
"asserts",
4242
"grpcio-health-checking==1.60.0",
4343
]
44+
pre-install-commands = [
45+
"hatch build",
46+
]
4447

45-
[tool.hatch.envs.default.scripts]
46-
test = "pytest {args:tests}"
47-
test-cov = "coverage run -m pytest {args:tests}"
48+
[tool.hatch.envs.hatch-test.scripts]
49+
run = "pytest {args:tests}"
50+
run-cov = "coverage run -m pytest {args:tests}"
51+
cov-combine = "coverage combine"
4852
cov-report = [
4953
"coverage xml",
5054
"coverage html",
55+
"coverage report",
5156
]
5257
cov = [
5358
"test-cov",
5459
"cov-report",
5560
]
5661

5762
[tool.hatch.build.hooks.protobuf]
58-
dependencies = ["hatch-protobuf"]
59-
paths = ["schemas/protobuf/schema/v1/schema.proto", "schemas/protobuf/sync/v1/sync_service.proto"]
60-
output_path = "src"
63+
generate_pyi = false
64+
dependencies = [
65+
"hatch-protobuf",
66+
"mypy-protobuf~=3.0",
67+
]
68+
proto_paths = [
69+
"schemas/protobuf/",
70+
]
71+
output_path = "src/"
72+
73+
[[tool.hatch.build.hooks.protobuf.generators]]
74+
name = "mypy"
75+
outputs = ["{proto_path}/{proto_name}_pb2.pyi"]
76+
77+
[[tool.hatch.build.hooks.protobuf.generators]]
78+
name = "mypy_grpc"
79+
outputs = ["{proto_path}/{proto_name}_pb2_grpc.pyi"]
6180

6281
[tool.hatch.build.targets.sdist]
6382
exclude = [
6483
".gitignore",
6584
"schemas",
85+
"src/schema",
86+
"src/sync",
6687
]
6788

6889
[tool.hatch.build.targets.wheel]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
flagd
2+
schema
3+
sync

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/grpc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import grpc
44
from google.protobuf.json_format import MessageToDict
55
from google.protobuf.struct_pb2 import Struct
6-
from schemas.protobuf.flagd.evaluation.v1 import ( # type:ignore[import-not-found]
6+
7+
from flagd.evaluation.v1 import ( # type:ignore[import-not-found]
78
evaluation_pb2,
89
evaluation_pb2_grpc,
910
)
10-
1111
from openfeature.evaluation_context import EvaluationContext
1212
from openfeature.exception import (
1313
FlagNotFoundError,
@@ -86,6 +86,13 @@ def _resolve( # noqa: PLR0915
8686
context = self._convert_context(evaluation_context)
8787
call_args = {"timeout": self.config.timeout}
8888
try:
89+
request: typing.Union[
90+
evaluation_pb2.ResolveBooleanRequest,
91+
evaluation_pb2.ResolveIntRequest,
92+
evaluation_pb2.ResolveStringRequest,
93+
evaluation_pb2.ResolveObjectRequest,
94+
evaluation_pb2.ResolveFloatRequest,
95+
]
8996
if flag_type == FlagType.BOOLEAN:
9097
request = evaluation_pb2.ResolveBooleanRequest(
9198
flag_key=flag_key, context=context

providers/openfeature-provider-flagd/src/schemas/.gitignore

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

0 commit comments

Comments
 (0)