mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Minor Python tidies in swift-api-dump.py
* Don't override the name of the builtin `str` * Use raw strings for regex matches * Replace a couple of unused variables by `_` * Remove an unused argument from `create_dump_module_api_args` (the arg is never used in the body of the function, and it's only called from this file).
This commit is contained in:
@@ -119,7 +119,7 @@ def run_command(args):
|
||||
def collect_submodules(common_args, module):
|
||||
# Execute swift-ide-test to print the interface.
|
||||
my_args = ['-module-print-submodules', '-module-to-print=%s' % (module)]
|
||||
(exitcode, out, err) = run_command(common_args + my_args)
|
||||
(exitcode, out, _) = run_command(common_args + my_args)
|
||||
if exitcode != 0:
|
||||
print(
|
||||
'error: submodule collection failed for module %s with error %d' %
|
||||
@@ -127,7 +127,7 @@ def collect_submodules(common_args, module):
|
||||
return ()
|
||||
|
||||
# Find all of the submodule imports.
|
||||
import_matcher = re.compile('.*import\s+%s\.([A-Za-z_0-9.]+)' % (module))
|
||||
import_matcher = re.compile(r'.*import\s+%s\.([A-Za-z_0-9.]+)' % (module))
|
||||
submodules = set()
|
||||
for line in out.splitlines():
|
||||
match = import_matcher.match(line)
|
||||
@@ -140,10 +140,10 @@ def collect_submodules(common_args, module):
|
||||
|
||||
|
||||
def print_command(cmd, outfile=""):
|
||||
str = " ".join(cmd)
|
||||
retstr = " ".join(cmd)
|
||||
if outfile != "":
|
||||
str += " > " + outfile
|
||||
print(str)
|
||||
retstr += " > " + outfile
|
||||
print(retstr)
|
||||
|
||||
# Dump the API for the given module.
|
||||
|
||||
@@ -200,7 +200,7 @@ def pretty_sdk_name(sdk):
|
||||
|
||||
|
||||
def collect_frameworks(sdk):
|
||||
(exitcode, sdk_path, err) = run_command(
|
||||
(exitcode, sdk_path, _) = run_command(
|
||||
["xcrun", "--show-sdk-path", "-sdk", sdk])
|
||||
if exitcode != 0:
|
||||
print('error: framework collection failed to find SDK path for %s '
|
||||
@@ -208,7 +208,7 @@ def collect_frameworks(sdk):
|
||||
return ()
|
||||
sdk_path = sdk_path.rstrip()
|
||||
|
||||
(exitcode, sdk_version, err) = run_command(
|
||||
(exitcode, sdk_version, _) = run_command(
|
||||
["xcrun", "--show-sdk-version", "-sdk", sdk])
|
||||
if exitcode != 0:
|
||||
print('error: framework collection failed to find SDK version for %s '
|
||||
@@ -221,7 +221,7 @@ def collect_frameworks(sdk):
|
||||
|
||||
# Collect all of the framework names
|
||||
frameworks_dir = '%s/System/Library/Frameworks' % sdk_path
|
||||
framework_matcher = re.compile('([A-Za-z_0-9.]+)\.framework')
|
||||
framework_matcher = re.compile(r'([A-Za-z_0-9.]+)\.framework')
|
||||
frameworks = set()
|
||||
for entry in os.listdir(frameworks_dir):
|
||||
match = framework_matcher.match(entry)
|
||||
@@ -234,8 +234,7 @@ def collect_frameworks(sdk):
|
||||
|
||||
|
||||
def create_dump_module_api_args(cmd_common, cmd_extra_args, sdk, module,
|
||||
target, source_filename, output_dir, quiet,
|
||||
verbose):
|
||||
target, output_dir, quiet, verbose):
|
||||
|
||||
# Determine the SDK root and collect the set of frameworks.
|
||||
(frameworks, sdk_root) = collect_frameworks(sdk)
|
||||
@@ -302,7 +301,7 @@ def main():
|
||||
for sdk in args.sdk:
|
||||
jobs = jobs + create_dump_module_api_args(
|
||||
cmd_common, extra_args, sdk, args.module,
|
||||
args.target, source_filename, args.output_dir,
|
||||
args.target, args.output_dir,
|
||||
args.quiet, args.verbose)
|
||||
|
||||
# Execute the API dumps
|
||||
|
||||
Reference in New Issue
Block a user