Skip to content

Commit 87c50a4

Browse files
committed
Merge branch 'feat/autogenerate_proto_files' into feat/grpc-sync-addition
Signed-off-by: Simon Schrottner <[email protected]>
2 parents 07a38e6 + 4b74a53 commit 87c50a4

File tree

20 files changed

+102
-54
lines changed

20 files changed

+102
-54
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: 14 additions & 2 deletions
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

@@ -50,6 +54,13 @@ Navigate to the repository folder
5054
cd python-sdk-contrib
5155
```
5256

57+
Checkout submodules
58+
59+
```bash
60+
git submodule update --init --recursive
61+
```
62+
63+
5364
Add your fork as an origin
5465

5566
```bash
@@ -60,7 +71,8 @@ Ensure your development environment is all set up by building and testing
6071

6172
```bash
6273
cd <package>
63-
hatch run test
74+
hatch build
75+
hatch test
6476
```
6577

6678
To start working on a new feature or bugfix, create a new branch and start working on it.

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",
Submodule spec updated from 0000000 to 3c737a6

providers/openfeature-provider-flagd/pyproject.toml

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

3434
[tool.hatch]
3535

36-
[tool.hatch.envs.default]
36+
[tool.hatch.envs.hatch-test]
3737
dependencies = [
3838
"coverage[toml]>=6.5",
3939
"pytest",
@@ -42,28 +42,47 @@ dependencies = [
4242
"asserts",
4343
"grpcio-health-checking==1.60.0",
4444
]
45+
pre-install-commands = [
46+
"hatch build",
47+
]
4548

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

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

6382
[tool.hatch.build.targets.sdist]
6483
exclude = [
6584
".gitignore",
66-
"schemas",
85+
"/openfeature",
6786
"test-harness",
6887
"spec"
6988
]
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
@@ -7,10 +7,6 @@
77
from cachebox import LRUCache # type:ignore[import-not-found]
88
from google.protobuf.json_format import MessageToDict
99
from google.protobuf.struct_pb2 import Struct
10-
from schemas.protobuf.flagd.evaluation.v1 import ( # type:ignore[import-not-found]
11-
evaluation_pb2,
12-
evaluation_pb2_grpc,
13-
)
1410

1511
from openfeature.evaluation_context import EvaluationContext
1612
from openfeature.event import ProviderEventDetails
@@ -24,6 +20,10 @@
2420
TypeMismatchError,
2521
)
2622
from openfeature.flag_evaluation import FlagResolutionDetails, Reason
23+
from openfeature.schemas.protobuf.flagd.evaluation.v1 import ( # type:ignore[import-not-found]
24+
evaluation_pb2,
25+
evaluation_pb2_grpc,
26+
)
2727

2828
from ..config import CacheType, Config
2929
from ..flag_type import FlagType
@@ -217,6 +217,13 @@ def _resolve( # noqa: PLR0915 C901
217217
context = self._convert_context(evaluation_context)
218218
call_args = {"timeout": self.deadline}
219219
try:
220+
request: typing.Union[
221+
evaluation_pb2.ResolveBooleanRequest,
222+
evaluation_pb2.ResolveIntRequest,
223+
evaluation_pb2.ResolveStringRequest,
224+
evaluation_pb2.ResolveObjectRequest,
225+
evaluation_pb2.ResolveFloatRequest,
226+
]
220227
if flag_type == FlagType.BOOLEAN:
221228
request = evaluation_pb2.ResolveBooleanRequest(
222229
flag_key=flag_key, context=context

0 commit comments

Comments
 (0)