def generate_vega_schema_wrapper(schema_file): """Generate a schema wrapper at the given path.""" # TODO: generate simple tests for each wrapper basename = 'VegaSchema' with open(schema_file) as f: rootschema = json.load(f) contents = [ HEADER, "from altair.utils.schemapi import SchemaBase, Undefined", LOAD_SCHEMA.format(schemafile='vega-schema.json') ] contents.append(BASE_SCHEMA.format(basename=basename)) contents.append( schema_class('Root', schema=rootschema, basename=basename, schemarepr=CodeSnippet('load_schema()'))) for deflist in ['defs', 'refs']: for name in rootschema[deflist]: defschema = {'$ref': '#/{0}/{1}'.format(deflist, name)} defschema_repr = {'$ref': '#/{0}/{1}'.format(deflist, name)} contents.append( schema_class(get_valid_identifier(name), schema=defschema, schemarepr=defschema_repr, rootschema=rootschema, basename=basename, rootschemarepr=CodeSnippet("Root._schema"))) contents.append('') # end with newline return '\n'.join(contents)
def generate_schema_wrapper(schema_file): """Generate a schema wrapper at the given path.""" with open(schema_file) as f: rootschema = json.load(f) contents = [ "# The contents of this file are automatically generated", "# at time {0}\n".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), "from altair.utils.schemapi import SchemaBase, Undefined", LOAD_SCHEMA ] contents.append( schema_class('Root', schema=rootschema, schemarepr=CodeSnippet('load_schema()'))) for name in rootschema['definitions']: defschema = {'$ref': '#/definitions/' + name} defschema_repr = {'$ref': '#/definitions/' + name} contents.append( schema_class(get_valid_identifier(name), schema=defschema, schemarepr=defschema_repr, rootschema=rootschema, rootschemarepr=CodeSnippet("Root._schema"))) contents.append('') # end with newline return '\n'.join(contents)
def generate_vegalite_schema_wrapper(schema_file): """Generate a schema wrapper at the given path.""" # TODO: generate simple tests for each wrapper with open(schema_file) as f: rootschema = json.load(f) contents = [ HEADER, "from altair.utils.schemapi import SchemaBase, Undefined", LOAD_SCHEMA.format(schemafile='vega-lite-schema.json') ] contents.append( schema_class('Root', schema=rootschema, schemarepr=CodeSnippet('load_schema()'))) for name in rootschema['definitions']: defschema = {'$ref': '#/definitions/' + name} defschema_repr = {'$ref': '#/definitions/' + name} contents.append( schema_class(get_valid_identifier(name), schema=defschema, schemarepr=defschema_repr, rootschema=rootschema, rootschemarepr=CodeSnippet("Root._schema"))) contents.append('') # end with newline return '\n'.join(contents)
def generate_schema_wrapper(schema): schema = load_schema() contents = [ "# The contents of this file are automatically generated", "# at time {0}\n".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), "from altair.schema.base import SchemaBase, Undefined", "from altair.schema.loader import load_schema", "" ] contents.append(schema_class('Root', schema, CodeSnippet('load_schema()'))) for name in schema['definitions']: pyname = get_valid_identifier(name) defschema = { '$ref': '#/definitions/' + name, 'definitions': schema['definitions'] } defschema_repr = { '$ref': '#/definitions/' + name, 'definitions': CodeSnippet("Root._Root__schema['definitions']") } contents.append(schema_class(pyname, defschema, defschema_repr)) contents.append('') # end with newline return '\n'.join(contents)