Skip to content

Commit 7262fc4

Browse files
authored
chore(tests): Update precommit config yaml file to newest versions (#206)
* Add mypy.ini file to ignore type errors for setuptools * Updated pre-commit, linting updates from pre-commit update, patch auto_spec updated to autospec in tests/lib/metrics_test.py * moved flake8 our of pre-commit section to its own repo in pre-commit-config * precommit hook versions set to latest to still support python 3.6
1 parent bc9cc9e commit 7262fc4

27 files changed

+101
-97
lines changed

.pre-commit-config.yaml

+16-13
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@ exclude: ^(buildspec.yml|.pre-commit-config.yaml)$
22
fail_fast: true
33
repos:
44
- repo: https://github.com/pre-commit/mirrors-isort
5-
rev: v4.3.17
5+
rev: v5.10.1
66
hooks:
77
- id: isort
88
# language_version: python3.6
99
- repo: https://github.com/psf/black
10-
rev: 22.3.0
10+
rev: 22.8.0
1111
hooks:
1212
- id: black
1313
exclude: templates/
1414
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v2.0.0
15+
rev: v4.1.0
1616
hooks:
1717
- id: check-case-conflict
1818
- id: end-of-file-fixer
1919
- id: mixed-line-ending
2020
args:
2121
- --fix=lf
2222
- id: trailing-whitespace
23+
- id: pretty-format-json
24+
args:
25+
- --autofix
26+
- --indent=4
27+
- --no-sort-keys
28+
- id: check-merge-conflict
29+
- id: check-yaml
30+
- repo: https://github.com/pycqa/flake8
31+
rev: "5.0.4"
32+
hooks:
2333
- id: flake8
2434
additional_dependencies:
2535
- flake8-bugbear>=19.3.0
@@ -30,28 +40,21 @@ repos:
3040
- flake8-pep3101>=1.2.1
3141
# language_version: python3.6
3242
exclude: templates/
33-
- id: pretty-format-json
34-
args:
35-
- --autofix
36-
- --indent=4
37-
- --no-sort-keys
38-
- id: check-merge-conflict
39-
- id: check-yaml
4043
- repo: https://github.com/pre-commit/pygrep-hooks
41-
rev: v1.3.0
44+
rev: v1.9.0
4245
hooks:
4346
- id: python-check-blanket-noqa
4447
- id: python-check-mock-methods
4548
- id: python-no-log-warn
4649
- repo: https://github.com/PyCQA/bandit
47-
rev: "1.6.2"
50+
rev: "1.7.1"
4851
hooks:
4952
- id: bandit
5053
files: ^(src|python)/
5154
additional_dependencies:
5255
- "importlib-metadata<5" # https://github.com/PyCQA/bandit/issues/956
5356
- repo: https://github.com/pre-commit/mirrors-mypy
54-
rev: v0.790
57+
rev: v0.812
5558
hooks:
5659
- id: mypy
5760
files: ^src/

mypy.ini

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[mypy]
2+
3+
# Per-module options:
4+
[mypy-setuptools.*]
5+
ignore_missing_imports = True

python/rpdk/python/codegen.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
import docker
12
import logging
23
import os
34
import shutil
45
import zipfile
5-
from pathlib import PurePosixPath
6-
from subprocess import PIPE, CalledProcessError, run as subprocess_run # nosec
7-
from tempfile import TemporaryFile
8-
from typing import Dict
9-
10-
import docker
116
from docker.errors import APIError, ContainerError, ImageLoadError
7+
from pathlib import PurePosixPath
128
from requests.exceptions import ConnectionError as RequestsConnectionError
139
from rpdk.core.data_loaders import resource_stream
1410
from rpdk.core.exceptions import DownstreamError, SysExitRecommendedError
1511
from rpdk.core.init import input_with_validation
1612
from rpdk.core.jsonutils.resolver import ContainerType, resolve_models
1713
from rpdk.core.plugin_base import LanguagePlugin
1814
from rpdk.core.project import ARTIFACT_TYPE_HOOK
15+
from subprocess import PIPE, CalledProcessError, run as subprocess_run # nosec
16+
from tempfile import TemporaryFile
17+
from typing import Dict
1918

2019
from . import __version__
2120
from .resolver import contains_model, translate_type

python/rpdk/python/templates/handlers.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
from typing import Any, MutableMapping, Optional
3-
43
from {{support_lib_pkg}} import (
54
Action,
65
HandlerErrorCode,

python/rpdk/python/templates/hook_handlers.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
from typing import Any, MutableMapping, Optional
3-
43
from {{support_lib_pkg}} import (
54
BaseHookHandlerRequest,
65
HandlerErrorCode,

python/rpdk/python/templates/hook_models.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# DO NOT modify this file by hand, changes will be overwritten
2-
import sys
32
from dataclasses import dataclass
3+
4+
from cloudformation_cli_python_lib.interface import BaseHookHandlerRequest, BaseModel
5+
from cloudformation_cli_python_lib.recast import recast_object
6+
from cloudformation_cli_python_lib.utils import deserialize_list
7+
8+
import sys
49
from inspect import getmembers, isclass
510
from typing import (
611
AbstractSet,
@@ -14,10 +19,6 @@
1419
TypeVar,
1520
)
1621

17-
from cloudformation_cli_python_lib.interface import BaseHookHandlerRequest, BaseModel
18-
from cloudformation_cli_python_lib.recast import recast_object
19-
from cloudformation_cli_python_lib.utils import deserialize_list
20-
2122
T = TypeVar("T")
2223

2324

python/rpdk/python/templates/models.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# DO NOT modify this file by hand, changes will be overwritten
2-
import sys
32
from dataclasses import dataclass
3+
4+
from cloudformation_cli_python_lib.interface import (
5+
BaseModel,
6+
BaseResourceHandlerRequest,
7+
)
8+
from cloudformation_cli_python_lib.recast import recast_object
9+
from cloudformation_cli_python_lib.utils import deserialize_list
10+
11+
import sys
412
from inspect import getmembers, isclass
513
from typing import (
614
AbstractSet,
@@ -14,13 +22,6 @@
1422
TypeVar,
1523
)
1624

17-
from cloudformation_cli_python_lib.interface import (
18-
BaseModel,
19-
BaseResourceHandlerRequest,
20-
)
21-
from cloudformation_cli_python_lib.recast import recast_object
22-
from cloudformation_cli_python_lib.utils import deserialize_list
23-
2425
T = TypeVar("T")
2526

2627

python/rpdk/python/templates/target_model.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# DO NOT modify this file by hand, changes will be overwritten
2-
import sys
32
from dataclasses import dataclass
3+
4+
from cloudformation_cli_python_lib.interface import BaseModel
5+
from cloudformation_cli_python_lib.recast import recast_object
6+
from cloudformation_cli_python_lib.utils import deserialize_list
7+
8+
import sys
49
from inspect import getmembers, isclass
510
from typing import (
611
AbstractSet,
@@ -14,10 +19,6 @@
1419
TypeVar,
1520
)
1621

17-
from cloudformation_cli_python_lib.interface import BaseModel
18-
from cloudformation_cli_python_lib.recast import recast_object
19-
from cloudformation_cli_python_lib.utils import deserialize_list
20-
2122
T = TypeVar("T")
2223

2324

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""Python 3.6 and 3.7 language support for the CloudFormation CLI"""
33
import os.path
44
import re
5-
65
from setuptools import setup
76

87
HERE = os.path.abspath(os.path.dirname(__file__))

src/cloudformation_cli_python_lib/boto3_proxy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# boto3 doesn't have stub files
2-
from typing import Optional
3-
42
from boto3.session import Session # type: ignore
53

4+
from typing import Optional
5+
66
from .utils import Credentials
77

88

src/cloudformation_cli_python_lib/cipher.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import base64
2-
import json
3-
import uuid
4-
from typing import Optional
5-
61
# boto3, botocore, aws_encryption_sdk don't have stub files
72
import boto3 # type: ignore
83

94
import aws_encryption_sdk # type: ignore
5+
import base64
6+
import json
7+
import uuid
108
from aws_encryption_sdk.exceptions import AWSEncryptionSDKClientError # type: ignore
119
from aws_encryption_sdk.identifiers import CommitmentPolicy # type: ignore
1210
from botocore.client import BaseClient # type: ignore
@@ -16,6 +14,7 @@
1614
create_assume_role_refresher,
1715
)
1816
from botocore.session import Session, get_session # type: ignore
17+
from typing import Optional
1918

2019
from .exceptions import _EncryptionError
2120
from .utils import Credentials

src/cloudformation_cli_python_lib/interface.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# pylint: disable=invalid-name
2-
import logging
32
from dataclasses import dataclass
3+
4+
import logging
45
from enum import Enum, auto
56
from typing import Any, List, Mapping, MutableMapping, Optional, Type
67

src/cloudformation_cli_python_lib/log_delivery.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(
2424
self.group = group
2525
self.stream = stream.replace(":", "__")
2626
self.client = session.client("logs")
27-
self.sequence_token = ""
27+
self.sequence_token = "" # nosec
2828

2929
@classmethod
3030
def _get_existing_logger(cls) -> Optional["ProviderLogHandler"]:

src/cloudformation_cli_python_lib/metrics.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import datetime
22
import logging
3-
from typing import Any, List, Mapping, Optional, Union
4-
53
from botocore.exceptions import ClientError # type: ignore
4+
from typing import Any, List, Mapping, Optional, Union
65

76
from .boto3_proxy import SessionProxy
87
from .interface import Action, HookInvocationPoint, MetricTypes, StandardUnit

src/cloudformation_cli_python_lib/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# pylint: disable=invalid-name
2-
import json
32
from dataclasses import dataclass, field, fields
3+
4+
import json
45
from datetime import date, datetime, time
56
from typing import (
67
Any,

tests/lib/cipher_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# pylint: disable=wrong-import-order,line-too-long
2-
from unittest.mock import Mock, patch
3-
42
import pytest
53
from cloudformation_cli_python_lib.cipher import KmsCipher
64
from cloudformation_cli_python_lib.exceptions import _EncryptionError
75
from cloudformation_cli_python_lib.utils import Credentials
86

97
from aws_encryption_sdk.exceptions import AWSEncryptionSDKClientError
8+
from unittest.mock import Mock, patch
109

1110

1211
def mock_session():

tests/lib/exceptions_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import importlib
2-
import inspect
3-
41
import pytest
52
from cloudformation_cli_python_lib.interface import HandlerErrorCode, OperationStatus
63

4+
import importlib
5+
import inspect
6+
77

88
def get_public_exceptions(module_name="cloudformation_cli_python_lib.exceptions"):
99
module = importlib.import_module(module_name)

tests/lib/hook_test.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# pylint: disable=redefined-outer-name,protected-access,line-too-long
2-
import json
32
from dataclasses import dataclass
4-
from datetime import datetime
5-
from unittest.mock import Mock, call, patch, sentinel
63

74
import pytest
85
from cloudformation_cli_python_lib import Hook
@@ -23,6 +20,10 @@
2320
)
2421
from cloudformation_cli_python_lib.utils import Credentials, HookInvocationRequest
2522

23+
import json
24+
from datetime import datetime
25+
from unittest.mock import Mock, call, patch, sentinel
26+
2627
ENTRYPOINT_PAYLOAD = {
2728
"awsAccountId": "123456789012",
2829
"clientRequestToken": "4b90a7e4-b790-456b-a937-0cfdfa211dfe",

tests/lib/interface_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# pylint: disable=protected-access,redefined-outer-name,abstract-method
2-
import json
32
from dataclasses import dataclass
4-
from string import ascii_letters
53

64
import boto3
75
import pytest
@@ -15,7 +13,9 @@
1513
)
1614

1715
import hypothesis.strategies as s # pylint: disable=C0411
16+
import json
1817
from hypothesis import given # pylint: disable=C0411
18+
from string import ascii_letters
1919

2020

2121
@pytest.fixture(scope="module")

tests/lib/log_delivery_test.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
# pylint: disable=redefined-outer-name,protected-access
2-
import logging
3-
from unittest.mock import DEFAULT, Mock, create_autospec, patch
4-
from uuid import uuid4
5-
62
import pytest
73
from cloudformation_cli_python_lib.log_delivery import (
84
HookProviderLogHandler,
@@ -18,6 +14,9 @@
1814

1915
import botocore.errorfactory
2016
import botocore.session
17+
import logging
18+
from unittest.mock import DEFAULT, Mock, create_autospec, patch
19+
from uuid import uuid4
2120

2221
logs_model = botocore.session.get_session().get_service_model("logs")
2322
factory = botocore.errorfactory.ClientExceptionsFactory()

tests/lib/metrics_test.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# auto enums `.name` causes no-member
22
# pylint: disable=redefined-outer-name,no-member,protected-access
3-
from datetime import datetime
4-
from unittest.mock import Mock, call, patch
5-
63
import pytest
74
from cloudformation_cli_python_lib.interface import (
85
Action,
@@ -19,6 +16,8 @@
1916

2017
import botocore.errorfactory
2118
import botocore.session
19+
from datetime import datetime
20+
from unittest.mock import Mock, call, patch
2221

2322
cloudwatch_model = botocore.session.get_session().get_service_model("cloudwatch")
2423
factory = botocore.errorfactory.ClientExceptionsFactory()
@@ -67,7 +66,7 @@ def test_put_metric_catches_error(mock_session):
6766
}
6867

6968
with patch(
70-
"cloudformation_cli_python_lib.metrics.LOG", auto_spec=True
69+
"cloudformation_cli_python_lib.metrics.LOG", autospec=True
7170
) as mock_logger:
7271
publisher.publish_metric(
7372
MetricTypes.HandlerInvocationCount,
@@ -226,7 +225,7 @@ def test_put_hook_metric_catches_error(mock_session):
226225
}
227226

228227
with patch(
229-
"cloudformation_cli_python_lib.metrics.LOG", auto_spec=True
228+
"cloudformation_cli_python_lib.metrics.LOG", autospec=True
230229
) as mock_logger:
231230
publisher.publish_metric(
232231
MetricTypes.HandlerInvocationCount,

0 commit comments

Comments
 (0)