Skip to content

chore(tests): Update precommit config yaml file to newest versions #206

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 8 commits into from
Nov 1, 2022
Merged
29 changes: 16 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@ exclude: ^(buildspec.yml|.pre-commit-config.yaml)$
fail_fast: true
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.17
rev: v5.10.1
hooks:
- id: isort
# language_version: python3.6
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.8.0
hooks:
- id: black
exclude: templates/
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
rev: v4.1.0
hooks:
- id: check-case-conflict
- id: end-of-file-fixer
- id: mixed-line-ending
args:
- --fix=lf
- id: trailing-whitespace
- id: pretty-format-json
args:
- --autofix
- --indent=4
- --no-sort-keys
- id: check-merge-conflict
- id: check-yaml
- repo: https://github.com/pycqa/flake8
rev: "5.0.4"
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear>=19.3.0
Expand All @@ -30,28 +40,21 @@ repos:
- flake8-pep3101>=1.2.1
# language_version: python3.6
exclude: templates/
- id: pretty-format-json
args:
- --autofix
- --indent=4
- --no-sort-keys
- id: check-merge-conflict
- id: check-yaml
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.3.0
rev: v1.9.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: python-no-log-warn
- repo: https://github.com/PyCQA/bandit
rev: "1.6.2"
rev: "1.7.1"
hooks:
- id: bandit
files: ^(src|python)/
additional_dependencies:
- "importlib-metadata<5" # https://github.com/PyCQA/bandit/issues/956
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.790
rev: v0.812
hooks:
- id: mypy
files: ^src/
Expand Down
5 changes: 5 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[mypy]

# Per-module options:
[mypy-setuptools.*]
ignore_missing_imports = True
11 changes: 5 additions & 6 deletions python/rpdk/python/codegen.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import docker
import logging
import os
import shutil
import zipfile
from pathlib import PurePosixPath
from subprocess import PIPE, CalledProcessError, run as subprocess_run # nosec
from tempfile import TemporaryFile
from typing import Dict

import docker
from docker.errors import APIError, ContainerError, ImageLoadError
from pathlib import PurePosixPath
from requests.exceptions import ConnectionError as RequestsConnectionError
from rpdk.core.data_loaders import resource_stream
from rpdk.core.exceptions import DownstreamError, SysExitRecommendedError
from rpdk.core.init import input_with_validation
from rpdk.core.jsonutils.resolver import ContainerType, resolve_models
from rpdk.core.plugin_base import LanguagePlugin
from rpdk.core.project import ARTIFACT_TYPE_HOOK
from subprocess import PIPE, CalledProcessError, run as subprocess_run # nosec
from tempfile import TemporaryFile
from typing import Dict

from . import __version__
from .resolver import contains_model, translate_type
Expand Down
1 change: 0 additions & 1 deletion python/rpdk/python/templates/handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from typing import Any, MutableMapping, Optional

from {{support_lib_pkg}} import (
Action,
HandlerErrorCode,
Expand Down
1 change: 0 additions & 1 deletion python/rpdk/python/templates/hook_handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from typing import Any, MutableMapping, Optional

from {{support_lib_pkg}} import (
BaseHookHandlerRequest,
HandlerErrorCode,
Expand Down
11 changes: 6 additions & 5 deletions python/rpdk/python/templates/hook_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# DO NOT modify this file by hand, changes will be overwritten
import sys
from dataclasses import dataclass

from cloudformation_cli_python_lib.interface import BaseHookHandlerRequest, BaseModel
from cloudformation_cli_python_lib.recast import recast_object
from cloudformation_cli_python_lib.utils import deserialize_list

import sys
from inspect import getmembers, isclass
from typing import (
AbstractSet,
Expand All @@ -14,10 +19,6 @@
TypeVar,
)

from cloudformation_cli_python_lib.interface import BaseHookHandlerRequest, BaseModel
from cloudformation_cli_python_lib.recast import recast_object
from cloudformation_cli_python_lib.utils import deserialize_list

T = TypeVar("T")


Expand Down
17 changes: 9 additions & 8 deletions python/rpdk/python/templates/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# DO NOT modify this file by hand, changes will be overwritten
import sys
from dataclasses import dataclass

from cloudformation_cli_python_lib.interface import (
BaseModel,
BaseResourceHandlerRequest,
)
from cloudformation_cli_python_lib.recast import recast_object
from cloudformation_cli_python_lib.utils import deserialize_list

import sys
from inspect import getmembers, isclass
from typing import (
AbstractSet,
Expand All @@ -14,13 +22,6 @@
TypeVar,
)

from cloudformation_cli_python_lib.interface import (
BaseModel,
BaseResourceHandlerRequest,
)
from cloudformation_cli_python_lib.recast import recast_object
from cloudformation_cli_python_lib.utils import deserialize_list

T = TypeVar("T")


Expand Down
11 changes: 6 additions & 5 deletions python/rpdk/python/templates/target_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# DO NOT modify this file by hand, changes will be overwritten
import sys
from dataclasses import dataclass

from cloudformation_cli_python_lib.interface import BaseModel
from cloudformation_cli_python_lib.recast import recast_object
from cloudformation_cli_python_lib.utils import deserialize_list

import sys
from inspect import getmembers, isclass
from typing import (
AbstractSet,
Expand All @@ -14,10 +19,6 @@
TypeVar,
)

from cloudformation_cli_python_lib.interface import BaseModel
from cloudformation_cli_python_lib.recast import recast_object
from cloudformation_cli_python_lib.utils import deserialize_list

T = TypeVar("T")


Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Python 3.6 and 3.7 language support for the CloudFormation CLI"""
import os.path
import re

from setuptools import setup

HERE = os.path.abspath(os.path.dirname(__file__))
Expand Down
4 changes: 2 additions & 2 deletions src/cloudformation_cli_python_lib/boto3_proxy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# boto3 doesn't have stub files
from typing import Optional

from boto3.session import Session # type: ignore

from typing import Optional

from .utils import Credentials


Expand Down
9 changes: 4 additions & 5 deletions src/cloudformation_cli_python_lib/cipher.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import base64
import json
import uuid
from typing import Optional

# boto3, botocore, aws_encryption_sdk don't have stub files
import boto3 # type: ignore

import aws_encryption_sdk # type: ignore
import base64
import json
import uuid
from aws_encryption_sdk.exceptions import AWSEncryptionSDKClientError # type: ignore
from aws_encryption_sdk.identifiers import CommitmentPolicy # type: ignore
from botocore.client import BaseClient # type: ignore
Expand All @@ -16,6 +14,7 @@
create_assume_role_refresher,
)
from botocore.session import Session, get_session # type: ignore
from typing import Optional

from .exceptions import _EncryptionError
from .utils import Credentials
Expand Down
3 changes: 2 additions & 1 deletion src/cloudformation_cli_python_lib/interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=invalid-name
import logging
from dataclasses import dataclass

import logging
from enum import Enum, auto
from typing import Any, List, Mapping, MutableMapping, Optional, Type

Expand Down
2 changes: 1 addition & 1 deletion src/cloudformation_cli_python_lib/log_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(
self.group = group
self.stream = stream.replace(":", "__")
self.client = session.client("logs")
self.sequence_token = ""
self.sequence_token = "" # nosec

@classmethod
def _get_existing_logger(cls) -> Optional["ProviderLogHandler"]:
Expand Down
3 changes: 1 addition & 2 deletions src/cloudformation_cli_python_lib/metrics.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import datetime
import logging
from typing import Any, List, Mapping, Optional, Union

from botocore.exceptions import ClientError # type: ignore
from typing import Any, List, Mapping, Optional, Union

from .boto3_proxy import SessionProxy
from .interface import Action, HookInvocationPoint, MetricTypes, StandardUnit
Expand Down
3 changes: 2 additions & 1 deletion src/cloudformation_cli_python_lib/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=invalid-name
import json
from dataclasses import dataclass, field, fields

import json
from datetime import date, datetime, time
from typing import (
Any,
Expand Down
3 changes: 1 addition & 2 deletions tests/lib/cipher_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# pylint: disable=wrong-import-order,line-too-long
from unittest.mock import Mock, patch

import pytest
from cloudformation_cli_python_lib.cipher import KmsCipher
from cloudformation_cli_python_lib.exceptions import _EncryptionError
from cloudformation_cli_python_lib.utils import Credentials

from aws_encryption_sdk.exceptions import AWSEncryptionSDKClientError
from unittest.mock import Mock, patch


def mock_session():
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/exceptions_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import importlib
import inspect

import pytest
from cloudformation_cli_python_lib.interface import HandlerErrorCode, OperationStatus

import importlib
import inspect


def get_public_exceptions(module_name="cloudformation_cli_python_lib.exceptions"):
module = importlib.import_module(module_name)
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/hook_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# pylint: disable=redefined-outer-name,protected-access,line-too-long
import json
from dataclasses import dataclass
from datetime import datetime
from unittest.mock import Mock, call, patch, sentinel

import pytest
from cloudformation_cli_python_lib import Hook
Expand All @@ -23,6 +20,10 @@
)
from cloudformation_cli_python_lib.utils import Credentials, HookInvocationRequest

import json
from datetime import datetime
from unittest.mock import Mock, call, patch, sentinel

ENTRYPOINT_PAYLOAD = {
"awsAccountId": "123456789012",
"clientRequestToken": "4b90a7e4-b790-456b-a937-0cfdfa211dfe",
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/interface_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# pylint: disable=protected-access,redefined-outer-name,abstract-method
import json
from dataclasses import dataclass
from string import ascii_letters

import boto3
import pytest
Expand All @@ -15,7 +13,9 @@
)

import hypothesis.strategies as s # pylint: disable=C0411
import json
from hypothesis import given # pylint: disable=C0411
from string import ascii_letters


@pytest.fixture(scope="module")
Expand Down
7 changes: 3 additions & 4 deletions tests/lib/log_delivery_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# pylint: disable=redefined-outer-name,protected-access
import logging
from unittest.mock import DEFAULT, Mock, create_autospec, patch
from uuid import uuid4

import pytest
from cloudformation_cli_python_lib.log_delivery import (
HookProviderLogHandler,
Expand All @@ -18,6 +14,9 @@

import botocore.errorfactory
import botocore.session
import logging
from unittest.mock import DEFAULT, Mock, create_autospec, patch
from uuid import uuid4

logs_model = botocore.session.get_session().get_service_model("logs")
factory = botocore.errorfactory.ClientExceptionsFactory()
Expand Down
9 changes: 4 additions & 5 deletions tests/lib/metrics_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# auto enums `.name` causes no-member
# pylint: disable=redefined-outer-name,no-member,protected-access
from datetime import datetime
from unittest.mock import Mock, call, patch

import pytest
from cloudformation_cli_python_lib.interface import (
Action,
Expand All @@ -19,6 +16,8 @@

import botocore.errorfactory
import botocore.session
from datetime import datetime
from unittest.mock import Mock, call, patch

cloudwatch_model = botocore.session.get_session().get_service_model("cloudwatch")
factory = botocore.errorfactory.ClientExceptionsFactory()
Expand Down Expand Up @@ -67,7 +66,7 @@ def test_put_metric_catches_error(mock_session):
}

with patch(
"cloudformation_cli_python_lib.metrics.LOG", auto_spec=True
"cloudformation_cli_python_lib.metrics.LOG", autospec=True
) as mock_logger:
publisher.publish_metric(
MetricTypes.HandlerInvocationCount,
Expand Down Expand Up @@ -226,7 +225,7 @@ def test_put_hook_metric_catches_error(mock_session):
}

with patch(
"cloudformation_cli_python_lib.metrics.LOG", auto_spec=True
"cloudformation_cli_python_lib.metrics.LOG", autospec=True
) as mock_logger:
publisher.publish_metric(
MetricTypes.HandlerInvocationCount,
Expand Down
Loading