Skip to content

Commit 62cda8e

Browse files
gruebelaepfli
andauthored
build: auto generate proto files from schema (#115)
build(flagd): auto generate proto files from schema Signed-off-by: gruebel <[email protected]> Co-authored-by: Simon Schrottner <[email protected]>
1 parent c16883e commit 62cda8e

File tree

26 files changed

+128
-1023
lines changed

26 files changed

+128
-1023
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,21 @@ 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+
48+
- name: Type checking
49+
# TODO: migrate other packages to use their own 'mypy' setup
50+
if: matrix.python-version == '3.11' && matrix.package == 'providers/openfeature-provider-flagd'
51+
working-directory: ${{ matrix.package }}
52+
run: hatch run mypy:run
53+
4954
- name: Test with pytest
50-
run: hatch run cov
55+
run: hatch test -c
5156
working-directory: ${{ matrix.package }}
5257

5358
- 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

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ repos:
2929
- mmh3
3030
- semver
3131
- panzi-json-logic
32-
exclude: proto|tests
32+
exclude: providers/openfeature-provider-flagd|tests

CONTRIBUTING.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@ 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

2731
### Integration tests
2832

2933
These are planned once the SDK has been stabilized and a Flagd provider implemented. At that point, we will utilize the [gherkin integration tests](https://github.com/open-feature/test-harness/blob/main/features/evaluation.feature) to validate against a live, seeded Flagd instance.
3034

35+
### Type checking
36+
37+
Run `mypy` by entering the package directory and running `hatch run mypy:run`.
38+
3139
## Pull Request
3240

3341
All contributions to the OpenFeature project are welcome via GitHub pull requests.

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
files = hooks,providers
2+
files = hooks,providers/openfeature-provider-ofrep
33
exclude = proto|tests
44
untyped_calls_exclude = flagd.proto
55

providers/openfeature-provider-flagd/pyproject.toml

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
]
1818
keywords = []
1919
dependencies = [
20-
"openfeature-sdk>=0.4.0",
20+
"openfeature-sdk>=0.6.0",
2121
"grpcio>=1.60.0",
2222
"protobuf>=4.25.2",
2323
"mmh3>=4.1.0",
@@ -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,26 +41,60 @@ dependencies = [
4141
"asserts",
4242
"grpcio-health-checking==1.60.0",
4343
]
44-
post-install-commands = [
45-
"./scripts/gen_protos.sh"
44+
pre-install-commands = [
45+
"hatch build",
4646
]
4747

48-
[tool.hatch.envs.default.scripts]
49-
test = "pytest {args:tests}"
50-
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"
5152
cov-report = [
5253
"coverage xml",
5354
"coverage html",
55+
"coverage report",
5456
]
5557
cov = [
5658
"test-cov",
5759
"cov-report",
5860
]
5961

62+
[tool.hatch.envs.mypy]
63+
dependencies = [
64+
"mypy[faster-cache]>=1.13.0",
65+
"types-protobuf",
66+
"types-pyyaml",
67+
]
68+
pre-install-commands = [
69+
"hatch build",
70+
]
71+
72+
[tool.hatch.envs.mypy.scripts]
73+
run = "mypy"
74+
75+
[tool.hatch.build.hooks.protobuf]
76+
generate_pyi = false
77+
dependencies = [
78+
"hatch-protobuf",
79+
"mypy-protobuf~=3.0",
80+
]
81+
proto_paths = [
82+
".",
83+
]
84+
output_path = "src/"
85+
86+
[[tool.hatch.build.hooks.protobuf.generators]]
87+
name = "mypy"
88+
outputs = ["{proto_path}/{proto_name}_pb2.pyi"]
89+
90+
[[tool.hatch.build.hooks.protobuf.generators]]
91+
name = "mypy_grpc"
92+
outputs = ["{proto_path}/{proto_name}_pb2_grpc.pyi"]
93+
6094
[tool.hatch.build.targets.sdist]
6195
exclude = [
6296
".gitignore",
63-
"schemas",
97+
"/openfeature",
6498
]
6599

66100
[tool.hatch.build.targets.wheel]
@@ -69,6 +103,32 @@ packages = ["src/openfeature"]
69103
[tool.coverage.run]
70104
omit = [
71105
# exclude generated files
72-
"src/openfeature/contrib/provider/flagd/proto/*",
106+
"src/openfeature/schemas/*",
73107
"tests/**",
74108
]
109+
110+
[tool.mypy]
111+
mypy_path = "src"
112+
files = "src"
113+
114+
python_version = "3.8" # should be identical to the minimum supported version
115+
namespace_packages = true
116+
explicit_package_bases = true
117+
local_partial_types = true
118+
pretty = true
119+
120+
strict = true
121+
disallow_any_generics = false
122+
123+
[[tool.mypy.overrides]]
124+
module = [
125+
"grpc.*",
126+
"json_logic.*",
127+
]
128+
ignore_missing_imports = true
129+
130+
[[tool.mypy.overrides]]
131+
module = [
132+
"openfeature.schemas.*"
133+
]
134+
warn_unused_ignores = false
Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)