Skip to content

python3 compat #25749

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 7 commits into from
May 27, 2015
Merged

python3 compat #25749

merged 7 commits into from
May 27, 2015

Conversation

richo
Copy link
Contributor

@richo richo commented May 24, 2015

This is enough to make make tidy work if you're using python3

There's definitely more stuff to do, but PR'ing now to avoid bitrot

@rust-highfive
Copy link
Contributor

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

if sys.version_info.major == 2:
_open = lambda f: open(f, 'r')
elif sys.version_info.major == 3:
_open = lambda f: open(f, 'r', encoding="utf-8")
Copy link
Member

Choose a reason for hiding this comment

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

How come this was necessary? Did this run into problems for some files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it exploded on some of the innards of Rc, although I didn't dig into it super far.

I did a little reading, and the gist was that evidently python2 would lossily coerce invalid ascii characters, whereas python3 treats them as a hard error. I can dig up what I was reading if you'd like.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to open a file as UTF-8 in python2? All our source files should be valid UTF-8 I believe at least

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a commit that uses the codecs module to do it.

@alexcrichton
Copy link
Member

Thanks @richo! Unfortunately I don't think we can move completely to accepting python 3 until LLVM's build system supports it, but this certainly can't hurt!

@richo
Copy link
Contributor Author

richo commented May 26, 2015

Yup. It's not even clear to me that we'd want to, but a few projects I work on have been stung repeatedly by Ubuntu's default python switching, and I was waiting on a build so I figured I'd at least get make tidy working under py3.

this asserts that source is valid utf8 on both python3 and python2
@richo
Copy link
Contributor Author

richo commented May 26, 2015

Actually that approach also works on python3. Removed the janky branch.

@alexcrichton
Copy link
Member

@bors: r+ 96d7400

@bors
Copy link
Collaborator

bors commented May 27, 2015

⌛ Testing commit 96d7400 with merge 55f48b1...

@bors
Copy link
Collaborator

bors commented May 27, 2015

💔 Test failed - auto-linux-32-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

On Tue, May 26, 2015 at 9:49 PM, bors [email protected] wrote:

[image: 💔] Test failed - auto-linux-32-nopt-t
http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/5107


Reply to this email directly or view it on GitHub
#25749 (comment).

@bors
Copy link
Collaborator

bors commented May 27, 2015

⌛ Testing commit 96d7400 with merge 5a2c766...

bors added a commit that referenced this pull request May 27, 2015
This is enough to make `make tidy` work if you're using python3

There's definitely more stuff to do, but PR'ing now to avoid bitrot
@bors bors merged commit 96d7400 into rust-lang:master May 27, 2015
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.

4 participants