Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $schema to top-level specs #370

Closed
jakevdp opened this issue Aug 8, 2017 · 7 comments
Closed

Add $schema to top-level specs #370

jakevdp opened this issue Aug 8, 2017 · 7 comments
Milestone

Comments

@jakevdp
Copy link
Collaborator

jakevdp commented Aug 8, 2017

We should point to schemas as listed at https://github.com/vega/schema

Also should use these schemas directly for Altair's API generation.

I'd like to tackle this once #364 is merged.

@ellisonbg
Copy link
Collaborator

ellisonbg commented Aug 9, 2017 via email

@jakevdp jakevdp mentioned this issue Aug 9, 2017
8 tasks
@jakevdp
Copy link
Collaborator Author

jakevdp commented Aug 9, 2017

I'm looking at this now. I could patch it onto altair pretty easily, but trying to address it within schemapi brought up a challenge that you may be able to help with, @ellisonbg:

A JSON schema can contain keys like "$schema" and "$id" which are not valid Python variable names, and thus can't be defined within traitlets in the standard way. Once a T.HasTraits class is instantiated, I can use the add_traits() method to add non-conforming trait names; e.g.

import traitlets as T

class Foo(T.HasTraits):
    pass

f = Foo()
f.add_traits(**{'$schema': T.Unicode()})
f.set_trait('$schema', 'http://myurl.com/schema.json')
print(getattr(f, '$schema'))
http://myurl.com/schema.json

Is there a good way to add a non-conforming trait name like this to a class rather than to an instance as above? Maybe construct the class using the metaclass directly?

@ellisonbg
Copy link
Collaborator

ellisonbg commented Aug 9, 2017 via email

@jakevdp
Copy link
Collaborator Author

jakevdp commented Aug 9, 2017

Yeah, that's the easy way. But in terms of generality in schemapi, it would be nice to handle this in a more general way. Perhaps I'll just add it in to_dict() for now...

@jakevdp
Copy link
Collaborator Author

jakevdp commented Aug 9, 2017

Poking around, it looks like this works:

Foo = T.MetaHasTraits('Foo', (T.HasTraits,), {'$schema': T.Unicode()})
print(Foo.class_traits())
{'$schema': <traitlets.traitlets.Unicode at 0x1069dd668>}

though I think that's not ideal to start constructing all our classes that way...

@ellisonbg
Copy link
Collaborator

ellisonbg commented Aug 9, 2017 via email

@jakevdp
Copy link
Collaborator Author

jakevdp commented Aug 10, 2017

Done in #372

@ellisonbg ellisonbg added this to the 1.2.1 milestone Sep 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants