-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Python code cleanup, first work toward CPython 3 compatibility #33036
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@sanmai-NL Thanks for the pull! Since each of those commits is a small change and the commit messages are the same, you should probably squash them all to one commit. |
Thanks! Most of these scripts aren't actually used anyway, for example almost all of these scripts are on the way out except for Also would it be possible to just change how we print things to be a little more compatible? (parens are all we need, right?). |
@luqmana: So as these Python files other than Questions
Minimal changes required to gain CPython 3 compatibility for
I think the way to move forward is to merge this PR and if |
Some of the scripts are irrelevant to the build process but very much tied to the Rust source code, e.g., because they generate source code that goes into
Identifying and removing such obsolete scripts is thankless but not useless work. It also makes for a cool diffstat 😄 |
A good question! The
A bunch of it is on the way out but in general we don't clean up I'd definitely be ok removing anything we don't need, but stuff like
Ah I believe what's going on here is @rkruppe is pointing out that LLVM requires Python 2.7 as the version to build it. We just, however, build LLVM, we don't test it. It may be the case that building LLVM has a looser restriction for Python than testing it, but neither @rkruppe nor I seem to know many details here :) Either way, we're not gonna be rushing to update Python on our bots any time soon, but it's certainly a good idea to whip all our own stuff in to shape for using Python 3 eventually.
Oh dear! Feel free to include a fix for that in this PR! I guess my main question is this: So most of this PR is adding this to the top of all Python files: from __future__ import print_function Is that necessary? Shouldn't it only matter if we call |
I'm basing this off footnote 2 on http://llvm.org/releases/3.8.0/docs/GettingStarted.html#software which seems to imply no Python is needed at all if you don't run tests. Of course I never actually tried that.
It is indeed unnecessary if you restrict yourself to the form |
Actually, spamming |
Yes @rkruppe, that was exactly my reason for adding these lines everywhere. Is guess that was unclear. This is actually part of any first attempt at dual Python 2/3 compatibility. If CPython turns out not be a build dependency at all, then wouldn't it be better if
Not to mention it is slow and behaves unpredictably across platforms and environments. Probably some people are going to have issues down the road because something is unexpected about their CPython setup (e.g., similar to #32994). Dropping CPython reduces compilation time and will reduce the size of any virtualization image (e.g., Docker container image) that ships a toolchain to build Rust from source (based on the stated dependencies). |
☔ The latest upstream changes (presumably #32942) made this pull request unmergeable. Please resolve the merge conflicts. |
Not sure whether I have successfully rebased to resolve the merge conflicts now. @alexcrichton: it would be helpful if you could make some graphical and/or verbal overview of the build process as public documentation. It will reduce time needed to prepare for contribution. |
I think this may be overstating the benefits. But regardless,
Perhaps this topic would be better discussed in a thread over at http://internals.rust-lang.org/ since it's more far-future planning and has little to do with the contents of this PR (which seems borked by the way, as 100+ commits by various authors show up). |
Yeah we're probably not gonna drop Python just yet, but if it turns out that LLVM doesn't need it we're surely much closre! Also as @rkruppe mentioned you may need a |
Oops, sorry for the borked PR state. I've now reset the PR state to the last of my initial commits, recloned, then again tried to follow the project's tips creating the appropriate remotes etc., rebasing worked without conflict (odd?), then tried to push a merge commit to my fork. But that didn't work out so well because @rkruppe: I questioned the very use of Python to find out whether there's any merit in me spending time on the Python files if they are more-or-less redundant/in flux. Given your and @alexcrichton' s comments and recent commits, I suppose I'd better leave this rather internal part of the source tree to you. Regardless, it would be good the build process (i.e., the purpose and status of the dependencies) is documented schematically somewhere, for outsiders. |
|
Looks like there may still be some lingering commits? |
@mitaa: thanks. That would reset back to my last commit, but bors reported the PR was unmergable in that state. @alexcrichton: any tips what to do, should I indeed reset to my last commit? |
@sanmai-NL Reset to your last commit to get rid of the nonsense commits. Then rebase again, and hopefully it works the second time around. |
@alexcrichton: It's mergable now. 😃 |
@@ -1,3 +1,4 @@ | |||
from __future__ import print_function |
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.
Could these imports go under the license header? Or is it required that they're the first thing in the file?
* Remove redundant parentheses, imports. * Improve CPython 3 compatibility. * Add or modify shebang for scripts predictably depending on specific CPython version. * Simplify conditional control structures. * Define RustBuild constructor instead of mutating object unnecessarily. * Apply style normalization according to PEP guides. * Et cetera.
@alexcrichton: Yes, There are also definite bugs in If you wish to remove some Python code, please do so after merging this PR, and I if time permits I'll try to refactor the remaining code. Finding out what scripts are important/in use by your team is too much work for me to do I think. For example, it seems one script |
@sanmai-NL hm looks like there's a huge number more of related changes going on here now? Perhaps the stylistic ones can be left out for a future PR, and just the Python 3 compatibility ones can be here? |
@alexcrichton, I fully agree that PRs should ideally be well circumscribed. One thing I think we already agree about, is that there's a lot to improve about the Python code needed for building and testing Rust. The trade-off I made here takes into account reviewing/process overhead between submitting multiple PRs vs. submitting one larger PR. Practically of the changes are basic cleanup style changes, just to prepare the ground for more substantial refactoring still to come. I'll make sure that the number, scope and type of commits will be more productive next time. I'm sorry, I think the Python commit isn't disentangleable without excessive effort at this point. The PR started out as a first, small batch of automated CPython 3 compatibility refactorings. After some exchanges and me having to learn a few things along the way, you then requested a stylistic fixup. But making a stylistic fixup in one or a few files isn't so optimal, without consistency with the other related Python code. And stylistic changes are I think best primarily done with an automated tool following common norms, instead of manually fixing one aspect (i.e., I didn't find a way to look what the merge conflicts are that GitHub warns me about at the end of this page. |
Can we keep this PR constrained to just Python 3 compatibility? Let's move the stylistic changes (e.g. whitespace, etc) to a separate PR as they can be somewhat more controversial. The merge conflicts mostly just indicate that the PR needs a rebase from master. |
I'll do my best, may have to wait until next weekend though. |
Closing due to inactivity, but feel free to resubmit with a rebase! |
This is a first attempt at making the Python codebase dual CPython 2 and 3 compatible.
I was guided by this official porting guide. I used
futurize
0.15.2. In this PR, I restricted myself to stage 1 modifications, described as:Some
print
statements became a little uglier by additional parentheses. That can be prevented with a2to3
parameter, by why not clean that up later if needed at all ... Let's for now just see if the build still succeeds.