Skip to content

Commit

Permalink
flx: treat descr field in schema definitions as optional (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-makerx authored Jan 8, 2024
1 parent 5ea4716 commit 864134f
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 87 deletions.
18 changes: 17 additions & 1 deletion examples/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import importlib
import json
import logging
import os
from collections.abc import Generator
from contextlib import contextmanager
from pathlib import Path

import algokit_utils

logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)-10s: %(message)s")
logger = logging.getLogger(__name__)
root_path = Path(__file__).parent
Expand All @@ -20,6 +23,19 @@ def cwd(path: Path) -> Generator[None, None, None]:
os.chdir(old_pwd)


def to_json(app_spec: algokit_utils.ApplicationSpecification) -> str:
app_spec_dict = app_spec.dictify()
# beaker always outputs an empty string by default for the schema "descr" field, however this field is optional
# so remove these keys if they are an empty string so optional descr fields are covered
for scope in ("global", "local"):
for reservation in ("declared", "reserved"):
state_dict = app_spec_dict["schema"][scope][reservation]
for _field, field_spec in state_dict.items():
if not field_spec.get("descr"):
del field_spec["descr"]
return json.dumps(app_spec_dict, indent=4)


def main() -> None:
example_dirs = filter(lambda file: file.is_dir() and "__" not in file.name, root_path.glob("*"))
for example in example_dirs:
Expand All @@ -30,7 +46,7 @@ def main() -> None:
logger.info(f" Building app {app.name}")
app_spec = app.build()
logger.info(f" Writing {example.name}/application.json")
(example / "application.json").write_text(app_spec.to_json())
(example / "application.json").write_text(to_json(app_spec))


if __name__ == "__main__":
Expand Down
6 changes: 2 additions & 4 deletions examples/lifecycle/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
"declared": {
"greeting": {
"type": "bytes",
"key": "greeting",
"descr": ""
"key": "greeting"
},
"times": {
"type": "uint64",
"key": "times",
"descr": ""
"key": "times"
}
},
"reserved": {}
Expand Down
6 changes: 2 additions & 4 deletions examples/lifecycle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@
"declared": {
"greeting": {
"type": "bytes",
"key": "greeting",
"descr": ""
"key": "greeting"
},
"times": {
"type": "uint64",
"key": "times",
"descr": ""
"key": "times"
}
},
"reserved": {}
Expand Down
27 changes: 9 additions & 18 deletions examples/state/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,23 @@
"declared": {
"bytes1": {
"type": "bytes",
"key": "bytes1",
"descr": ""
"key": "bytes1"
},
"bytes2": {
"type": "bytes",
"key": "bytes2",
"descr": ""
"key": "bytes2"
},
"int1": {
"type": "uint64",
"key": "int1",
"descr": ""
"key": "int1"
},
"int2": {
"type": "uint64",
"key": "int2",
"descr": ""
"key": "int2"
},
"value": {
"type": "uint64",
"key": "value",
"descr": ""
"key": "value"
}
},
"reserved": {}
Expand All @@ -176,23 +171,19 @@
"declared": {
"local_bytes1": {
"type": "bytes",
"key": "local_bytes1",
"descr": ""
"key": "local_bytes1"
},
"local_bytes2": {
"type": "bytes",
"key": "local_bytes2",
"descr": ""
"key": "local_bytes2"
},
"local_int1": {
"type": "uint64",
"key": "local_int1",
"descr": ""
"key": "local_int1"
},
"local_int2": {
"type": "uint64",
"key": "local_int2",
"descr": ""
"key": "local_int2"
}
},
"reserved": {}
Expand Down
27 changes: 9 additions & 18 deletions examples/state/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,28 +168,23 @@
"declared": {
"bytes1": {
"type": "bytes",
"key": "bytes1",
"descr": ""
"key": "bytes1"
},
"bytes2": {
"type": "bytes",
"key": "bytes2",
"descr": ""
"key": "bytes2"
},
"int1": {
"type": "uint64",
"key": "int1",
"descr": ""
"key": "int1"
},
"int2": {
"type": "uint64",
"key": "int2",
"descr": ""
"key": "int2"
},
"value": {
"type": "uint64",
"key": "value",
"descr": ""
"key": "value"
}
},
"reserved": {}
Expand All @@ -198,23 +193,19 @@
"declared": {
"local_bytes1": {
"type": "bytes",
"key": "local_bytes1",
"descr": ""
"key": "local_bytes1"
},
"local_bytes2": {
"type": "bytes",
"key": "local_bytes2",
"descr": ""
"key": "local_bytes2"
},
"local_int1": {
"type": "uint64",
"key": "local_int1",
"descr": ""
"key": "local_int1"
},
"local_int2": {
"type": "uint64",
"key": "local_int2",
"descr": ""
"key": "local_int2"
}
},
"reserved": {}
Expand Down
Loading

1 comment on commit 864134f

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/algokit_client_generator
   __main__.py220%1–3
   cli.py47470%1–81
   document.py82890%44, 47, 49–50, 55, 69, 74–75
   generator.py459699%22, 118, 264, 792, 966, 981
   utils.py1081289%24, 41–42, 44, 46, 48, 50, 52, 55–56, 82, 111
TOTAL8307591% 

Tests Skipped Failures Errors Time
40 0 💤 0 ❌ 0 🔥 19.275s ⏱️

Please sign in to comment.