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

Stop explicitly depending on python 2 #66605

Merged
merged 1 commit into from
Apr 10, 2020

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Nov 21, 2019

This PR revises our previous policy of officially only supporting and testing with python 2 in the CI environment to instead test with python 3. It also changes the defaults to python 3 in our various scripts (usually, by way of python rather than python3 to preserve compatibility with systems that do not have a python 3 available).

The effect of this is that we expect all new patches to support python 3 (and will test as such). We explicitly also expect that patches support python 2.7 as well -- and test as such, though only on one builder. This is intended as a temporary, though likely long-lived, measure to preserve compatibility while looking towards the future which is likely to be a python 3 only world. We do not at this point set a timeline for when we'll drop support for python 2.7; it's plausible that this is months or years into the future, depending on how quickly the ecosystem drops support and how painful it is for us to maintain that support over time.

Closes #65063 (as far as I can tell; please file explicit and separate issues or PRs if not).

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-21T13:00:20.8576826Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-21T13:00:21.4980495Z ##[command]git config gc.auto 0
2019-11-21T13:00:21.4986718Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-21T13:00:21.4991279Z ##[command]git config --get-all http.proxy
2019-11-21T13:00:21.4994050Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66605/merge:refs/remotes/pull/66605/merge
---
2019-11-21T13:06:01.4636533Z Successfully built afea3e5a34f9
2019-11-21T13:06:01.5816052Z Successfully tagged rust-ci:latest
2019-11-21T13:06:01.6453091Z Built container sha256:afea3e5a34f918d45141a9a881f8cdd73c282c51ce7d95414d70e9e818651d19
2019-11-21T13:06:01.6468993Z Uploading finished image to https://rust-lang-ci-sccache2.s3.amazonaws.com/docker/2781c8e6f0d7ff5702addf75da3252d9fe2c3b87f17f4cf2f6886d0417f523eab2b6e8b3a56c5580ab060276d097ffa9209fe0fe08f69277e52760e31cdece60
2019-11-21T13:07:04.0959445Z upload failed: - to s3://rust-lang-ci-sccache2/docker/2781c8e6f0d7ff5702addf75da3252d9fe2c3b87f17f4cf2f6886d0417f523eab2b6e8b3a56c5580ab060276d097ffa9209fe0fe08f69277e52760e31cdece60 An error occurred (InvalidAccessKeyId) when calling the CreateMultipartUpload operation: The AWS Access Key Id you provided does not exist in our records.
2019-11-21T13:07:05.1197349Z [CI_JOB_NAME=mingw-check]
2019-11-21T13:07:05.1230153Z == clock drift check ==
2019-11-21T13:07:05.1239639Z   local time: Thu Nov 21 13:07:05 UTC 2019
2019-11-21T13:07:05.4026416Z   network time: Thu, 21 Nov 2019 13:07:05 GMT
---
2019-11-21T13:12:31.9720499Z configure: rust.verify-llvm-ir  := True
2019-11-21T13:12:31.9720557Z configure: build.submodules     := False
2019-11-21T13:12:31.9720731Z configure: rust.dist-src        := False
2019-11-21T13:12:31.9720770Z configure: llvm.ccache          := sccache
2019-11-21T13:12:31.9721011Z configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
2019-11-21T13:12:31.9721097Z configure: writing `config.toml` in current directory
2019-11-21T13:12:31.9721136Z configure: 
2019-11-21T13:12:31.9721370Z configure: run `python3 /checkout/x.py --help`
2019-11-21T13:12:31.9721410Z configure: 
---
2019-11-21T13:21:06.9148519Z Build completed successfully in 0:01:44
2019-11-21T13:21:06.9242313Z + /scripts/validate-toolstate.sh
2019-11-21T13:21:06.9275486Z Cloning into 'rust-toolstate'...
2019-11-21T13:21:07.6008403Z Traceback (most recent call last):
2019-11-21T13:21:07.6008521Z   File "../../src/tools/publish_toolstate.py", line 303, in <module>
2019-11-21T13:21:07.6008658Z     cur_datetime
2019-11-21T13:21:07.6008711Z   File "../../src/tools/publish_toolstate.py", line 178, in update_latest
2019-11-21T13:21:07.6008764Z     latest = json.load(f, object_pairs_hook=collections.OrderedDict)
2019-11-21T13:21:07.6008838Z   File "/usr/lib/python3.5/json/__init__.py", line 268, in load
2019-11-21T13:21:07.6008891Z     parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
2019-11-21T13:21:07.6008944Z   File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
2019-11-21T13:21:07.6009010Z     s.__class__.__name__))
2019-11-21T13:21:07.6009798Z TypeError: the JSON object must be str, not 'bytes'
2019-11-21T13:21:07.6104774Z   local time: Thu Nov 21 13:21:07 UTC 2019
2019-11-21T13:21:07.8861508Z   network time: Thu, 21 Nov 2019 13:21:07 GMT
2019-11-21T13:21:07.8869120Z == end clock drift check ==
2019-11-21T13:21:09.5330129Z 
2019-11-21T13:21:09.5330129Z 
2019-11-21T13:21:09.5425446Z ##[error]Bash exited with code '1'.
2019-11-21T13:21:09.5454163Z ##[section]Starting: Checkout
2019-11-21T13:21:09.5455610Z ==============================================================================
2019-11-21T13:21:09.5455655Z Task         : Get sources
2019-11-21T13:21:09.5455693Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@hanna-kruppe
Copy link
Contributor

High-level comment after skimming parts of the diff: if possible we should be more specific than "Python 3", since 3.0 and other very old 3.x releases will likely not work (for long). These scripts will only be tested with the versions that python3 stands for on developers' machines and CI builders, so "Python 3" is misleading, though of course the same reasons make it difficult to determine the minimum version required.

@GuillaumeGomez
Copy link
Member Author

python3 should be fine in most (if not all) cases no? By installing python3, we'll generally get the 3.5 version. But even if we get a lower version, I don't know a case where it wouldn't work. Do you have any? (very interested in such cases!)

@hanna-kruppe
Copy link
Contributor

One example that comes to mind is that u"..." string literals were removed in 3.0 but brought back in 3.3 (now equivalent to normal "..." literals, just reducing the number of mechanical changes needed when porting from 2.x). I haven't checked but it seems likely to me that there's instances of this syntax in code originally written for 2.x and not changed for "Python 3 compatibility" since everyone was testing with 3.3+.

And of course there's also a large number of new features that were added over the years since 3.0 which only work after whatever version they were introduced, so that's a risk for code written in the future. As concrete examples, 3.6 added f-strings and underscores in numeric literals, both of which are really convenient. When I write Python code (which admittedly isn't that often these days) I use them rather often, and I can't imagine I'm the only one.

@little-dude
Copy link
Contributor

Fwiw the oldest 3.x Python version officially supported is 3.5, which will reach end-of-life on 2020-09-13. However there are still distros out there that use Python 3.4 (Debian Jessie for instance, which will reach end of life on 2020-06-30).

Anyway the scripts are currently written to be compatible with python 2.7 so they are most likely compatible with any 3.x version.

@GuillaumeGomez
Copy link
Member Author

Seems like the tests passed. Should we give it a try?

src/etc/htmldocck.py Outdated Show resolved Hide resolved
@Mark-Simulacrum
Copy link
Member

I find this PR somewhat unexpected. I would not expect us to drop compatibility with Python 2 for some time still, regardless of whether it is officially supported or not. For one thing, it's still supported until January 1st (I believe), so this PR is at least premature from that perspective. I also don't personally expect that we should be so eager to drop support just because it's not officially maintained -- if we can be compatible, why not be? To my knowledge, it's not historically been a burden on us to maintain that compatibility, so it's not clear why we should suddenly stop doing so.

I am on board with us trying to change the default to python 3, though, and making sure that works on CI and such. I am not sure if LLVM's use of python has sufficiently migrated for that to be possible, but if yes, then we can switch our defaults to I think.

@mati865
Copy link
Contributor

mati865 commented Nov 23, 2019

What about symlinking python to python3 on some builders?
That way both versions would be tested without changing other files.

@smmalis37
Copy link
Contributor

smmalis37 commented Nov 24, 2019

@Mark-Simulacrum just one piece of anecdotal evidence, but without this PR I was still able to successfully complete x.py test on my x86-64 linux system with only python 3.8 installed (after changing one call from python27 to python3). That run included successfully building LLVM.

@Mark-Simulacrum
Copy link
Member

IMO, we do not need to take any action with regards to changing scripts to remove python 2 compatibility. We should likely switch the default to python 3 as soon as is feasible (@smmalis37's results sound like we can do it now), but we should not remove compatibility with python 2 intentionally. I don't think we need to test that compatibility -- but for at least until all known distro LTS releases, etc. have moved off python 2 by default we shouldn't just drop support for it entirely.

@GuillaumeGomez
Copy link
Member Author

I'd debate over the fact that relying on an unmaintained/unsupported technology is never a good idea, but I can rollback the few python2 support removals.

@cuviper
Copy link
Member

cuviper commented Nov 24, 2019

It won't be supported by python.org, but in those LTS distros it will still be maintained and supported by their vendor.

@GuillaumeGomez
Copy link
Member Author

Added back the python2 compatibility code.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

I'd like to hear @alexcrichton's thoughts here as well, and will try to bring this up at infra meeting tomorrow (nominating).


def handle_charref(self, name):
code = int(name[1:], 16) if name.startswith(('x', 'X')) else int(name, 10)
self.__builder.data(unichr(code))
self.__builder.data(chr(code))
Copy link
Member

Choose a reason for hiding this comment

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

AFAICT, this drops compatibility with python 2 here -- is there a way to avoid that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oups indeed!

configure Outdated
try python2 "$@"
exec python $script "$@"
try python3 "$@"
exec python3 $script "$@"
Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to fallback on python 2 here to avoid breaking compatibility, i.e., we just try python 3 first.

@@ -120,10 +120,9 @@ pub fn check(build: &mut Build) {
}

build.config.python = build.config.python.take().map(|p| cmd_finder.must_have(p))
.or_else(|| cmd_finder.maybe_have("python2.7"))
.or_else(|| cmd_finder.maybe_have("python2"))
.or_else(|| cmd_finder.maybe_have("python3"))
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I'd prefer to avoid breaking compat with python 2, we should keep it as a fallback everywhere (in bootstrap/configure/etc, our CI scripts can assume it's installed).

@Mark-Simulacrum Mark-Simulacrum added I-nominated T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Nov 25, 2019
@GuillaumeGomez
Copy link
Member Author

Updated!

@alexcrichton
Copy link
Member

My personal opinion about python versions and such basically boils down to: (ranked in order of importance):

  • ./x.py build should work on "most systems"
  • CI can be whatever we want it to be
  • Ideally we'd support both Python 2 and Python 3

Other than that I do not have a preference as to what is supported nor what all the nitty-gritty is in the various locations. I do not also understand all the intricacies of why we might not support python 3 today.

@Coder-256
Copy link
Contributor

Unrelated to python... shouldn't configure be changed from:

exec python $script "$@"

to:

exec python "$script" "$@"

to work in paths that contain spaces?

Also, wouldn't the remaining env changes break Python 2 for systems that currently work? There are workarounds that would keep compatibility, although they're not pretty. To me, it seems like changing python or python2 to python3 anywhere outside of specific CI instances might be breaking. IMHO there should be at least 1 CI setup that tests with only Python 2 in its PATH so that things like this are caught.

An alternative idea: since it looks like the Python interpreter path is determined in several places, maybe this should be refactored into an environment variable? Users can set the variable, but x.py tries to find a suitable default and exports it.

@bors
Copy link
Contributor

bors commented Nov 25, 2019

☔ The latest upstream changes (presumably #66739) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 25, 2019
def py2_chr(x):
if sys.version_info[0] < 3:
return unichr(x)
return chr(x)
Copy link
Member

Choose a reason for hiding this comment

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

There is already compatibility code for this below. There is no need to modify this file at all.

@@ -1,2 +1,2 @@
all:
python2.7 test.py
python3 test.py
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
python3 test.py
'$(PYTHON)' test.py

@@ -90,6 +90,7 @@
import threading
import ctypes
import binascii
import queue as Queue
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import queue as Queue

This is handled below.

x.py Outdated
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
Copy link
Member

Choose a reason for hiding this comment

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

These shebangs should all remain #!/usr/bin/env python because the scripts support both Python 2 and 3.

Copy link
Member Author

Choose a reason for hiding this comment

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

For this file I agree, for the others not really. The default should be python3 if started as an executable. None of the other scripts are starting like this.

src/bootstrap/sanity.rs Outdated Show resolved Hide resolved
@pietroalbini
Copy link
Member

Discussed this at the infra meeting, we're fine with switching everything to Python 3 as long as we don't break Python 2, which seems the direction of this PR.

@bors
Copy link
Contributor

bors commented Apr 5, 2020

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 5, 2020
@Mark-Simulacrum Mark-Simulacrum force-pushed the drop-python2 branch 3 times, most recently from 685fc79 to bf35d8f Compare April 8, 2020 20:23
@Mark-Simulacrum
Copy link
Member

@bors r+

Fixed the conversion to a str, hopefully (it works locally). Also added some debug logging just in case.

@bors
Copy link
Contributor

bors commented Apr 8, 2020

📌 Commit bf35d8f3559c6376caf4542236dddfb2388bd650 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 8, 2020
@bors
Copy link
Contributor

bors commented Apr 10, 2020

⌛ Testing commit bf35d8f3559c6376caf4542236dddfb2388bd650 with merge 264d449596c4f21e2f9c55301bf64ba712420d3c...

@bors
Copy link
Contributor

bors commented Apr 10, 2020

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 10, 2020
@Mark-Simulacrum
Copy link
Member

@bors r+

Hopefully fixed that failure...

@bors
Copy link
Contributor

bors commented Apr 10, 2020

📌 Commit 38eb369 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 10, 2020
@bors
Copy link
Contributor

bors commented Apr 10, 2020

⌛ Testing commit 38eb369 with merge 9682f0e...

@bors
Copy link
Contributor

bors commented Apr 10, 2020

☀️ Test successful - checks-azure
Approved by: Mark-Simulacrum
Pushing 9682f0e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 10, 2020
@bors bors merged commit 9682f0e into rust-lang:master Apr 10, 2020
@chrissimpkins
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port rust python scripts to python3