-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Python] Use explicit imports #752
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
@@ -1,6 +1,3 @@ | |||
from __future__ import absolute_import | |||
from .main import main | |||
|
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.
This change causes an error:
apple/swift $ ./utils/cmpcodesize/cmpcodesize.py -h
Traceback (most recent call last):
File "./utils/cmpcodesize/cmpcodesize.py", line 6, in <module>
cmpcodesize.main()
AttributeError: 'module' object has no attribute 'main'
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.
The error could be fixed with a corresponding change to utils/cmpcodesize/cmpcodesize.py
:
diff --git a/utils/cmpcodesize/cmpcodesize.py b/utils/cmpcodesize/cmpcodesize.py
index 0390af7..eb9ecfa 100755
--- a/utils/cmpcodesize/cmpcodesize.py
+++ b/utils/cmpcodesize/cmpcodesize.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import cmpcodesize
+from cmpcodesize.main import main
if __name__ == '__main__':
- cmpcodesize.main()
+ main()
Which I wouldn't be opposed to. I wrote it this way because it mirrored the structure of llvm/utils/lit/lit.py.
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.
I'm curious, though: is it bad form to use this style of relative imports? If so, should a corresponding change be proposed to llvm/utils/lit as well?
/cc @ddunbar, author of lit
from SwiftBuildSupport import check_call, get_all_preset_names | ||
from SwiftBuildSupport import get_preset_options, HOME, print_with_argv0 | ||
from SwiftBuildSupport import quote_shell_command, SWIFT_BUILD_ROOT | ||
from SwiftBuildSupport import SWIFT_SOURCE_ROOT |
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.
nit: How about instead:
from SwiftBuildSupport import (
SWIFT_SOURCE_ROOT,
SWIFT_BUILD_ROOT,
print_with_argv0,
quote_shell_command,
check_call,
get_preset_options,
get_all_preset_names
)
I've seen this import
style suggested in a few style guides:
@modocache Thanks a lot for reviewing! I've updated accordingly. Please take a look at the updated code :-) |
@practicalswift I think this is an improvement, but I would recommend to switch to the code formatting suggested by @modocache: from SwiftBuildSupport import (
SWIFT_SOURCE_ROOT,
SWIFT_BUILD_ROOT,
print_with_argv0,
quote_shell_command,
check_call,
get_preset_options,
get_all_preset_names
) since we normally don't do "endline" layout in Python code. |
@gribozavr Fixed :-) |
Looks great! Thanks for updating. I'll follow up with @ddunbar about how lit is structured. |
[Python] Use explicit imports
No description provided.