Skip to content

[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

Merged
merged 1 commit into from
Dec 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion tools/SourceKit/bindings/python/sourcekitd/capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@
#
#===------------------------------------------------------------------------===#

from ctypes import *
from ctypes import (
CFUNCTYPE,
POINTER,
Structure,
addressof,
c_bool,
c_char_p,
c_int,
c_int64,
c_size_t,
c_uint64,
c_void_p,
cdll,
py_object,
string_at,
)

# ctypes doesn't implicitly convert c_void_p to the appropriate wrapper
# object. This is a problem, because it means that from_parameter will see an
Expand Down
12 changes: 10 additions & 2 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ import textwrap

sys.path.append(os.path.dirname(__file__))

from SwiftBuildSupport import *

from SwiftBuildSupport import (
HOME,
SWIFT_BUILD_ROOT,
SWIFT_SOURCE_ROOT,
check_call,
get_all_preset_names,
get_preset_options,
print_with_argv0,
quote_shell_command,
)

# Main entry point for the preset mode.
def main_preset():
Expand Down
4 changes: 2 additions & 2 deletions utils/cmpcodesize/cmpcodesize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import cmpcodesize
from cmpcodesize.main import main

if __name__ == '__main__':
cmpcodesize.main()
main()
3 changes: 0 additions & 3 deletions utils/cmpcodesize/cmpcodesize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from .main import main

__author__ = 'Brian Gesiak'
__email__ = '[email protected]'
__versioninfo__ = (0, 1, 0)
Copy link
Contributor

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'

Copy link
Contributor

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.

Copy link
Contributor

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

Expand Down
17 changes: 15 additions & 2 deletions utils/pygments/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@

import re

from pygments.lexer import RegexLexer, include, bygroups
from pygments.token import *
from pygments.lexer import (
Comment,
Generic,
Keyword,
Name,
Number,
Operator,
Punctuation,
RegexLexer,
String,
Text,
Whitespace,
bygroups,
include,
)

__all__ = ['SwiftLexer', 'SwiftConsoleLexer']

Expand Down
2 changes: 1 addition & 1 deletion utils/recursive-lipo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import filecmp
import os
import shutil

from SwiftBuildSupport import *
from SwiftBuildSupport import check_call

def merge_file_lists(src_root_dirs, skip_files, skip_subpaths):
"""Merges the file lists recursively from all src_root_dirs supplied,
Expand Down
8 changes: 6 additions & 2 deletions utils/update-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ import sys

sys.path.append(os.path.dirname(__file__))

from SwiftBuildSupport import *

from SwiftBuildSupport import (
SWIFT_SOURCE_ROOT,
WorkingDirectory,
check_call,
check_output,
)

def update_git_svn(repo_path):
with WorkingDirectory(repo_path):
Expand Down