Skip to content

Commit

Permalink
WIP, created the functions file
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Nov 7, 2023
1 parent 4746dc7 commit a6b8a5a
Show file tree
Hide file tree
Showing 3 changed files with 870 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from os.path import exists
from pathlib import Path
from os import getcwd
from json import loads
from json import loads, dumps
from jsonschema.validators import Draft202012Validator
from referencing import Registry, Resource
from opentelemetry.configuration._internal.yaml_parser import YAMLParser
Expand Down Expand Up @@ -214,6 +214,11 @@ def traverse(schema_dictionary, schema_path, schema_paths):
schema_dictionary.items()
):

if schema_dictionary_key == "sampler":
# This is because there are recursive samplers that crash this
# algorithm.
continue

if isinstance(schema_dictionary_value, dict):
if schema_dictionary_key in schema_dictionary.keys():
schema_dictionary_key = schema_dictionary_key
Expand Down Expand Up @@ -243,6 +248,51 @@ def traverse(schema_dictionary, schema_path, schema_paths):
schema_path.pop()

schema_paths = []

traverse(schema_dictionary, [], schema_paths)

schema_paths.pop(0)

return schema_paths


def write_schema_paths_functions(
schema_paths: list, schema_paths_functions_file_path: str
):

schema_paths_function_names = {}

for schema_path in schema_paths:

schema_paths_function_names[schema_path] = (
schema_path.
replace("properties/", "").
replace("items/", "").
replace("/", "_")
)

schema_paths_functions = dumps(schema_paths_function_names, indent=4)

schema_paths_functions = schema_paths_functions.replace(': "', ": ")
schema_paths_functions = schema_paths_functions.replace('",', ",")
schema_paths_functions = schema_paths_functions.replace('"\n', "\n")

with open(schema_paths_functions_file_path, "w") as (
schema_paths_functions_file
):
schema_paths_functions_file.write("# flake8: noqa: E501\n")

for function_name in schema_paths_function_names.values():
schema_paths_functions_file.write("\n")
schema_paths_functions_file.write("\n")
schema_paths_functions_file.write(
f"def {function_name}(*args, **kwargs):\n"
)
schema_paths_functions_file.write(" pass\n")

schema_paths_functions_file.write("\n")
schema_paths_functions_file.write("\n")

schema_paths_functions_file.write(
f"path_function = {schema_paths_functions}"
)
Loading

0 comments on commit a6b8a5a

Please sign in to comment.