diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..bffe9b83e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,45 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-yaml + - id: name-tests-test + args: [--unittest] + exclude: ^tests/utils.py +- repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + args: [--profile=black, --gitignore] +- repo: https://github.com/psf/black + rev: 23.10.1 + hooks: + - id: black + args: [--line-length=127] +- repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + args: + - --count + - --max-complexity=55 + - --max-line-length=127 + - --statistics + - --extend-ignore=E203,E231,E252,E721,F403,F405,F541,W503 + files: zappa +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.6.1 + hooks: + - id: mypy + args: + - --show-error-codes + - --pretty + - --ignore-missing-imports + - --no-site-packages + files: zappa +- repo: https://github.com/thlorenz/doctoc + rev: v2.2.0 + hooks: + - id: doctoc + args: [--update-only] + files: ./README.md diff --git a/Pipfile b/Pipfile index f8d05fbd9..89ab19269 100644 --- a/Pipfile +++ b/Pipfile @@ -15,6 +15,7 @@ isort = "*" mock = "*" mypy = "*" packaging = "*" +pre-commit = "*" pytest = "*" pytest-cov = "*" diff --git a/zappa/cli.py b/zappa/cli.py index c95859325..f5993daaf 100755 --- a/zappa/cli.py +++ b/zappa/cli.py @@ -120,7 +120,7 @@ class ZappaCLI: aws_kms_key_arn = "" context_header_mappings = None additional_text_mimetypes = None - tags = [] + tags = [] # type: ignore[var-annotated] layers = None stage_name_env_pattern = re.compile("^[a-zA-Z0-9_]+$") @@ -2414,14 +2414,14 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None): # Create the Lambda zip package (includes project and virtualenvironment) # Also define the path the handler file so it can be copied to the zip # root for Lambda. - current_file = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + current_file = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # type: ignore[arg-type] handler_file = os.sep.join(current_file.split(os.sep)[0:]) + os.sep + "handler.py" # Create the zip file(s) if self.stage_config.get("slim_handler", False): # Create two zips. One with the application and the other with just the handler. # https://github.com/Miserlou/Zappa/issues/510 - self.zip_path = self.zappa.create_lambda_zip( + self.zip_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined] prefix=self.lambda_name, use_precompiled_packages=self.stage_config.get("use_precompiled_packages", True), exclude=self.stage_config.get("exclude", []), @@ -2432,11 +2432,11 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None): # Make sure the normal venv is not included in the handler's zip exclude = self.stage_config.get("exclude", []) - cur_venv = self.zappa.get_current_venv() + cur_venv = self.zappa.get_current_venv() # type: ignore[attr-defined] exclude.append(cur_venv.split("/")[-1]) - self.handler_path = self.zappa.create_lambda_zip( + self.handler_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined] prefix="handler_{0!s}".format(self.lambda_name), - venv=self.zappa.create_handler_venv(use_zappa_release=use_zappa_release), + venv=self.zappa.create_handler_venv(use_zappa_release=use_zappa_release), # type: ignore[attr-defined] handler_file=handler_file, slim_handler=True, exclude=exclude, @@ -2448,7 +2448,7 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None): exclude = self.stage_config.get("exclude", ["boto3", "dateutil", "botocore", "s3transfer", "concurrent"]) # Create a single zip that has the handler and application - self.zip_path = self.zappa.create_lambda_zip( + self.zip_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined] prefix=self.lambda_name, handler_file=handler_file, use_precompiled_packages=self.stage_config.get("use_precompiled_packages", True), @@ -2472,7 +2472,7 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None): else: handler_zip = self.zip_path - with zipfile.ZipFile(handler_zip, "a") as lambda_zip: + with zipfile.ZipFile(handler_zip, "a") as lambda_zip: # type: ignore[call-overload] settings_s = self.get_zappa_settings_string() # Copy our Django app into root of our package.