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

[SR-7211] ImportError: cannot import name 'maketrans'. Python 3 doesn't have 'maketrans' function. #49759

Open
swift-ci opened this issue Mar 15, 2018 · 8 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7211
Radar None
Original Reporter kkushal32 (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: eac4cd925d62f3dfb4cef600730cc2c6

Issue Description:

When I do a clean build i.e. by running the command

utils/build-script -c

this is the error.

File "/Volumes/SSD-KSVSK/swift-source/swift/stdlib/public/core/Integers.swift.gyb", line 20, in <module>{{ from string import maketrans, capitalize}}ImportError: cannot import name 'maketrans'

Python 3 doesn't have the maketrans function. Instead they have static maketrans methods.Now str, bytes, and bytearray each have their own maketrans and translate methods with intermediate translation tables of the appropriate type.

@swift-ci
Copy link
Collaborator Author

Comment by Kushal K S V S (JIRA)

I think this should be the case for Python 3

diff --git a/stdlib/public/core/Integers.swift.gyb b/stdlib/public/core/Integers.swift.gyb

index a2a02b8c93..3900bc9080 100644

      • a/stdlib/public/core/Integers.swift.gyb

+++ b/stdlib/public/core/Integers.swift.gyb

@@ -17,7 +17,7 @@

from SwiftIntTypes import all_integer_types, int_max_bits, should_define_truncating_bit_pattern_init

from SwiftFloatingPointTypes import getFtoIBounds

-from string import maketrans, capitalize

+from string import capitalize

from itertools import chain

Number of bits in the Builtin.Word type

@@ -2490,7 +2490,7 @@ ${operatorComment(x.nonMaskingOperator, True)}

 lhs = ${x.helper}(lhs, shift)

}

-% reversedOperator = x.operator.translate(maketrans('<>', '><'))

+% reversedOperator = x.operator.translate(str.maketrans('<>', '><'))

% isRightShift = '>' in x.operator

@_inlineable // FIXME(sil-serialize-all)

@inline(__always)

@swift-ci
Copy link
Collaborator Author

Comment by Kushal K S V S (JIRA)

Also capitalize isn't supported on python3

@swift-ci
Copy link
Collaborator Author

Comment by Kushal K S V S (JIRA)

So, there are other errors coming up if compiled using python 3. So, I think there should be an indication in the documentation that python 2 must be used.

To solve the issue, I created a virtual environment with python 2.7 and then built swift in that virtual environment.
That was successful.

Please update the README.

Thank You

@belkadan
Copy link
Contributor

Thanks![]( We definitely should update the Readme. Additionally, if you want to make a patch that works in both Python 2 and Python 3, we'd be happy to take it)

@swift-ci
Copy link
Collaborator Author

Comment by Kushal K S V S (JIRA)

Sure. I'll work on that.

@swift-ci
Copy link
Collaborator Author

Comment by Kushal K S V S (JIRA)

I am still getting acquainted with swift. I'd like to know the build script option(s) required for this.

I don't want everything to build again or somethings to miss.

Thank You

@belkadan
Copy link
Contributor

The basic invocation you have should build everything (and should be able to drop -c when investigating; all of the Python-generated outputs should have proper dependencies set up); if you want to look for Python 3 issues in the tests as well you can add -t. Unfortunately I don't see any way to just generate the .gyb files and not actually spend the effort building the standard library.

@swift-ci
Copy link
Collaborator Author

Comment by Kushal K S V S (JIRA)

I have a doubt.
When I run `utils/build-script -t`, is it supposed to pass all the tests ? Ths is my test summary.

?? ********************??
?? Testing Time: 7609.71s??
?? ********************??
?? Failing Tests (3):??
?? Swift(macosx-x86_64) :: Serialization/comments-framework.swift??
?? Swift(macosx-x86_64) :: Interpreter/SDK/libc.swift??
?? Swift(macosx-x86_64) :: Index/Store/output-failure.swift??

?? Expected Passes : 4248??
?? Expected Failures : 23??
?? Unsupported Tests : 85??
?? Unexpected Failures: 3??
?? *** Failed while running tests for swift (check-swift-macosx-x86_64)??
?? utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting??

Is there anything I have to configure ?
Also here is the pastebin of the errors encountered during the tests.

https://pastebin.com/TmpcvzgN

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants