Skip to content

Local plot schema #648

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

Merged
merged 6 commits into from
Jan 5, 2017
Merged

Local plot schema #648

merged 6 commits into from
Jan 5, 2017

Conversation

theengineear
Copy link
Contributor

This PR stops auto-loading the plot-schema on import. We decided in #642 that this shouldn't need to force a major version bump, so I'll add a minor version bump here.

See #614 for the original PR. I noticed that we actually had a weird PY3 conflict due to a change in how importing works in PY3 (See commit notes).

Conflicts:
	plotly/api/v2/plot_schema.py
	plotly/graph_reference.py
	plotly/tests/test_core/test_api/test_v2/test_plot_schema.py
	plotly/tests/test_core/test_graph_reference/test_graph_reference.py
@theengineear
Copy link
Contributor Author

@Kully can you give this a review? We discussed the no-download-on-import portion of this in #642, but I've also done the following (which we haven't discussed wrt Semantic Versioning):

  • .js and .json files --> plotly/package_data. I can't imagine any users are using the non-python files directly in scripts.
  • auto-object generation. This isn't backwards-incompatible. In fact, it's exactly what we had before, except now it's not generated on import in memory.

@chriddyp, 👍 on the meta programming introduced in 51ef008?

@@ -37,7 +37,8 @@ def _list_help(object_name, path=(), parent_object_names=()):
items = graph_reference.ARRAYS[object_name]['items']
items_classes = [graph_reference.string_to_class_name(item)
for item in items]
lines = textwrap.wrap(repr(items_classes), width=LINE_SIZE-TAB_SIZE)
items_classes.sort()
lines = textwrap.wrap(repr(items_classes), width=LINE_SIZE-TAB_SIZE - 1)
Copy link
Contributor

@Kully Kully Jan 5, 2017

Choose a reason for hiding this comment

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

Nit Picky, but would lines = textwrap.wrap(repr(items_classes), width=LINE_SIZE - TAB_SIZE - 1)
or lines = textwrap.wrap(repr(items_classes), width=LINE_SIZE-TAB_SIZE-1) be better for consistency?

@@ -167,7 +169,7 @@ def _dict_attribute_help(object_name, path, parent_object_names, attribute):
if isinstance(val, list) and attribute == 'showline':
val = val[0]

lines = textwrap.wrap(val, width=LINE_SIZE)
lines = textwrap.wrap(val, width=LINE_SIZE - 1)
Copy link
Contributor

@Kully Kully Jan 5, 2017

Choose a reason for hiding this comment

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

Same thing

attributes = list(
graph_reference.get_valid_attributes(object_name, parent_object_names))
attributes.sort()
lines = textwrap.wrap(repr(list(attributes)), width=LINE_SIZE-TAB_SIZE - 1)
Copy link
Contributor

Choose a reason for hiding this comment

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


:raises: (ValueError) If the FLAG isn't found.
:return: (list) The lines we're copying.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the doc strings should not have the extra space between last line and the triple quotes """

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hehe, I disagree on this one. But I'm OK with changing it. You like to do the blank line after the """ then?

if not flag_found:
raise ValueError(
'Failed to find flag:\n''{}\n''in graph_objs_tools.py.'
.format(FLAG)
Copy link
Contributor

@Kully Kully Jan 5, 2017

Choose a reason for hiding this comment

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

More a suggestion, but for legibility, what do you think about putting the format(FLAG) on the line above? I think it's 81 chars on that line, but would be worth IMO

Your call ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh... that string looks wrong to me, the extra ' characters? I'll fix this up.



def print_figure_patch(f):
"""Print a patch to our Figure object into the given open file."""
Copy link
Contributor

@Kully Kully Jan 5, 2017

Choose a reason for hiding this comment

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

For one-liner doc strings, which is more common to your knowledge:

'''one-line-here'''

'''
one-line-here
'''

I usually do the latter. Let me know if you think this is worth worrying/thinking about

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, we generated these *on import*, which is slow and it’s a
little sneaky. Users end up using classes that are not actually written
*anywhere* in our package.

Now that we only update the plot schema in version releases (no longer
on import), we can also just programmatically add in all the graph obj
classes. Instead of adding them to memory, we literally just print them
to the file.

This is some serious meta-programming… but, the resulting file will have
to be syntactically valid and pass our test suite, so I’m not *too*
worried about it.
In Python 2, you *must* have an `__init__.py` file to have a python
package. However, in Python 3, you don’t need that!

We have `/graph_reference` and `graph_reference.py` defined, which seems
to *work*, but is poorly organized and should be fixed. For instance, it
causes `unresolved import errors` in IDEs that have `goto-source`-type
functionality.

Conflicts:
	makefile
This has been a source of confusion every time we end up needing a new
resource (like a js or json file). If you forget to add the new pattern
in `setup.py`, the installed site-package just won’t include the file.

Now all our non `.py` files should live in `package_data/`.
I think this got introduced during some rebases ;__;.
@theengineear
Copy link
Contributor Author

@Kully alright with this?

@theengineear
Copy link
Contributor Author

theengineear commented Jan 5, 2017

@chriddyp , it'd be great to get a high-level 👍 from you on 51ef008 still.

You don't need to dig into the code very much. In general I'm just wondering if you think the approach of moving the meta programming we were already doing into auto-generated lines inside the graph_objs.py files seems OK.

Specifically, all the work is done in update_graph_objs.py, where I literally print new lines into graph_objs.py programmatically.

Edit, after rebase --> c26e318

@theengineear
Copy link
Contributor Author

Since I've got a lot of moving parts happening in this repo, I'm going to merge after chatting with @Kully in slack and with @chriddyp's 👍 for hard-coding our graph_objs.

@theengineear theengineear merged commit 4191458 into master Jan 5, 2017
@theengineear theengineear deleted the local-plot-schema branch January 5, 2017 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants