Skip to content

Commit 3bfe42f

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

File tree

14 files changed

+77
-40
lines changed

14 files changed

+77
-40
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ 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+
working-directory: ${{ matrix.package }}
47+
4948
- name: Test with pytest
50-
run: hatch run cov
49+
run: hatch test -c
5150
working-directory: ${{ matrix.package }}
5251

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

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[submodule "schemas"]
2-
path = providers/openfeature-provider-flagd/schemas
2+
path = providers/openfeature-provider-flagd/openfeature/schemas
33
url = https://github.com/open-feature/schemas
44
[submodule "providers/openfeature-provider-flagd/test-harness"]
5-
path = providers/openfeature-provider-flagd/test-harness
5+
path = providers/openfeature-provider-flagd/openfeature/test-harness
66
url = [email protected]:open-feature/flagd-testbed.git
77
[submodule "providers/openfeature-provider-flagd/spec"]
8-
path = providers/openfeature-provider-flagd/spec
8+
path = providers/openfeature-provider-flagd/openfeature/spec
99
url = https://github.com/open-feature/spec

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: 27 additions & 8 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,47 @@ 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+
".",
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",
65-
"schemas",
84+
"openfeature",
6685
]
6786

6887
[tool.hatch.build.targets.wheel]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
schemas

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
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]
7-
evaluation_pb2,
8-
evaluation_pb2_grpc,
9-
)
106

117
from openfeature.evaluation_context import EvaluationContext
128
from openfeature.exception import (
@@ -17,6 +13,10 @@
1713
TypeMismatchError,
1814
)
1915
from openfeature.flag_evaluation import FlagResolutionDetails
16+
from openfeature.schemas.protobuf.flagd.evaluation.v1 import ( # type:ignore[import-not-found]
17+
evaluation_pb2,
18+
evaluation_pb2_grpc,
19+
)
2020

2121
from ..config import Config
2222
from ..flag_type import FlagType
@@ -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

0 commit comments

Comments
 (0)