-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Pyplot update in setup.py #928
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
Conversation
Providing a function for building pyplot.py is good, but I don't think it should be run automatically by setup. We don't want the act of installation to modify the code being installed, if it can possibly be avoided. In addition, I don't like the mechanism of switching stdout to grab what is printed when boilerplate is imported. Importing should import capabilities, not generate output. Suggestion: take all this out of setup.py, and turn the present boilerplate.py into a "make_pyplot.py". The present contents of boilerplate would become a function returning a string; another function would take that string and substitute it in the correct location in pyplot.py, as you are doing; and the whole thing would end with the usual "if name == 'main':" block to scriptify it. |
I actually don't have a problem with code being generated by However, there are some things about this approach that could be improved. This is putting generated code in the git repository (pyplot.py is in the repo), so it's possible that just the act of building matplotlib could cause unexpected git merge conflicts on the next Here's what I would propose:
|
I'm still a bit uncomfortable with this, but I will get used to it. But please, where you have the "from .pyplot_generated.py..." line, include a comment to the effect that this is generated in the build directory at build time, so some poor soul doesn't waste an hour hunting around for it in the git repo or tarball. And it probably should have a leading underscore to help drive home the point. |
@efiring: good point about the comment and leading underscore. |
Thanks to you both. I was hoping for a quick win by improving some stuff re boilerplating without having to change all of it, but clearly there are some un-ignorable warts :-) .
I don't really have a good response to this statement. Your absolutely correct. A standard user could do an install and end up with a different pyplot to the one we thought we had released (admittedly this is not very likely). On the other hand, pyplot is currently not being kept perfectly up to date and that is unlikely to change even if there was a simple script for a developer to run. I guess one approach could be to put a git hook inplace which runs the
In general, I agree with this statement. Indeed, I started off by having the leading part of pyplot in the src directory, but I felt that it added yet another thing to remember for very little benefit.
From this point I'm considering taking the easy answer and creating a script as @efiring suggested. This will at least make building pyplot easier, but it does leave the outstanding issue of keeping the content up-to-date. |
@pelson: github doesn't allow custom git hooks, so that's out. Generated code should never go in the git repository -- unfortunately it has been that way for a long time in the case of pyplot.py, but since the generation of that file was manually controlled (i.e. not as part of setup.py), the problems with that approach were minimized -- you have to consciously know what you're doing. The problem with the approach in this PR is that you could have a particular version of pyplot.py checked into repo, a user checks it out, installs matplotlib and pyplot.py gets changed -- this could be as simple as updating the timestamp or perhaps dictionary ordering causes the elements to come out in a different order than before. Either way, now the user has a file that git considers "changed", yet she did nothing active where she would expect a change. Doing a In case there was some confusion -- the leading part of pyplot.py would stay where it is in I agree that creating a separate script is a reasonable first step, and worthwhile work even if it gets automated in |
There are different kinds of generated code, and some belong in the repo, some don't. For example, cython-generated C-code typically is in the repo, for good reason. Its generation should be under developer control, not installer or user control. |
I have updated the boilerplate script. Unfortunately, the diffs look bigger than they are due to simple indentation. Fortunately, pyplot has changed very little, so that should give confidence that boilerplate is still doing what it was originally. |
This does look like a step in the right direction. I like it. @mdboom, are there any potential 2to3 or other version issues involved in the use of file() and binary versus text mode, for example? Does this need to be tested with git on Windows? (I don't know who would do that.) |
It would be nice (though not entirely necessary) for boilerplate to run under Python 3. At the moment, it doesn't, since it doesn't get run through 2to3.
As @efiring points out, the calls to This approach (which isn't running in setup.py anymore) shouldn't have any issues wrt to git on Windows, unless I'm missing something. |
That makes things a little neater. There are still some improvements that could be made, but I am resisting the temptation. The motivation for this whole PR is so that I can submit a small change to the content of pyplot. However I am reluctant to include it here as it would make the review harder. |
import inspect | ||
import random | ||
import re | ||
import sys | ||
import types | ||
|
||
# import the local copy of matplotlib, not the installed one | ||
#sys.path.insert(0, './lib') | ||
from matplotlib.axes import Axes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that this line probably puts the scuppers on including the boilerplate script in setup.py (at least before building the c code) in the future.
I've filed a pull request against your branch that adds Python 3 compatibility for boilerplate.py. One other thing while we're in here -- maybe we should add a paragraph to the developer docs about this? I can't seem to find it if it already exists. Other than that, I think this is good to go and is a worthwhile improvement. |
Add Python 3 compatiblity to boilerplate.py
…ot_build * 'pyplot_build' of github.com:pelson/matplotlib: Make boilerplate.py Python 3 compatible
Added some docs to the developer guide. I have built them and it all renders nicely. |
manually written and some autogenerated functions. Modifications can be made | ||
to pyplot where the function definition does not explicitly state otherwise | ||
and autogenerated functions can be modified by changing, and subsequently | ||
runnning, the :file:`boilerplate.py` script which will re-generate the complete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What changes to boilerplate.py are required?
I was trying to keep it succinct and to avoid any redundancy by documenting the boilerplate mechanism in two places (here and in boilerplate.py itself). It was my intention to ensure that a developer was aware of |
The perfect is the enemy of the good, so I have no problem accepting an improved boilerplate.py solution. But the real solution is to probably just get rid of it. As discussed in the thread linked below, when I wrote boilerplate.py there were already code magic solutions in python2.4 that could have avoided the need for boilerplate.py But I was supporting python 2.2 at the time so I just did the brute force thing. There is now so much magic cleverness in python function generation that I expect we could do away with it entirely, |
Technically, as you say, there is a far more elegant solution using @mdboom: Do you have any suggestions for the documentation in the developer guide? |
How about something like:
I think John makes a good point about removing code generation in the future if possible. I don't think it would be terribly complex, and |
@mdboom I've used your content and tweaked a little. |
Looks good, thanks! |
I think this resolves all of the issues. Unless anyone objects, I will merge in a couple of hours. |
Improved boilerplate.py and associated docs to simplify the generation of pyplot.py
It seems that it is currently very easy for the pyplot.py file to get out of date.
I have included an update process in
setup.py
which always re-builds thepyplot.py
file.