SERVER-67993 fix 4.4 pylinters

This commit is contained in:
Daniel Moody 2022-07-12 13:38:18 -05:00 committed by Evergreen Agent
parent fafbdd8cc4
commit 1919b5797c
48 changed files with 165 additions and 157 deletions

View File

@ -5,12 +5,11 @@ import logging
import os
import sys
from typing import Any, Dict, List
from git import Repo
from shrub.v2 import ShrubProject, BuildVariant, ExistingTask
import click
from evergreen.api import RetryingEvergreenApi, EvergreenApi
from git import Repo
from shrub.v2 import ShrubProject, BuildVariant, ExistingTask
# Get relative imports to work when the package is not installed on the PYTHONPATH.
if __name__ == "__main__" and __package__ is None:

View File

@ -14,13 +14,15 @@ from typing import Optional, Set, Tuple, List, Dict
import click
import requests
import yaml
from evergreen.api import RetryingEvergreenApi, EvergreenApi
from git import Repo
import structlog
from structlog.stdlib import LoggerFactory
from shrub.v2 import Task, TaskDependency, BuildVariant, ShrubProject, ExistingTask
from evergreen.api import RetryingEvergreenApi, EvergreenApi
# Get relative imports to work when the package is not installed on the PYTHONPATH.
if __name__ == "__main__" and __package__ is None:
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@ -256,8 +258,9 @@ def find_excludes(selector_file: str) -> Tuple[List, List, List]:
try:
js_test = yml["selector"]["js_test"]
except KeyError:
raise Exception(f"The selector file {selector_file} is missing the 'selector.js_test' key")
except KeyError as exc:
raise Exception(
f"The selector file {selector_file} is missing the 'selector.js_test' key") from exc
return (default_if_none(js_test.get("exclude_suites"), []),
default_if_none(js_test.get("exclude_tasks"), []),

View File

@ -6,12 +6,14 @@ import sys
from typing import Dict
import click
from evergreen.api import EvergreenApi
from git import Repo
from shrub.v2 import BuildVariant, ExistingTask, ShrubProject
import structlog
from structlog.stdlib import LoggerFactory
from evergreen.api import EvergreenApi
import buildscripts.evergreen_gen_multiversion_tests as gen_multiversion
import buildscripts.evergreen_generate_resmoke_tasks as gen_resmoke
from buildscripts.burn_in_tests import GenerateConfig, DEFAULT_PROJECT, CONFIG_FILE, _configure_logging, RepeatConfig, \

View File

@ -12,15 +12,14 @@ import urllib.parse
from urllib.parse import urlparse
import urllib.request
from typing import Any, Dict, List
import click
from evergreen.api import RetryingEvergreenApi, EvergreenApi, Build, Task
from git.repo import Repo
import requests
import structlog
from structlog.stdlib import LoggerFactory
import yaml
import click
from evergreen.api import RetryingEvergreenApi, EvergreenApi, Build, Task
# Get relative imports to work when the package is not installed on the PYTHONPATH.
if __name__ == "__main__" and __package__ is None:
@ -338,11 +337,11 @@ def download_file(download_url: str, download_location: str) -> None:
"""
try:
urllib.request.urlretrieve(download_url, download_location)
except urllib.error.ContentTooShortError:
except urllib.error.ContentTooShortError as exc:
LOGGER.warning(
"The artifact could not be completely downloaded. Default"
" compile bypass to false.", filename=download_location)
raise ValueError("No artifacts were found for the current task")
raise ValueError("No artifacts were found for the current task") from exc
def extract_artifacts(filename: str) -> None:

View File

@ -190,12 +190,10 @@ class ClangFormat(object):
for ospath in directories_to_check:
for program in programs:
self.path = os.path.join(ospath, program)
if os.path.exists(self.path) and self._validate_version():
break
else:
if not os.path.exists(self.path) or not self._validate_version():
self.path = None
continue
break
else:
break
else:
continue
break

View File

@ -15,9 +15,9 @@ import requests
import click
import structlog
from evergreen.api import RetryingEvergreenApi, EvergreenApi
from shrub.v2 import ShrubProject, FunctionCall, Task, TaskDependency, BuildVariant, ExistingTask
from evergreen.api import RetryingEvergreenApi, EvergreenApi
from buildscripts.resmokelib import config as _config
from buildscripts.resmokelib.multiversionconstants import (LAST_STABLE_MONGO_BINARY,
REQUIRES_FCV_TAG)

View File

@ -23,11 +23,12 @@ import requests
import structlog
import yaml
from evergreen.api import EvergreenApi, RetryingEvergreenApi
from pydantic.main import BaseModel
from shrub.v2 import Task, TaskDependency, BuildVariant, ExistingTask, ShrubProject
from evergreen.api import EvergreenApi, RetryingEvergreenApi
# Get relative imports to work when the package is not installed on the PYTHONPATH.
if __name__ == "__main__" and __package__ is None:
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@ -69,7 +70,7 @@ you need to:
(1) add a "large_distro_name" expansion to this build variant ("{build_variant}").
-- or --
(2) add this build variant ("{build_variant}") to the "build_variant_large_distro_exception"
list in the "etc/generate_subtasks_config.yml" file.
***************************************************************************************

View File

@ -101,8 +101,8 @@ def is_task_tagged(task, tags, filters):
:param filters: List of tags that should not belong to the task.
:return: True if task matches the query.
"""
if all([tag in task.tags for tag in tags]):
if not filters or not any([tag in task.tags for tag in filters]):
if all(tag in task.tags for tag in tags):
if not filters or not any(tag in task.tags for tag in filters):
return True
return False

View File

@ -502,7 +502,7 @@ class MongoSubPrettyPrinter(gdb.printing.SubPrettyPrinter):
def __init__(self, name, prefix, is_template, printer):
"""Initialize MongoSubPrettyPrinter."""
super(MongoSubPrettyPrinter, self).__init__(name)
super().__init__(name)
self.prefix = prefix
self.printer = printer
self.is_template = is_template
@ -516,7 +516,7 @@ class MongoPrettyPrinterCollection(gdb.printing.PrettyPrinter):
def __init__(self):
"""Initialize MongoPrettyPrinterCollection."""
super(MongoPrettyPrinterCollection, self).__init__("mongo", [])
super().__init__("mongo", [])
def add(self, name, prefix, is_template, printer):
"""Add a subprinter."""

View File

@ -82,7 +82,7 @@ class Global(common.SourceLocation):
self.cpp_includes = [] # type: List[str]
self.configs = None # type: ConfigGlobal
super(Global, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Struct(common.SourceLocation):
@ -105,7 +105,7 @@ class Struct(common.SourceLocation):
self.inline_chained_structs = False # type: bool
self.generate_comparison_operators = False # type: bool
self.fields = [] # type: List[Field]
super(Struct, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Expression(common.SourceLocation):
@ -118,7 +118,7 @@ class Expression(common.SourceLocation):
self.validate_constexpr = True # type: bool
self.export = False # type: bool
super(Expression, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Validator(common.SourceLocation):
@ -142,7 +142,7 @@ class Validator(common.SourceLocation):
self.lte = None # type: Expression
self.callback = None # type: Optional[str]
super(Validator, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Field(common.SourceLocation):
@ -196,7 +196,7 @@ class Field(common.SourceLocation):
# Validation rules.
self.validator = None # type: Optional[Validator]
super(Field, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Command(Struct):
@ -211,7 +211,7 @@ class Command(Struct):
"""Construct a command."""
self.namespace = None # type: str
self.command_field = None # type: Field
super(Command, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class EnumValue(common.SourceLocation):
@ -227,7 +227,7 @@ class EnumValue(common.SourceLocation):
self.name = None # type: str
self.value = None # type: str
super(EnumValue, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Enum(common.SourceLocation):
@ -246,7 +246,7 @@ class Enum(common.SourceLocation):
self.type = None # type: str
self.values = [] # type: List[EnumValue]
super(Enum, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Condition(common.SourceLocation):
@ -259,7 +259,7 @@ class Condition(common.SourceLocation):
self.constexpr = None # type: str
self.preprocessor = None # type: str
super(Condition, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ServerParameterClass(common.SourceLocation):
@ -274,7 +274,7 @@ class ServerParameterClass(common.SourceLocation):
self.override_ctor = False # type: bool
self.override_set = False # type: bool
super(ServerParameterClass, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ServerParameter(common.SourceLocation):
@ -301,7 +301,7 @@ class ServerParameter(common.SourceLocation):
self.validator = None # type: Validator
self.on_update = None # type: str
super(ServerParameter, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class GlobalInitializer(common.SourceLocation):
@ -315,7 +315,7 @@ class GlobalInitializer(common.SourceLocation):
self.register = None # type: str
self.store = None # type: str
super(GlobalInitializer, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ConfigGlobal(common.SourceLocation):
@ -328,7 +328,7 @@ class ConfigGlobal(common.SourceLocation):
# Other config globals are consumed in bind phase.
self.initializer = None # type: GlobalInitializer
super(ConfigGlobal, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ConfigOption(common.SourceLocation):
@ -365,4 +365,4 @@ class ConfigOption(common.SourceLocation):
self.positional_end = None # type: int
self.validator = None # type: Validator
super(ConfigOption, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)

View File

@ -850,7 +850,7 @@ def _validate_enum_int(ctxt, idl_enum):
min_value = min(int_values_set)
max_value = max(int_values_set)
valid_int = {x for x in range(min_value, max_value + 1)}
valid_int = set(range(min_value, max_value + 1))
if valid_int != int_values_set:
ctxt.add_enum_non_continuous_range_error(idl_enum, idl_enum.name)

View File

@ -98,7 +98,7 @@ def cpp_bson_type_name(name):
def list_valid_types():
# type: () -> List[str]
"""Return a list of supported bson types."""
return [a for a in _BSON_TYPE_INFORMATION]
return list(_BSON_TYPE_INFORMATION)
def is_valid_bindata_subtype(name):

View File

@ -73,7 +73,7 @@ class CompilerImportResolver(parser.ImportResolverBase):
"""Construct a ImportResolver."""
self._import_directories = import_directories
super(CompilerImportResolver, self).__init__()
super().__init__()
def resolve(self, base_file, imported_file_name):
# type: (str, str) -> str

View File

@ -247,7 +247,7 @@ class _CppTypeView(CppTypeBase):
# type: (ast.Field, str, str) -> None
self._storage_type = storage_type
self._view_type = view_type
super(_CppTypeView, self).__init__(field)
super().__init__(field)
def get_type_name(self):
# type: () -> str
@ -363,7 +363,7 @@ class _CppTypeDelegating(CppTypeBase):
def __init__(self, base, field):
# type: (CppTypeBase, ast.Field) -> None
self._base = base
super(_CppTypeDelegating, self).__init__(field)
super().__init__(field)
def get_type_name(self):
# type: () -> str
@ -614,7 +614,7 @@ class _CommonBsonCppTypeBase(BsonCppTypeBase):
def __init__(self, field, deserialize_method_name):
# type: (ast.Field, str) -> None
self._deserialize_method_name = deserialize_method_name
super(_CommonBsonCppTypeBase, self).__init__(field)
super().__init__(field)
def gen_deserializer_expression(self, indented_writer, object_instance):
# type: (writer.IndentedTextWriter, str) -> str

View File

@ -136,7 +136,7 @@ class ParserError(common.SourceLocation):
# pylint: disable=too-many-arguments
self.error_id = error_id
self.msg = msg
super(ParserError, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
def __str__(self):
# type: () -> str

View File

@ -184,7 +184,7 @@ def _get_all_fields(struct):
all_fields += struct.fields
return sorted([field for field in all_fields], key=lambda f: f.cpp_name)
return sorted(all_fields, key=lambda f: f.cpp_name)
class _FieldUsageCheckerBase(object, metaclass=ABCMeta):
@ -226,7 +226,7 @@ class _SlowFieldUsageChecker(_FieldUsageCheckerBase):
def __init__(self, indented_writer):
# type: (writer.IndentedTextWriter) -> None
super(_SlowFieldUsageChecker, self).__init__(indented_writer)
super().__init__(indented_writer)
self._writer.write_line('std::set<StringData> usedFields;')
@ -285,7 +285,7 @@ class _FastFieldUsageChecker(_FieldUsageCheckerBase):
def __init__(self, indented_writer, fields):
# type: (writer.IndentedTextWriter, List[ast.Field]) -> None
super(_FastFieldUsageChecker, self).__init__(indented_writer)
super().__init__(indented_writer)
self._writer.write_line('std::bitset<%d> usedFields;' % (len(fields)))
@ -1054,7 +1054,7 @@ class _CppSourceFileWriter(_CppFileWriterBase):
# type: (writer.IndentedTextWriter, str) -> None
"""Create a C++ .cpp file code writer."""
self._target_arch = target_arch
super(_CppSourceFileWriter, self).__init__(indented_writer)
super().__init__(indented_writer)
def _gen_field_deserializer_expression(self, element_name, field):
# type: (str, ast.Field) -> str
@ -1450,7 +1450,7 @@ class _CppSourceFileWriter(_CppFileWriterBase):
self._writer.write_line(
'%s object(localNS);' % (common.title_case(struct.cpp_name)))
else:
assert "Missing case"
assert False, "Missing case"
else:
self._writer.write_line('%s object;' % common.title_case(struct.cpp_name))

View File

@ -314,7 +314,7 @@ class _CommandBaseTypeInfo(_StructTypeInfo):
"""Create a _CommandBaseTypeInfo instance."""
self._command = command
super(_CommandBaseTypeInfo, self).__init__(command)
super().__init__(command)
def get_op_msg_request_serializer_method(self):
# type: () -> Optional[MethodInfo]
@ -344,7 +344,7 @@ class _IgnoredCommandTypeInfo(_CommandBaseTypeInfo):
"""Create a _IgnoredCommandTypeInfo instance."""
self._command = command
super(_IgnoredCommandTypeInfo, self).__init__(command)
super().__init__(command)
def get_serializer_method(self):
# type: () -> MethodInfo
@ -387,7 +387,7 @@ class _CommandFromType(_CommandBaseTypeInfo):
"""Create a _CommandFromType instance."""
assert command.command_field
self._command = command
super(_CommandFromType, self).__init__(command)
super().__init__(command)
def get_constructor_method(self):
# type: () -> MethodInfo
@ -449,7 +449,7 @@ class _CommandWithNamespaceTypeInfo(_CommandBaseTypeInfo):
"""Create a _CommandWithNamespaceTypeInfo instance."""
self._command = command
super(_CommandWithNamespaceTypeInfo, self).__init__(command)
super().__init__(command)
def get_constructor_method(self):
# type: () -> MethodInfo
@ -511,7 +511,7 @@ class _CommandWithUUIDNamespaceTypeInfo(_CommandBaseTypeInfo):
"""Create a _CommandWithUUIDNamespaceTypeInfo instance."""
self._command = command
super(_CommandWithUUIDNamespaceTypeInfo, self).__init__(command)
super().__init__(command)
def get_constructor_method(self):
# type: () -> MethodInfo

View File

@ -231,7 +231,7 @@ class Global(common.SourceLocation):
self.cpp_includes = [] # type: List[str]
self.configs = None # type: ConfigGlobal
super(Global, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Import(common.SourceLocation):
@ -248,7 +248,7 @@ class Import(common.SourceLocation):
# All imports directly or indirectly included
self.dependencies = [] # type: List[str]
super(Import, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Type(common.SourceLocation):
@ -274,7 +274,7 @@ class Type(common.SourceLocation):
self.deserializer = None # type: str
self.default = None # type: str
super(Type, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Validator(common.SourceLocation):
@ -298,7 +298,7 @@ class Validator(common.SourceLocation):
self.lte = None # type: Expression
self.callback = None # type: str
super(Validator, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Field(common.SourceLocation):
@ -331,7 +331,7 @@ class Field(common.SourceLocation):
self.serialize_op_msg_request_only = False # type: bool
self.constructed = False # type: bool
super(Field, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ChainedStruct(common.SourceLocation):
@ -347,7 +347,7 @@ class ChainedStruct(common.SourceLocation):
self.name = None # type: str
self.cpp_name = None # type: str
super(ChainedStruct, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ChainedType(common.SourceLocation):
@ -363,7 +363,7 @@ class ChainedType(common.SourceLocation):
self.name = None # type: str
self.cpp_name = None # type: str
super(ChainedType, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Struct(common.SourceLocation):
@ -398,7 +398,7 @@ class Struct(common.SourceLocation):
# Internal property: cpp_namespace from globals section
self.cpp_namespace = None # type: str
super(Struct, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Command(Struct):
@ -414,7 +414,7 @@ class Command(Struct):
self.namespace = None # type: str
self.type = None # type: str
super(Command, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class EnumValue(common.SourceLocation):
@ -430,7 +430,7 @@ class EnumValue(common.SourceLocation):
self.name = None # type: str
self.value = None # type: str
super(EnumValue, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Enum(common.SourceLocation):
@ -455,7 +455,7 @@ class Enum(common.SourceLocation):
# Internal property: cpp_namespace from globals section
self.cpp_namespace = None # type: str
super(Enum, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Condition(common.SourceLocation):
@ -468,7 +468,7 @@ class Condition(common.SourceLocation):
self.constexpr = None # type: str
self.preprocessor = None # type: str
super(Condition, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class Expression(common.SourceLocation):
@ -482,7 +482,7 @@ class Expression(common.SourceLocation):
self.expr = None # type: str
self.is_constexpr = True # type: bool
super(Expression, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ServerParameterClass(common.SourceLocation):
@ -497,7 +497,7 @@ class ServerParameterClass(common.SourceLocation):
self.override_ctor = False # type: bool
self.override_set = False # type: bool
super(ServerParameterClass, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ServerParameter(common.SourceLocation):
@ -524,7 +524,7 @@ class ServerParameter(common.SourceLocation):
self.validator = None # type: Validator
self.on_update = None # type: str
super(ServerParameter, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class GlobalInitializer(common.SourceLocation):
@ -538,7 +538,7 @@ class GlobalInitializer(common.SourceLocation):
self.register = None # type: str
self.store = None # type: str
super(GlobalInitializer, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ConfigGlobal(common.SourceLocation):
@ -551,7 +551,7 @@ class ConfigGlobal(common.SourceLocation):
self.source = [] # type: List[str]
self.initializer = None # type: GlobalInitializer
super(ConfigGlobal, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)
class ConfigOption(common.SourceLocation):
@ -588,4 +588,4 @@ class ConfigOption(common.SourceLocation):
self.positional = None # type str
self.validator = None # type: Validator
super(ConfigOption, self).__init__(file_name, line, column)
super().__init__(file_name, line, column)

View File

@ -53,7 +53,7 @@ class DictionaryImportResolver(idl.parser.ImportResolverBase):
# type: (Dict[str, str]) -> None
"""Construct a DictionaryImportResolver."""
self._import_dict = import_dict
super(DictionaryImportResolver, self).__init__()
super().__init__()
def resolve(self, base_file, imported_file_name):
# type: (str, str) -> str

View File

@ -64,7 +64,7 @@ class NothingImportResolver(idl.parser.ImportResolverBase):
class IDLTestcase(unittest.TestCase):
"""IDL Test case base class."""
def _parse(self, doc_str, resolver):
def _parse(self, doc_str, resolver): # pylint: disable=inconsistent-return-statements
# type: (str, idl.parser.ImportResolverBase) -> idl.syntax.IDLParsedSpec
"""Parse a document and throw a unittest failure if it fails to parse as a valid YAML document."""

View File

@ -14,7 +14,7 @@ class MypyLinter(base.LinterBase):
"""Create a mypy linter."""
# User can override the location of mypy from an environment variable.
super(MypyLinter, self).__init__("mypy", "0.800", os.getenv("MYPY"))
super().__init__("mypy", "0.800", os.getenv("MYPY"))
def get_lint_version_cmd_args(self):
# type: () -> List[str]

View File

@ -11,7 +11,7 @@ class PyDocstyleLinter(base.LinterBase):
def __init__(self):
# type: () -> None
"""Create a pydocstyle linter."""
super(PyDocstyleLinter, self).__init__("pydocstyle", "2.1.1")
super().__init__("pydocstyle", "2.1.1")
def get_lint_version_cmd_args(self):
# type: () -> List[str]

View File

@ -13,7 +13,7 @@ class PyLintLinter(base.LinterBase):
def __init__(self):
# type: () -> None
"""Create a pylint linter."""
super(PyLintLinter, self).__init__("pylint", "2.3.1")
super().__init__("pylint", "2.3.1")
def get_lint_version_cmd_args(self):
# type: () -> List[str]

View File

@ -11,7 +11,7 @@ class YapfLinter(base.LinterBase):
def __init__(self):
# type: () -> None
"""Create a yapf linter."""
super(YapfLinter, self).__init__("yapf", "0.26.0")
super().__init__("yapf", "0.26.0")
def get_lint_version_cmd_args(self):
# type: () -> List[str]

View File

@ -228,7 +228,7 @@ def main():
if not trace_doc:
print("could not find json backtrace object in input", file=sys.stderr)
exit(1)
sys.exit(1)
output_fn = None
if options.output_format == 'json':

View File

@ -502,10 +502,10 @@ def unpack_binaries_into(build_os, arch, spec, where):
print("moving file: %s/%s" % (release_dir, releasefile))
os.rename("%s/%s" % (release_dir, releasefile), releasefile)
os.rmdir(release_dir)
except Exception:
except Exception as oexc:
exc = sys.exc_info()[1]
os.chdir(rootdir)
raise exc
raise exc from oexc
os.chdir(rootdir)
@ -666,12 +666,12 @@ def move_repos_into_place(src, dst): # pylint: disable=too-many-branches
try:
os.mkdir(dname)
break
except OSError:
except OSError as oexc:
exc = sys.exc_info()[1]
if exc.errno == errno.EEXIST:
pass
else:
raise exc
raise exc from oexc
i = i + 1
# Put the stuff in our new directory.
@ -686,12 +686,12 @@ def move_repos_into_place(src, dst): # pylint: disable=too-many-branches
try:
os.symlink(dname, tmpnam)
break
except OSError: # as exc: # Python >2.5
except OSError as oexc: # as exc: # Python >2.5
exc = sys.exc_info()[1]
if exc.errno == errno.EEXIST:
pass
else:
raise exc
raise exc from oexc
i = i + 1
# Make a symlink to the old directory; this symlink will be
@ -704,12 +704,12 @@ def move_repos_into_place(src, dst): # pylint: disable=too-many-branches
try:
os.symlink(os.readlink(dst), oldnam)
break
except OSError: # as exc: # Python >2.5
except OSError as oexc: # as exc: # Python >2.5
exc = sys.exc_info()[1]
if exc.errno == errno.EEXIST:
pass
else:
raise exc
raise exc from oexc
os.rename(tmpnam, dst)
if oldnam:
@ -803,7 +803,7 @@ def make_rpm(distro, build_os, arch, spec, srcdir): # pylint: disable=too-many-
"-D",
f"dist .{distro.release_dist(build_os)}",
"-D",
f"_use_internal_dependency_generator 0",
"_use_internal_dependency_generator 0",
"-D",
f"dynamic_version {spec.pversion(distro)}",
"-D",
@ -844,12 +844,12 @@ def ensure_dir(filename):
dirpart = os.path.dirname(filename)
try:
os.makedirs(dirpart)
except OSError: # as exc: # Python >2.5
except OSError as oexc: # as exc: # Python >2.5
exc = sys.exc_info()[1]
if exc.errno == errno.EEXIST:
pass
else:
raise exc
raise exc from oexc
return filename

View File

@ -146,7 +146,7 @@ class EnterpriseDistro(packager.Distro):
if re.search("(redhat|fedora|centos)", self.dname):
return ["rhel80", "rhel70", "rhel62", "rhel57"]
return super(EnterpriseDistro, self).build_os(arch)
return super().build_os(arch)
# pylint: enable=too-many-return-statements
@ -228,10 +228,10 @@ def unpack_binaries_into(build_os, arch, spec, where):
for releasefile in "bin", "snmp", "LICENSE-Enterprise.txt", "README", "THIRD-PARTY-NOTICES", "MPL-2":
os.rename("%s/%s" % (release_dir, releasefile), releasefile)
os.rmdir(release_dir)
except Exception:
except Exception as oexc:
exc = sys.exc_info()[1]
os.chdir(rootdir)
raise exc
raise exc from oexc
os.chdir(rootdir)
@ -333,12 +333,12 @@ def move_repos_into_place(src, dst): # pylint: disable=too-many-branches
try:
os.mkdir(dname)
break
except OSError:
except OSError as oexc:
exc = sys.exc_info()[1]
if exc.errno == errno.EEXIST:
pass
else:
raise exc
raise exc from oexc
idx = idx + 1
# Put the stuff in our new directory.
@ -353,12 +353,12 @@ def move_repos_into_place(src, dst): # pylint: disable=too-many-branches
try:
os.symlink(dname, tmpnam)
break
except OSError: # as exc: # Python >2.5
except OSError as oexc: # as exc: # Python >2.5
exc = sys.exc_info()[1]
if exc.errno == errno.EEXIST:
pass
else:
raise exc
raise exc from oexc
idx = idx + 1
# Make a symlink to the old directory; this symlink will be
@ -371,12 +371,12 @@ def move_repos_into_place(src, dst): # pylint: disable=too-many-branches
try:
os.symlink(os.readlink(dst), oldnam)
break
except OSError: # as exc: # Python >2.5
except OSError as oexc: # as exc: # Python >2.5
exc = sys.exc_info()[1]
if exc.errno == errno.EEXIST:
pass
else:
raise exc
raise exc from oexc
os.rename(tmpnam, dst)
if oldnam:

View File

@ -4,9 +4,11 @@ from itertools import chain
from typing import Any, Dict, Iterable, Set, Optional, List
import structlog
from evergreen import EvergreenApi
from git import DiffIndex, Repo
from evergreen import EvergreenApi
LOGGER = structlog.get_logger(__name__)
RevisionMap = Dict[str, str]

View File

@ -248,7 +248,7 @@ class TestRunner(interface.Subcommand): # pylint: disable=too-many-instance-att
suite.test_kind, suite.get_display_name(), config.RANDOM_SEED)
random.shuffle(suite.tests)
def _get_suites(self):
def _get_suites(self): # pylint: disable=inconsistent-return-statements
"""Return the list of suites for this resmoke invocation."""
try:
return suitesconfig.get_suites(config.SUITE_FILES, config.TEST_FILES)
@ -297,9 +297,9 @@ class TestRunner(interface.Subcommand): # pylint: disable=too-many-instance-att
proto_file = os.path.join(root_dir, "buildscripts", "resmokelib", "core", "jasper.proto")
try:
well_known_protos_include = pkg_resources.resource_filename("grpc_tools", "_proto")
except ImportError:
except ImportError as exc:
raise ImportError("You must run: sys.executable + '-m pip install grpcio grpcio-tools "
"googleapis-common-protos' to use --spawnUsing=jasper.")
"googleapis-common-protos' to use --spawnUsing=jasper.") from exc
# We use the build/ directory as the output directory because the generated files aren't
# meant to because tracked by git or linted.
@ -331,8 +331,8 @@ class TestRunner(interface.Subcommand): # pylint: disable=too-many-instance-att
sys.path.append(os.path.dirname(proto_out))
from jasper import jasper_pb2
from jasper import jasper_pb2_grpc
from jasper import jasper_pb2 # pylint: disable=import-outside-toplevel
from jasper import jasper_pb2_grpc # pylint: disable=import-outside-toplevel
jasper_process.Process.jasper_pb2 = jasper_pb2
jasper_process.Process.jasper_pb2_grpc = jasper_pb2_grpc

View File

@ -344,8 +344,8 @@ def _set_logging_config():
return
raise ValueError("Unknown logger '%s'" % pathname)
except FileNotFoundError:
raise IOError("Directory {} does not exist.".format(_config.LOGGER_DIR))
except FileNotFoundError as exc:
raise IOError("Directory {} does not exist.".format(_config.LOGGER_DIR)) from exc
def _expand_user(pathname):

View File

@ -61,7 +61,7 @@ class WindowsDumper(Dumper):
cdb = spawn.find_executable(debugger)
if cdb is not None:
return cdb
from win32com.shell import shell, shellcon
from win32com.shell import shell, shellcon # pylint: disable=import-outside-toplevel
# Cygwin via sshd does not expose the normal environment variables
# Use the shell api to get the variable instead

View File

@ -3,6 +3,7 @@
import os
import sys
import glob
import shutil
def extract_debug_symbols(root_logger):
@ -31,7 +32,7 @@ def extract_debug_symbols(root_logger):
def _extract_tar(path, root_logger):
import shutil
# The file name is always .tgz but it's "secretly" a zip file on Windows :(
compressed_format = 'zip' if sys.platform == "win32" else 'gztar'
shutil.unpack_archive(path, format=compressed_format)

View File

@ -538,25 +538,25 @@ def to_local_args(input_args=None): # pylint: disable=too-many-branches,too-man
# one such argument has been visited.
if arg_dest in arg_dests_visited:
continue
else:
arg_dests_visited.add(arg_dest)
arg_dests_visited.add(arg_dest)
# If the arg doesn't exist in the parsed namespace, skip.
# This is mainly for "--help".
if not hasattr(parsed_args, arg_dest):
continue
# Skip any evergreen centric args.
elif group.title in [_INTERNAL_OPTIONS_TITLE, _EVERGREEN_ARGUMENT_TITLE]:
if group.title in [_INTERNAL_OPTIONS_TITLE, _EVERGREEN_ARGUMENT_TITLE]:
continue
# Keep these args.
elif group.title == 'optional arguments':
if group.title == 'optional arguments':
arg_name = action.option_strings[-1]
# If an option has the same value as the default, we don't need to specify it.
if getattr(parsed_args, arg_dest, None) == action.default:
continue
# These are arguments that take no value.
elif action.nargs == 0:
if action.nargs == 0:
other_local_args.append(arg_name)
elif isinstance(action, argparse._AppendAction): # pylint: disable=protected-access
args = [format_option(arg_name, elem) for elem in arg_value]

View File

@ -198,21 +198,21 @@ class ReplFixture(Fixture):
remaining = deadline - time.time()
insert_fn(remaining)
break
except pymongo.errors.ConnectionFailure:
except pymongo.errors.ConnectionFailure as exc:
remaining = deadline - time.time()
if remaining <= 0.0:
message = "Failed to connect to {} within {} minutes".format(
self.get_driver_connection_url(), ReplFixture.AWAIT_REPL_TIMEOUT_MINS)
self.logger.error(message)
raise errors.ServerFailure(message)
except pymongo.errors.WTimeoutError:
raise errors.ServerFailure(message) from exc
except pymongo.errors.WTimeoutError as exc:
message = "Replication of write operation timed out."
self.logger.error(message)
raise errors.ServerFailure(message)
raise errors.ServerFailure(message) from exc
except pymongo.errors.PyMongoError as err:
message = "Write operation on {} failed: {}".format(
self.get_driver_connection_url(), err)
raise errors.ServerFailure(message)
raise errors.ServerFailure(message) from err
class NoOpFixture(Fixture):

View File

@ -465,12 +465,12 @@ class _MongoSFixture(interface.Fixture):
client = self.mongo_client(timeout_millis=500)
client.admin.command("ping")
break
except pymongo.errors.ConnectionFailure:
except pymongo.errors.ConnectionFailure as exc:
remaining = deadline - time.time()
if remaining <= 0.0:
raise errors.ServerFailure(
"Failed to connect to mongos on port {} after {} seconds".format(
self.port, standalone.MongoDFixture.AWAIT_READY_TIMEOUT_SECS))
self.port, standalone.MongoDFixture.AWAIT_READY_TIMEOUT_SECS)) from exc
self.logger.info("Waiting to connect to mongos on port %d.", self.port)
time.sleep(0.1) # Wait a little bit before trying again.

View File

@ -105,12 +105,12 @@ class MongoDFixture(interface.Fixture):
client = self.mongo_client(timeout_millis=500)
client.admin.command("ping")
break
except pymongo.errors.ConnectionFailure:
except pymongo.errors.ConnectionFailure as exc:
remaining = deadline - time.time()
if remaining <= 0.0:
raise errors.ServerFailure(
"Failed to connect to mongod on port {} after {} seconds".format(
self.port, MongoDFixture.AWAIT_READY_TIMEOUT_SECS))
self.port, MongoDFixture.AWAIT_READY_TIMEOUT_SECS)) from exc
self.logger.info("Waiting to connect to mongod on port %d.", self.port)
time.sleep(0.1) # Wait a little bit before trying again.

View File

@ -198,10 +198,10 @@ class PeriodicKillSecondariesTestCase(interface.DynamicTestCase):
try:
secondary.teardown()
except errors.ServerFailure:
except errors.ServerFailure as exc:
raise errors.ServerFailure(
"{} did not exit cleanly after reconciling the end of its oplog".format(
secondary))
secondary)) from exc
self.logger.info("Starting the fixture back up again with its data files intact for final"
" validation...")
@ -244,9 +244,10 @@ class PeriodicKillSecondariesTestCase(interface.DynamicTestCase):
try:
self.fixture.teardown()
except errors.ServerFailure:
except errors.ServerFailure as exc:
raise errors.ServerFailure(
"{} did not exit cleanly after verifying data consistency".format(self.fixture))
"{} did not exit cleanly after verifying data consistency".format(
self.fixture)) from exc
self.logger.info("Starting the fixture back up again with no data...")
self.fixture.setup()
@ -407,10 +408,10 @@ class PeriodicKillSecondariesTestCase(interface.DynamicTestCase):
try:
secondary.teardown()
except errors.ServerFailure:
except errors.ServerFailure as exc:
raise errors.ServerFailure(
"{} did not exit cleanly after being started up as a standalone".format(
secondary))
secondary)) from exc
except pymongo.errors.OperationFailure as err:
self.logger.exception(
"Failed to read the minValid document, the oplogTruncateAfterPoint document,"

View File

@ -220,18 +220,18 @@ class Job(object): # pylint: disable=too-many-instance-attributes
except errors.StopExecution:
raise
except errors.ServerFailure:
except errors.ServerFailure as exc:
self.logger.exception("%s marked as a failure by a hook's before_test.",
test.short_description())
self._fail_test(test, sys.exc_info(), return_code=2)
raise errors.StopExecution("A hook's before_test failed")
raise errors.StopExecution("A hook's before_test failed") from exc
except errors.TestFailure:
except errors.TestFailure as exc:
self.logger.exception("%s marked as a failure by a hook's before_test.",
test.short_description())
self._fail_test(test, sys.exc_info(), return_code=1)
if self.suite_options.fail_fast:
raise errors.StopExecution("A hook's before_test failed")
raise errors.StopExecution("A hook's before_test failed") from exc
except:
# Record the before_test() error in 'self.report'.
@ -253,18 +253,18 @@ class Job(object): # pylint: disable=too-many-instance-attributes
except errors.StopExecution:
raise
except errors.ServerFailure:
except errors.ServerFailure as exc:
self.logger.exception("%s marked as a failure by a hook's after_test.",
test.short_description())
self.report.setFailure(test, return_code=2)
raise errors.StopExecution("A hook's after_test failed")
raise errors.StopExecution("A hook's after_test failed") from exc
except errors.TestFailure:
except errors.TestFailure as exc:
self.logger.exception("%s marked as a failure by a hook's after_test.",
test.short_description())
self.report.setFailure(test, return_code=1)
if self.suite_options.fail_fast:
raise errors.StopExecution("A hook's after_test failed")
raise errors.StopExecution("A hook's after_test failed") from exc
except:
self.report.setError(test)

View File

@ -48,7 +48,7 @@ class QueueElemRepeatTime(QueueElem):
def __init__(self, testcase, config, suite_options):
"""Initialize QueueElemRepeatTime class."""
super(QueueElemRepeatTime, self).__init__(testcase, config, suite_options)
super().__init__(testcase, config, suite_options)
self.repeat_num_min = suite_options.num_repeat_tests_min
self.repeat_num_max = suite_options.num_repeat_tests_max
self.repeat_secs = suite_options.time_repeat_tests_secs

View File

@ -80,7 +80,7 @@ def load_yaml_file(filename):
with open(filename, "r") as fp:
return yaml.safe_load(fp)
except yaml.YAMLError as err:
raise ValueError("File '%s' contained invalid YAML: %s" % (filename, err))
raise ValueError("File '%s' contained invalid YAML: %s" % (filename, err)) from err
def dump_yaml_file(value, filename):
@ -89,7 +89,7 @@ def dump_yaml_file(value, filename):
with open(filename, "w") as fp:
return yaml.safe_dump(value, fp)
except yaml.YAMLError as err:
raise ValueError("Could not write YAML to file '%s': %s" % (filename, err))
raise ValueError("Could not write YAML to file '%s': %s" % (filename, err)) from err
def dump_yaml(value):
@ -103,4 +103,4 @@ def load_yaml(value):
try:
return yaml.safe_load(value)
except yaml.YAMLError as err:
raise ValueError("Attempted to parse invalid YAML value '%s': %s" % (value, err))
raise ValueError("Attempted to parse invalid YAML value '%s': %s" % (value, err)) from err

View File

@ -123,7 +123,7 @@ class Archival(object): # pylint: disable=too-many-instance-attributes
@staticmethod
def _get_s3_client():
# Since boto3 is a 3rd party module, we import locally.
import boto3
import boto3 # pylint: disable=import-outside-toplevel
return boto3.client("s3")
def archive_files_to_s3(self, display_name, input_files, s3_bucket, s3_path):

View File

@ -38,8 +38,8 @@ def get_tags(pathname):
raise TypeError("Expected a list of string tags, but got '%s'" % (tags))
return tags
except yaml.YAMLError as err:
raise ValueError(
"File '%s' contained invalid tags (expected YAML): %s" % (pathname, err))
raise ValueError("File '%s' contained invalid tags (expected YAML): %s" %
(pathname, err)) from err
return []

View File

@ -15,7 +15,7 @@ import argparse
import collections
import logging
import os
import shutil
import sys
LOGGER = logging.getLogger("scons.cache.prune.lru") # type: ignore
@ -124,14 +124,14 @@ def main():
if args.cache_dir is None or not os.path.isdir(args.cache_dir):
LOGGER.error("must specify a valid cache path, [%s]", args.cache_dir)
exit(1)
sys.exit(1)
ok = prune_cache(cache_path=args.cache_dir, cache_size_gb=args.cache_size,
clean_ratio=args.prune_ratio)
if not ok:
LOGGER.error("encountered error cleaning the cache. exiting.")
exit(1)
sys.exit(1)
if __name__ == "__main__":

View File

@ -9,11 +9,12 @@ from typing import Any, Dict, List, Set
import click
import structlog
from structlog.stdlib import LoggerFactory
from evergreen.api import EvergreenApi, RetryingEvergreenApi
from git import Repo
from shrub.v2 import ShrubProject, BuildVariant
from evergreen.api import EvergreenApi, RetryingEvergreenApi
# Get relative imports to work when the package is not installed on the PYTHONPATH.
from buildscripts.patch_builds.change_data import find_changed_files_in_repos, \
generate_revision_map_from_manifest

View File

@ -93,7 +93,8 @@ def download_file(url, file_name, download_retries=5):
except requests.exceptions.ChunkedEncodingError as err:
download_retries -= 1
if download_retries == 0:
raise Exception("Incomplete download for URL {}: {}".format(url, err))
raise Exception("Incomplete download for URL {}: {}".format(url,
err)) from err
continue
# Check if file download was completed.
@ -350,7 +351,7 @@ class MultiVersionDownloader(object): # pylint: disable=too-many-instance-attri
# os.symlink is not supported on Windows, use a direct method instead.
def symlink_ms(source, link_name):
"""Provide symlink for Windows."""
import ctypes
import ctypes # pylint: disable=import-outside-toplevel
csl = ctypes.windll.kernel32.CreateSymbolicLinkW
csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
csl.restype = ctypes.c_ubyte

View File

@ -179,7 +179,7 @@ class TestRepeatConfig(unittest.TestCase):
repeat_config = under_test.RepeatConfig(repeat_tests_num=5)
repeat_options = repeat_config.generate_resmoke_options()
self.assertEqual(repeat_options.strip(), f"--repeatSuites=5")
self.assertEqual(repeat_options.strip(), "--repeatSuites=5")
def test_get_resmoke_repeat_options_secs(self):
repeat_config = under_test.RepeatConfig(repeat_tests_secs=5)

View File

@ -3,7 +3,7 @@
GitPython ~= 3.1.7
mypy < 0.900; python_version > "3.5"
pydocstyle == 2.1.1
pylint == 2.3.1
pylint == 2.7.2
structlog ~= 19.2.0
typing <= 3.7.4.3
yamllint == 1.15.0

View File

@ -439,7 +439,8 @@ def download_file(url, file_name, download_retries=5):
except requests.exceptions.ChunkedEncodingError as err:
download_retries -= 1
if download_retries == 0:
raise Exception("Incomplete download for URL {}: {}".format(url, err))
raise Exception("Incomplete download for URL {}: {}".format(url,
err)) from err
continue
# Check if file download was completed.
@ -505,8 +506,7 @@ def install_tarball(tarball, root_dir):
fi ;
done ;
popd ;
""".format( # pylint: disable=bad-continuation
tarball=tarball, tmp_dir=tmp_dir, root_dir=root_dir)
""".format(tarball=tarball, tmp_dir=tmp_dir, root_dir=root_dir)
ret, output = execute_cmd(cmds, use_file=True)
shutil.rmtree(tmp_dir)
else: