Fix invalid type hints in ansible-test.

This commit is contained in:
Matt Clay 2019-07-11 13:03:49 -07:00
parent b91a90a274
commit bc3a599678
18 changed files with 108 additions and 66 deletions

View file

@ -18,8 +18,10 @@ def main():
args += ['-m', 'coverage.__main__', 'run', '--rcfile', coverage_config] args += ['-m', 'coverage.__main__', 'run', '--rcfile', coverage_config]
else: else:
if sys.version_info >= (3, 4): if sys.version_info >= (3, 4):
# noinspection PyUnresolvedReferences
import importlib.util import importlib.util
# noinspection PyUnresolvedReferences
found = bool(importlib.util.find_spec('coverage')) found = bool(importlib.util.find_spec('coverage'))
else: else:
import imp import imp

View file

@ -170,6 +170,7 @@ def parse_args():
action='store_true', action='store_true',
help='run ansible commands in debug mode') help='run ansible commands in debug mode')
# noinspection PyTypeChecker
common.add_argument('--truncate', common.add_argument('--truncate',
dest='truncate', dest='truncate',
metavar='COLUMNS', metavar='COLUMNS',
@ -527,6 +528,7 @@ def parse_args():
action='store_true', action='store_true',
help='dump environment to disk') help='dump environment to disk')
# noinspection PyTypeChecker
env.add_argument('--timeout', env.add_argument('--timeout',
type=int, type=int,
metavar='MINUTES', metavar='MINUTES',
@ -749,6 +751,7 @@ def add_extra_docker_options(parser, integration=True):
action='store_true', action='store_true',
help='run docker container in privileged mode') help='run docker container in privileged mode')
# noinspection PyTypeChecker
docker.add_argument('--docker-memory', docker.add_argument('--docker-memory',
help='memory limit for docker in bytes', type=int) help='memory limit for docker in bytes', type=int)

View file

@ -79,7 +79,7 @@ class EnvironmentConfig(CommonConfig):
self.python_interpreter = args.python_interpreter self.python_interpreter = args.python_interpreter
self.delegate = self.tox or self.docker or self.remote self.delegate = self.tox or self.docker or self.remote
self.delegate_args = [] # type: list[str] self.delegate_args = [] # type: t.List[str]
if self.delegate: if self.delegate:
self.requirements = True self.requirements = True
@ -118,9 +118,9 @@ class TestConfig(EnvironmentConfig):
self.coverage_label = args.coverage_label # type: str self.coverage_label = args.coverage_label # type: str
self.coverage_check = args.coverage_check # type: bool self.coverage_check = args.coverage_check # type: bool
self.coverage_config_base_path = None # type: t.Optional[str] self.coverage_config_base_path = None # type: t.Optional[str]
self.include = args.include or [] # type: list [str] self.include = args.include or [] # type: t.List[str]
self.exclude = args.exclude or [] # type: list [str] self.exclude = args.exclude or [] # type: t.List[str]
self.require = args.require or [] # type: list [str] self.require = args.require or [] # type: t.List[str]
self.changed = args.changed # type: bool self.changed = args.changed # type: bool
self.tracked = args.tracked # type: bool self.tracked = args.tracked # type: bool
@ -129,7 +129,7 @@ class TestConfig(EnvironmentConfig):
self.staged = args.staged # type: bool self.staged = args.staged # type: bool
self.unstaged = args.unstaged # type: bool self.unstaged = args.unstaged # type: bool
self.changed_from = args.changed_from # type: str self.changed_from = args.changed_from # type: str
self.changed_path = args.changed_path # type: list [str] self.changed_path = args.changed_path # type: t.List[str]
self.lint = args.lint if 'lint' in args else False # type: bool self.lint = args.lint if 'lint' in args else False # type: bool
self.junit = args.junit if 'junit' in args else False # type: bool self.junit = args.junit if 'junit' in args else False # type: bool
@ -164,8 +164,8 @@ class SanityConfig(TestConfig):
""" """
super(SanityConfig, self).__init__(args, 'sanity') super(SanityConfig, self).__init__(args, 'sanity')
self.test = args.test # type: list [str] self.test = args.test # type: t.List[str]
self.skip_test = args.skip_test # type: list [str] self.skip_test = args.skip_test # type: t.List[str]
self.list_tests = args.list_tests # type: bool self.list_tests = args.list_tests # type: bool
self.allow_disabled = args.allow_disabled # type: bool self.allow_disabled = args.allow_disabled # type: bool
@ -232,7 +232,7 @@ class WindowsIntegrationConfig(IntegrationConfig):
""" """
super(WindowsIntegrationConfig, self).__init__(args, 'windows-integration') super(WindowsIntegrationConfig, self).__init__(args, 'windows-integration')
self.windows = args.windows # type: list [str] self.windows = args.windows # type: t.List[str]
if self.windows: if self.windows:
self.allow_destructive = True self.allow_destructive = True
@ -247,7 +247,7 @@ class NetworkIntegrationConfig(IntegrationConfig):
""" """
super(NetworkIntegrationConfig, self).__init__(args, 'network-integration') super(NetworkIntegrationConfig, self).__init__(args, 'network-integration')
self.platform = args.platform # type: list [str] self.platform = args.platform # type: t.List[str]
self.inventory = args.inventory # type: str self.inventory = args.inventory # type: str
self.testcase = args.testcase # type: str self.testcase = args.testcase # type: str
@ -278,7 +278,7 @@ class CoverageConfig(EnvironmentConfig):
""" """
super(CoverageConfig, self).__init__(args, 'coverage') super(CoverageConfig, self).__init__(args, 'coverage')
self.group_by = frozenset(args.group_by) if 'group_by' in args and args.group_by else set() # type: frozenset [str] self.group_by = frozenset(args.group_by) if 'group_by' in args and args.group_by else set() # type: t.FrozenSet[str]
self.all = args.all if 'all' in args else False # type: bool self.all = args.all if 'all' in args else False # type: bool
self.stub = args.stub if 'stub' in args else False # type: bool self.stub = args.stub if 'stub' in args else False # type: bool

View file

@ -51,6 +51,7 @@ def extract_csharp_module_utils_imports(path, module_utils, is_pure_csharp):
"""Return a list of module_utils imports found in the specified source file. """Return a list of module_utils imports found in the specified source file.
:type path: str :type path: str
:type module_utils: set[str] :type module_utils: set[str]
:type is_pure_csharp: bool
:rtype: set[str] :rtype: set[str]
""" """
imports = set() imports = set()

View file

@ -5,6 +5,8 @@ import re
import textwrap import textwrap
import traceback import traceback
import lib.types as t
from lib.util import ( from lib.util import (
ApplicationError, ApplicationError,
) )
@ -27,7 +29,7 @@ class FileDiff(object):
""" """
self.old = DiffSide(old_path, new=False) self.old = DiffSide(old_path, new=False)
self.new = DiffSide(new_path, new=True) self.new = DiffSide(new_path, new=True)
self.headers = [] # list [str] self.headers = [] # type: t.List[str]
self.binary = False self.binary = False
def append_header(self, line): def append_header(self, line):
@ -57,9 +59,9 @@ class DiffSide(object):
self.eof_newline = True self.eof_newline = True
self.exists = True self.exists = True
self.lines = [] # type: list [tuple[int, str]] self.lines = [] # type: t.List[t.Tuple[int, str]]
self.lines_and_context = [] # type: list [tuple[int, str]] self.lines_and_context = [] # type: t.List[t.Tuple[int, str]]
self.ranges = [] # type: list [tuple[int, int]] self.ranges = [] # type: t.List[t.Tuple[int, int]]
self._next_line_number = 0 self._next_line_number = 0
self._lines_remaining = 0 self._lines_remaining = 0
@ -138,13 +140,13 @@ class DiffParser(object):
:type lines: list[str] :type lines: list[str]
""" """
self.lines = lines self.lines = lines
self.files = [] # type: list [FileDiff] self.files = [] # type: t.List[FileDiff]
self.action = self.process_start self.action = self.process_start
self.line_number = 0 self.line_number = 0
self.previous_line = None # type: str self.previous_line = None # type: t.Optional[str]
self.line = None # type: str self.line = None # type: t.Optional[str]
self.file = None # type: FileDiff self.file = None # type: t.Optional[FileDiff]
for self.line in self.lines: for self.line in self.lines:
self.line_number += 1 self.line_number += 1

View file

@ -226,8 +226,8 @@ def docker_exec(args, container_id, cmd, options=None, capture=False, stdin=None
:type cmd: list[str] :type cmd: list[str]
:type options: list[str] | None :type options: list[str] | None
:type capture: bool :type capture: bool
:type stdin: file | None :type stdin: BinaryIO | None
:type stdout: file | None :type stdout: BinaryIO | None
:rtype: str | None, str | None :rtype: str | None, str | None
""" """
if not options: if not options:

View file

@ -304,6 +304,7 @@ def get_git_details(args):
return git_details return git_details
# noinspection PyUnusedLocal
def get_merged_commit(args, commit): # pylint: disable=unused-argument def get_merged_commit(args, commit): # pylint: disable=unused-argument
""" """
:type args: CommonConfig :type args: CommonConfig

View file

@ -18,6 +18,8 @@ import random
import string import string
import shutil import shutil
import lib.types as t
import lib.pytar import lib.pytar
import lib.thread import lib.thread
@ -358,7 +360,7 @@ def command_network_integration(args):
all_targets = tuple(walk_network_integration_targets(include_hidden=True)) all_targets = tuple(walk_network_integration_targets(include_hidden=True))
internal_targets = command_integration_filter(args, all_targets, init_callback=network_init) internal_targets = command_integration_filter(args, all_targets, init_callback=network_init)
instances = [] # type: list [lib.thread.WrappedThread] instances = [] # type: t.List[lib.thread.WrappedThread]
if args.platform: if args.platform:
get_python_path(args, args.python_executable) # initialize before starting threads get_python_path(args, args.python_executable) # initialize before starting threads
@ -411,9 +413,9 @@ def network_init(args, internal_targets):
if args.metadata.instance_config is not None: if args.metadata.instance_config is not None:
return return
platform_targets = set(a for t in internal_targets for a in t.aliases if a.startswith('network/')) platform_targets = set(a for target in internal_targets for a in target.aliases if a.startswith('network/'))
instances = [] # type: list [lib.thread.WrappedThread] instances = [] # type: t.List[lib.thread.WrappedThread]
# generate an ssh key (if needed) up front once, instead of for each instance # generate an ssh key (if needed) up front once, instead of for each instance
SshKey(args) SshKey(args)
@ -523,7 +525,7 @@ def command_windows_integration(args):
all_targets = tuple(walk_windows_integration_targets(include_hidden=True)) all_targets = tuple(walk_windows_integration_targets(include_hidden=True))
internal_targets = command_integration_filter(args, all_targets, init_callback=windows_init) internal_targets = command_integration_filter(args, all_targets, init_callback=windows_init)
instances = [] # type: list [lib.thread.WrappedThread] instances = [] # type: t.List[lib.thread.WrappedThread]
pre_target = None pre_target = None
post_target = None post_target = None
httptester_id = None httptester_id = None
@ -553,7 +555,7 @@ def command_windows_integration(args):
with open(filename, 'w') as inventory_fd: with open(filename, 'w') as inventory_fd:
inventory_fd.write(inventory) inventory_fd.write(inventory)
use_httptester = args.httptester and any('needs/httptester/' in t.aliases for t in internal_targets) use_httptester = args.httptester and any('needs/httptester/' in target.aliases for target in internal_targets)
# if running under Docker delegation, the httptester may have already been started # if running under Docker delegation, the httptester may have already been started
docker_httptester = bool(os.environ.get("HTTPTESTER", False)) docker_httptester = bool(os.environ.get("HTTPTESTER", False))
@ -638,7 +640,7 @@ def windows_init(args, internal_targets): # pylint: disable=locally-disabled, u
if args.metadata.instance_config is not None: if args.metadata.instance_config is not None:
return return
instances = [] # type: list [lib.thread.WrappedThread] instances = [] # type: t.List[lib.thread.WrappedThread]
for version in args.windows: for version in args.windows:
instance = lib.thread.WrappedThread(functools.partial(windows_start, args, version)) instance = lib.thread.WrappedThread(functools.partial(windows_start, args, version))
@ -765,7 +767,7 @@ def command_integration_filter(args, targets, init_callback=None):
if not internal_targets: if not internal_targets:
raise AllTargetsSkipped() raise AllTargetsSkipped()
if args.start_at and not any(t.name == args.start_at for t in internal_targets): if args.start_at and not any(target.name == args.start_at for target in internal_targets):
raise ApplicationError('Start at target matches nothing: %s' % args.start_at) raise ApplicationError('Start at target matches nothing: %s' % args.start_at)
if init_callback: if init_callback:
@ -835,7 +837,7 @@ def command_integration_filtered(args, targets, all_targets, inventory_path, pre
results = {} results = {}
current_environment = None # type: EnvironmentDescription | None current_environment = None # type: t.Optional[EnvironmentDescription]
# common temporary directory path that will be valid on both the controller and the remote # common temporary directory path that will be valid on both the controller and the remote
# it must be common because it will be referenced in environment variables that are shared across multiple hosts # it must be common because it will be referenced in environment variables that are shared across multiple hosts
@ -1944,7 +1946,7 @@ class EnvironmentDescription(object):
def get_version(command, warnings): def get_version(command, warnings):
""" """
:type command: list[str] :type command: list[str]
:type warnings: list[str] :type warnings: list[text]
:rtype: list[str] :rtype: list[str]
""" """
try: try:

View file

@ -113,6 +113,8 @@ class HttpClient(object):
6, # CURLE_COULDNT_RESOLVE_HOST 6, # CURLE_COULDNT_RESOLVE_HOST
) )
stdout = ''
while True: while True:
attempts += 1 attempts += 1

View file

@ -3,6 +3,8 @@ from __future__ import absolute_import, print_function
import json import json
import lib.types as t
from lib.util import ( from lib.util import (
display, display,
is_shippable, is_shippable,
@ -18,10 +20,10 @@ class Metadata(object):
"""Metadata object for passing data to delegated tests.""" """Metadata object for passing data to delegated tests."""
def __init__(self): def __init__(self):
"""Initialize metadata.""" """Initialize metadata."""
self.changes = {} # type: dict [str, tuple[tuple[int, int]] self.changes = {} # type: t.Dict[str, t.Tuple[t.Tuple[int, int]]]
self.cloud_config = None # type: dict [str, str] self.cloud_config = None # type: t.Optional[t.Dict[str, str]]
self.instance_config = None # type: list[dict[str, str]] self.instance_config = None # type: t.Optional[t.List[t.Dict[str, str]]]
self.change_description = None # type: ChangeDescription self.change_description = None # type: t.Optional[ChangeDescription]
if is_shippable(): if is_shippable():
self.ci_provider = 'shippable' self.ci_provider = 'shippable'
@ -33,7 +35,7 @@ class Metadata(object):
:type diff: list[str] | None :type diff: list[str] | None
""" """
patches = parse_diff(diff) patches = parse_diff(diff)
patches = sorted(patches, key=lambda k: k.new.path) # type: list [FileDiff] patches = sorted(patches, key=lambda k: k.new.path) # type: t.List[FileDiff]
self.changes = dict((patch.new.path, tuple(patch.new.ranges)) for patch in patches) self.changes = dict((patch.new.path, tuple(patch.new.ranges)) for patch in patches)
@ -103,11 +105,11 @@ class ChangeDescription(object):
"""Description of changes.""" """Description of changes."""
def __init__(self): def __init__(self):
self.command = '' # type: str self.command = '' # type: str
self.changed_paths = [] # type: list[str] self.changed_paths = [] # type: t.List[str]
self.deleted_paths = [] # type: list[str] self.deleted_paths = [] # type: t.List[str]
self.regular_command_targets = {} # type: dict[str, list[str]] self.regular_command_targets = {} # type: t.Dict[str, t.List[str]]
self.focused_command_targets = {} # type: dict[str, list[str]] self.focused_command_targets = {} # type: t.Dict[str, t.List[str]]
self.no_integration_paths = [] # type: list[str] self.no_integration_paths = [] # type: t.List[str]
@property @property
def targets(self): def targets(self):

View file

@ -8,6 +8,8 @@ import os
import re import re
import sys import sys
import lib.types as t
from lib.util import ( from lib.util import (
ApplicationError, ApplicationError,
SubprocessError, SubprocessError,
@ -76,16 +78,16 @@ def command_sanity(args):
tests = sanity_get_tests() tests = sanity_get_tests()
if args.test: if args.test:
tests = [t for t in tests if t.name in args.test] tests = [target for target in tests if target.name in args.test]
else: else:
disabled = [t.name for t in tests if not t.enabled and not args.allow_disabled] disabled = [target.name for target in tests if not target.enabled and not args.allow_disabled]
tests = [t for t in tests if t.enabled or args.allow_disabled] tests = [target for target in tests if target.enabled or args.allow_disabled]
if disabled: if disabled:
display.warning('Skipping tests disabled by default without --allow-disabled: %s' % ', '.join(sorted(disabled))) display.warning('Skipping tests disabled by default without --allow-disabled: %s' % ', '.join(sorted(disabled)))
if args.skip_test: if args.skip_test:
tests = [t for t in tests if t.name not in args.skip_test] tests = [target for target in tests if target.name not in args.skip_test]
total = 0 total = 0
failed = [] failed = []
@ -383,7 +385,7 @@ SANITY_TESTS = (
def sanity_init(): def sanity_init():
"""Initialize full sanity test list (includes code-smell scripts determined at runtime).""" """Initialize full sanity test list (includes code-smell scripts determined at runtime)."""
import_plugins('sanity') import_plugins('sanity')
sanity_plugins = {} # type: dict[str, type] sanity_plugins = {} # type: t.Dict[str, type]
load_plugins(SanityFunc, sanity_plugins) load_plugins(SanityFunc, sanity_plugins)
sanity_tests = tuple([plugin() for plugin in sanity_plugins.values()]) sanity_tests = tuple([plugin() for plugin in sanity_plugins.values()])
global SANITY_TESTS # pylint: disable=locally-disabled, global-statement global SANITY_TESTS # pylint: disable=locally-disabled, global-statement

View file

@ -6,6 +6,8 @@ import textwrap
import re import re
import os import os
import lib.types as t
from lib.sanity import ( from lib.sanity import (
SanitySingleVersion, SanitySingleVersion,
SanityMessage, SanityMessage,
@ -80,8 +82,8 @@ class IntegrationAliasesTest(SanitySingleVersion):
def __init__(self): def __init__(self):
super(IntegrationAliasesTest, self).__init__() super(IntegrationAliasesTest, self).__init__()
self._shippable_yml_lines = [] # type: list[str] self._shippable_yml_lines = [] # type: t.List[str]
self._shippable_test_groups = {} # type: dict[str, set[int]] self._shippable_test_groups = {} # type: t.Dict[str, t.Set[int]]
@property @property
def shippable_yml_lines(self): def shippable_yml_lines(self):
@ -231,9 +233,9 @@ class IntegrationAliasesTest(SanitySingleVersion):
:type find: str :type find: str
:rtype: list[SanityMessage] :rtype: list[SanityMessage]
""" """
all_paths = set(t.path for t in targets) all_paths = set(target.path for target in targets)
supported_paths = set(t.path for t in filter_targets(targets, [find], include=True, directories=False, errors=False)) supported_paths = set(target.path for target in filter_targets(targets, [find], include=True, directories=False, errors=False))
unsupported_paths = set(t.path for t in filter_targets(targets, [self.UNSUPPORTED], include=True, directories=False, errors=False)) unsupported_paths = set(target.path for target in filter_targets(targets, [self.UNSUPPORTED], include=True, directories=False, errors=False))
unassigned_paths = all_paths - supported_paths - unsupported_paths unassigned_paths = all_paths - supported_paths - unsupported_paths
conflicting_paths = supported_paths & unsupported_paths conflicting_paths = supported_paths & unsupported_paths
@ -259,8 +261,8 @@ class IntegrationAliasesTest(SanitySingleVersion):
integration_targets = list(walk_integration_targets()) integration_targets = list(walk_integration_targets())
module_targets = list(walk_module_targets()) module_targets = list(walk_module_targets())
integration_targets_by_name = dict((t.name, t) for t in integration_targets) integration_targets_by_name = dict((target.name, target) for target in integration_targets)
module_names_by_path = dict((t.path, t.module) for t in module_targets) module_names_by_path = dict((target.path, target.module) for target in module_targets)
disabled_targets = [] disabled_targets = []
unstable_targets = [] unstable_targets = []

View file

@ -6,6 +6,8 @@ import json
import os import os
import re import re
import lib.types as t
from lib.sanity import ( from lib.sanity import (
SanitySingleVersion, SanitySingleVersion,
SanityMessage, SanityMessage,
@ -50,7 +52,7 @@ class PslintTest(SanitySingleVersion):
invalid_ignores = [] invalid_ignores = []
ignore_entries = read_lines_without_comments(PSLINT_IGNORE_PATH, optional=True) ignore_entries = read_lines_without_comments(PSLINT_IGNORE_PATH, optional=True)
ignore = collections.defaultdict(dict) ignore = collections.defaultdict(dict) # type: t.Dict[str, t.Dict[str, int]]
line = 0 line = 0
for ignore_entry in ignore_entries: for ignore_entry in ignore_entries:
@ -85,6 +87,8 @@ class PslintTest(SanitySingleVersion):
['test/sanity/pslint/pslint.ps1'] + paths ['test/sanity/pslint/pslint.ps1'] + paths
] ]
stdout = ''
for cmd in cmds: for cmd in cmds:
try: try:
stdout, stderr = run_command(args, cmd, capture=True) stdout, stderr = run_command(args, cmd, capture=True)
@ -131,7 +135,7 @@ class PslintTest(SanitySingleVersion):
for error in errors: for error in errors:
if error.code in ignore[error.path]: if error.code in ignore[error.path]:
ignore[error.path][error.code] = None # error ignored, clear line number of ignore entry to track usage ignore[error.path][error.code] = 0 # error ignored, clear line number of ignore entry to track usage
else: else:
filtered.append(error) # error not ignored filtered.append(error) # error not ignored

View file

@ -26,7 +26,6 @@ from lib.util import (
) )
from lib.util_common import ( from lib.util_common import (
intercept_command,
run_command, run_command,
) )
@ -80,7 +79,7 @@ class PylintTest(SanitySingleVersion):
supported_versions = set([v.split('.')[0] for v in supported_versions]) | supported_versions supported_versions = set([v.split('.')[0] for v in supported_versions]) | supported_versions
ignore_entries = read_lines_without_comments(PYLINT_IGNORE_PATH, optional=True) ignore_entries = read_lines_without_comments(PYLINT_IGNORE_PATH, optional=True)
ignore = collections.defaultdict(dict) ignore = collections.defaultdict(dict) # type: t.Dict[str, t.Dict[str, int]]
line = 0 line = 0
for ignore_entry in ignore_entries: for ignore_entry in ignore_entries:
@ -207,7 +206,7 @@ class PylintTest(SanitySingleVersion):
for error in errors: for error in errors:
if error.code in ignore[error.path]: if error.code in ignore[error.path]:
ignore[error.path][error.code] = None # error ignored, clear line number of ignore entry to track usage ignore[error.path][error.code] = 0 # error ignored, clear line number of ignore entry to track usage
else: else:
filtered.append(error) # error not ignored filtered.append(error) # error not ignored

View file

@ -5,6 +5,8 @@ import collections
import json import json
import os import os
import lib.types as t
from lib.sanity import ( from lib.sanity import (
SanitySingleVersion, SanitySingleVersion,
SanityMessage, SanityMessage,
@ -78,7 +80,7 @@ class ValidateModulesTest(SanitySingleVersion):
invalid_ignores = [] invalid_ignores = []
ignore_entries = read_lines_without_comments(VALIDATE_IGNORE_PATH, optional=True) ignore_entries = read_lines_without_comments(VALIDATE_IGNORE_PATH, optional=True)
ignore = collections.defaultdict(dict) ignore = collections.defaultdict(dict) # type: t.Dict[str, t.Dict[str, int]]
line = 0 line = 0
for ignore_entry in ignore_entries: for ignore_entry in ignore_entries:
@ -137,7 +139,7 @@ class ValidateModulesTest(SanitySingleVersion):
for error in errors: for error in errors:
if error.code in ignore[error.path]: if error.code in ignore[error.path]:
ignore[error.path][error.code] = None # error ignored, clear line number of ignore entry to track usage ignore[error.path][error.code] = 0 # error ignored, clear line number of ignore entry to track usage
else: else:
filtered.append(error) # error not ignored filtered.append(error) # error not ignored

View file

@ -29,14 +29,16 @@ except ImportError:
try: try:
# noinspection PyCompatibility # noinspection PyCompatibility
from ConfigParser import SafeConfigParser as ConfigParser from configparser import ConfigParser
except ImportError: except ImportError:
# noinspection PyCompatibility # noinspection PyCompatibility
from configparser import ConfigParser from ConfigParser import SafeConfigParser as ConfigParser
try: try:
# noinspection PyProtectedMember
from shlex import quote as cmd_quote from shlex import quote as cmd_quote
except ImportError: except ImportError:
# noinspection PyProtectedMember
from pipes import quote as cmd_quote from pipes import quote as cmd_quote
import lib.types as t import lib.types as t
@ -47,11 +49,12 @@ except AttributeError:
C = None C = None
DOCKER_COMPLETION = {} # type: dict[str, dict[str, str]] DOCKER_COMPLETION = {} # type: t.Dict[str, t.Dict[str, str]]
REMOTE_COMPLETION = {} # type: dict[str, dict[str, str]] REMOTE_COMPLETION = {} # type: t.Dict[str, t.Dict[str, str]]
PYTHON_PATHS = {} # type: dict[str, str] PYTHON_PATHS = {} # type: t.Dict[str, str]
try: try:
# noinspection PyUnresolvedReferences
MAXFD = subprocess.MAXFD MAXFD = subprocess.MAXFD
except AttributeError: except AttributeError:
MAXFD = -1 MAXFD = -1
@ -776,9 +779,12 @@ def load_plugins(base_type, database): # type: (t.Type[C], t.Dict[str, t.Type[C
def load_module(path, name): # type: (str, str) -> None def load_module(path, name): # type: (str, str) -> None
"""Load a Python module using the given name and path.""" """Load a Python module using the given name and path."""
if sys.version_info >= (3, 4): if sys.version_info >= (3, 4):
# noinspection PyUnresolvedReferences
import importlib.util import importlib.util
# noinspection PyUnresolvedReferences
spec = importlib.util.spec_from_file_location(name, path) spec = importlib.util.spec_from_file_location(name, path)
# noinspection PyUnresolvedReferences
module = importlib.util.module_from_spec(spec) module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module) spec.loader.exec_module(module)

View file

@ -75,12 +75,14 @@ def parse_args():
const='yes', const='yes',
default='auto') default='auto')
# noinspection PyTypeChecker
parser.add_argument('--tries', parser.add_argument('--tries',
metavar='TRIES', metavar='TRIES',
type=int, type=int,
default=3, default=3,
help='number of tries to execute command (default: %(default)s)') help='number of tries to execute command (default: %(default)s)')
# noinspection PyTypeChecker
parser.add_argument('--sleep', parser.add_argument('--sleep',
metavar='SECONDS', metavar='SECONDS',
type=int, type=int,

View file

@ -22,6 +22,10 @@ from lib.util import (
MissingEnvironmentVariable, MissingEnvironmentVariable,
) )
from lib.util_common import (
CommonConfig,
)
try: try:
import argcomplete import argcomplete
@ -33,15 +37,21 @@ def main():
"""Main program function.""" """Main program function."""
try: try:
args = parse_args() args = parse_args()
display.verbosity = args.verbosity args.debug = False
display.color = args.color args.truncate = False
args.redact = False
config = CommonConfig(args, '')
display.verbosity = config.verbosity
display.color = config.color
try: try:
run_id = os.environ['SHIPPABLE_BUILD_ID'] run_id = os.environ['SHIPPABLE_BUILD_ID']
except KeyError as ex: except KeyError as ex:
raise MissingEnvironmentVariable(ex.args[0]) raise MissingEnvironmentVariable(ex.args[0])
client = HttpClient(args) client = HttpClient(config)
response = client.get('https://api.shippable.com/jobs?runIds=%s' % run_id) response = client.get('https://api.shippable.com/jobs?runIds=%s' % run_id)
jobs = response.json() jobs = response.json()